2017-03-03 14 views
2

私はthisを達成しようとしており、間接的にそれを行う方法を知っています...もし私がテーブルのスキーマを取得できれば。どのようにしてsociのテーブルのスキーマまたは行名を取得できますか?

どうすればよいですか?

私が試してみました:

std::string i; 
soci::statement st = (mSql->prepare << 
       "show create table tab;", 
       soci::into(i)); 
st.execute(); 
while (st.fetch()) 
{ 
     std::cout << i <<'\n'; 
} 

だけ "タブ" が印刷されます。

私はまた、GitHubの中Sociのドキュメントから、これを試してみました:

soci::column_info ci; 
soci::statement st = (mSql->prepare_column_descriptions(table_name), into(ci)); 

st.execute(); 
while (st.fetch()) 
{ 
    // ci fields describe each column in turn 
} 

しかしcolumn_infoはSOCIのメンバーではないと言われました。

答えて

2

私はhere

soci::row v; 
soci::statement st = (mSql->prepare << "SELECT * FROM tab", into(v)); 
st.execute(true); /* with data exchange */ 
unsigned int num_fields = v.size(); 
std::cout << "fields: " << num_fields << std::endl; 
num_fields = (num_fields <= 9) ? num_fields : 9; 
unsigned long num_rows = (unsigned long)st.get_affected_rows(); 
std::cout << "rows: " << num_rows << std::endl; 
for (size_t i = 0; i < num_fields; ++i) { 
    const soci::column_properties &props = v.get_properties(i); 
    std::cout << props.get_name() << '\t'; 
} 
std::cout << std::endl; 

次のコードを見つけ、印刷の最後の物事が正しい列の名前です。

関連する問題