以下是我的数据库功能:
+(NSArray*)searchWithKey:(NSString*)_key{
NSMutableArray* tmpArray = [NSMutableArray array];
static Statement* stmt = nil;
char* sql = "select * from Bookmarks where BMUrl like '%?%'";
if (stmt == nil) {
stmt = [DBConnection statementWithQuery:sql];
[stmt retain];
}
[stmt bindString:_key forIndex:1];
while ([stmt step] == SQLITE_ROW) {
BookMark* tmpBM = [[BookMark alloc] initWithStatement:stmt];
NSLog(@"tmpBM = %@",tmpBM);
[tmpArray addObject:tmpBM];
[tmpBM release];
}
[stmt reset];
return tmpArray;}
sql的关键字是我使用的“like”。但是sqlite没有返回结果。有人能告诉我为什么吗?我将sql更改为“select * from Bookmarks where BMUrl like '%h%'”,返回了一些结果。所以,我猜错误是函数“bindString:forIndex”,代码是
- (void)bindString:(NSString*)value forIndex:(int)index{
sqlite3_bind_text(stmt, index, [value UTF8String], -1, SQLITE_TRANSIENT);}
我将使用哪个正确的 sqlite3 api?感谢你!