SQLite C++;查询行-如何处理多个列 我是SQLite的新手,C++有点理解如何处理从查询返回的多行。我需要把每列int的值作为一个变量,以便以后处理它
到目前为止,我已经:SQLite C++;查询行-如何处理多个列 我是SQLite的新手,C++有点理解如何处理从查询返回的多行。我需要把每列int的值作为一个变量,以便以后处理它,c++,sql,database,sqlite,c++11,C++,Sql,Database,Sqlite,C++11,到目前为止,我已经: sqlite3_stmt* statement; if (sqlite3_prepare_v2(getDatabase(), _sql.c_str(), -1, &statement, 0) == SQLITE_OK) { int cols = sqlite3_column_count(statement); int result = 0; while(true) { result = sq
sqlite3_stmt* statement;
if (sqlite3_prepare_v2(getDatabase(), _sql.c_str(), -1, &statement, 0)
== SQLITE_OK)
{
int cols = sqlite3_column_count(statement);
int result = 0;
while(true)
{
result = sqlite3_step(statement);
if(result == SQLITE_ROW)
{
for(int col = 0; col < cols; col++)
{
// go through each column and store it
}
}
else
{
break;
}
}
}
或者有没有一种方法可以通过列名来实现
还是有更好的办法呢?我想出来了
正确的步骤是循环每一行,并使用
sqlite\u列(语句,[col\35;])
最终目标是什么?循环完成后,您希望数据最终精确到哪里,下一步如何处理?关于:列名-请参见sqlite3\u column\u name
if (col == 0) // first column position
{
// store it...
}
else if (col == 1) // second column position
{
// store it...
}