sqlite3 - while循环未执行

时间:2011-09-13 07:20:14

标签: xcode4 sqlite

奇怪的问题有人请解决它

while循环没有执行,在我的read数据库代码中。

这是我的代码

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循环外,一切正常。

感谢您阅读我的帖子。

2 个答案:

答案 0 :(得分:0)

我猜问题出在查询中。在'子句中添加单引号like)。

"select usernote from savenote where recipename like '?'";

答案 1 :(得分:0)

您可以关注this link

在你的情况下代码看起来像,

const char * sqlStatement = "select usernote from savenote where recipename like ?001 ";

sqlite3_bind_text(compiledStatement,1,[selString UTF8String],-1,SQLITE_TRANSIENT);