4

我准备了一个选择语句。

sqlite3_prepare(db, "SELECT symbol,image FROM test WHERE template=? AND field=?", -1, &stmt, 0);
sqlite3_bind_text16(stmt, 1, pParams->pszFile, -1, SQLITE_STATIC);
sqlite3_bind_text16(stmt, 2, pParams->pszFieldId, -1, SQLITE_STATIC);

如何遍历结果?

4

2 回答 2

7
int rc = sqlite3_prepare(db, "SELECT symbol,image FROM test WHERE template=? AND field=?", -1, &stmt, 0);
sqlite3_bind_text16(stmt, 1, pParams->pszFile, -1, SQLITE_STATIC);
sqlite3_bind_text16(stmt, 2, pParams->pszFieldId, -1, SQLITE_STATIC);  

 if(rc != SQLITE_OK)
 {
    fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
    return;
  }
  rc = sqlite3_step(stmt);
  int ncols = sqlite3_column_count(stmt);

  while(rc == SQLITE_ROW)
  {

      for(i=0; i < ncols; i++)
      {
         fprintf(stderr, "'%s' ", sqlite3_column_text(stmt, i));
      }

      fprintf(stderr, "\n");
      rc = sqlite3_step(stmt);
  }

  sqlite3_finalize(stmt);
于 2013-04-16T06:32:43.793 回答
0

sqlite3_step()为此目的使用该功能。

于 2013-04-16T06:16:56.953 回答