【发布时间】:2016-04-28 02:45:59
【问题描述】:
我正在尝试查询在特定列中有字符串的行。但是,我无法得到想要的结果。
代码:
[_database open];
FMResultSet *results = [_database executeQuery:@"select * from testNotes where notesid=%d",notesID];
NSString *notes=[results stringForColumn:@"notes"];
if ([_database hadError]) {
NSLog(@"DB Error %d: %@", [_database lastErrorCode], [_database lastErrorMessage]);
}
[_database close];
我使用 sqlite 浏览器检查了数据。我发送的值是13,数据存在表中。
当我使用:notesid=%d 时,控制台会显示:(这里 FMResultsSet 是 nil,notes 是 nil)
DB 错误 1:“%”附近:语法错误
我还尝试在 = 和 %d 之间留一个空格
当我使用:notesid='%d' 时,控制台会说:(这里FMResultsSet 不是nil,notes 是nil)
DB 错误 25:绑定或列索引超出范围
当我使用时:notesid='?' 控制台说
DB 错误 25:绑定或列索引超出范围
当我使用:notesid=? 时,应用程序在FMDatabse.m 文件中的obj = va_arg(args, id); 处崩溃
我也试过这个:
[_database executeQuery:[NSString stringWithFormat:@"select * from testNotes where notesid='%d'",notesID]];
根据整数值查询行的正确方法是什么?
【问题讨论】: