我无法执行sqlite3_prepare_v2。当我调试程序时,程序打开数据库,然后它来到sqlite3_prepare_v2。当我点击继续时,它会出现if loop&控制转移到最终确定声明。这是我的代码
sqlite3 * database;
if(sqlite3_open([db_path UTF8String], &database)==SQLITE_OK)
{
sqlite3_stmt * compiledstatement;
sqlstmt = @" my select sql query";
if(sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement,NULL)==SQLITE_OK)
{
while(sqlite3_step(compiledstatement)==SQLITE_ROW)
{
// select query logic
}
}
sqlite3_finalize(compiledstatement);
}
sqlite3_close(database);
答案 0 :(得分:2)
sqlstmt是代码中的NSString。它应该是一个C字符串。改变
if (sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement,NULL)==SQLITE_OK)
到
if (sqlite3_prepare_v2(database, [sqlstmt **UTF8String**], -1, &compiledstatement,NULL)==SQLITE_OK)