我的桌子上有12根柱子。最后两列是新添加的。我使用sqlite3数据库。如果对除最后创建的两个新列之外的任何其他列使用where子句,则将创建数据库并正确执行查询。最后两列返回空字符串,这使得应用程序崩溃时抛出了终止应用程序,原因是'NSInvalidArgumentException',原因:' *+NSString stringWithUTF8String::NULL cString'**
当在SQL中执行查询时,我可以检索最后两列。我想我的准备陈述有什么地方不对劲。
NSString *query = @"select * from tableName where lastColumn = 'Value'";
const char *sqlStatement = [query UTF8String];
sqlite3_stmt *compiledStatement;
NSLog(@"could not prepare statement: %s\n", sqlite3_errmsg(database));
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
}请帮帮我。我完全不知道最后两列的去向..。:)
发布于 2012-06-15 19:53:38
将NULL传递给stringWithUTF8String: method,这是不允许的。在实例化NSString对象之前,您应该检查从sqlite获得的值。
const char *ctext = sqlite3_column_text(compiledStatement, 2);
if (ctext) {
text = [NSString stringWithUTF8String:ctext];
}添加新列时,所有现有行中的此列的值设置为空。
https://stackoverflow.com/questions/11053232
复制相似问题