【发布时间】:2011-09-13 07:20:14
【问题描述】:
奇怪的问题请大家解决
当循环未执行时,在我读取的数据库代码中。
这是我的代码
NSString * query=@"select usernote from savenote where recipename like ? ";
const char * sqlStatement=[query UTF8String];
sqlite3_stmt *compiledStatement;
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
if (sqlite3_prepare_v2 (database, sqlStatement,-1,&compiledStatement,NULL)==SQLITE_OK)
{
sqlite3_bind_text(compiledStatement,1,[selString UTF8String],-1,SQLITE_STATIC);
NSLog(@"selected:%@",selString);
while (sqlite3_step(compiledStatement)== SQLITE_ROW)
{
NSString * notz=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,0)];
[Notes addObject:notz];
NSLog(@"n:%@",Notes);
txt.text=[Notes objectAtIndex:0];
}
}
}
在上面的代码中,除了 while 循环永远不会被执行之外,一切正常。
感谢您阅读我的帖子。
【问题讨论】:
-
您是否尝试过使用调试器来单步调试您的代码?可能包含 while 循环的 if 语句永远不会计算为真。如果没有,可能您对 sqlite3_prepare_v2() 的调用失败了...