这是数据库字段值。
下面是我申请从 sqlite 数据库中获取数据的代码
-(void)readDataFromRestaurantTable
{
[self openDataBase];
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, & database) == SQLITE_OK)
{
sqlite3_stmt *statement = NULL;
NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM RestaurantDB"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW)
{
strRestaurantName = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
strRestaurantAddress = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
strRestaurantPhone = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)];
strRestaurantLatitude = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)];
strRestaurantLongitude = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 5)];
NSLog(@"strRestaurantName :--> %@",strRestaurantName);
}
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
在前面的代码块应用程序里面是不走的
if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
}
在这里,它得到了statement = 0x00000000 & 我认为正因为如此,它才不会进入 if 块。
崩溃时的错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithUTF8String:]: NULL cString'
First throw call stack:
(0x18dc012 0x12a1e7e 0x18dbdeb 0xcbdce6 0x78e4 0x7bdf 0x2ca817 0x2ca882 0x2ebed9 0x2ebd14 0x2ea1ea 0x2ea06c 0x2ebc57 0x12b5705 0x1ec920 0x1ec8b8 0x40f0b4 0x12b5705 0x1ec920 0x1ec8b8 0x2ad671 0x2adbcf 0x2ad6a6 0x412bb9 0x12b5705 0x1ec920 0x1ec8b8 0x2ad671 0x2adbcf 0x2acd38 0x21c33f 0x21c552 0x1fa3aa 0x1ebcf8 0x1da5df9 0x185ff3f 0x185f96f 0x1882734 0x1881f44 0x1881e1b 0x1da47e3 0x1da4668 0x1e965c 0x2712 0x2645 0x1)
libc++abi.dylib: terminate called throwing an exception
请指导我实际问题出在哪里。