if(sqlite3_open([databasePath UTF8String], & database) == SQLITE_OK) {
NSLog(@"DB OPENED");
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement ="select name from Medicine";
sqlite3_stmt *compiledStatement;
int result = sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, nil);
NSLog(@"RESULT %d", result);
if(result == SQLITE_OK) {
NSLog(@"RESULT IS OK...");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSLog(@"WHILE IS OK");
**araci = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];**
NSLog(@"Data read");
NSLog(@"wow: %",araci);
}//while
}//if sqlite_prepare v2
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
NSLog(@"compiled stmnt finalized..");
}
sqlite3_close(database);
NSLog(@"MA_DB CLOSED");
1)在大胆的代码之前一切都好。当我运行应用程序时,会在下面抛出异常。我的db中有一个表和一行相对,id(整数),name(varchar),desc(varchar)(我使用SQLite Manager创建了我的表)。
2-)SQLite Manager中的文本类型是什么?那是NSString吗?另外,我如何将字符串值(在表中)放入NSMutableArray? (我真的很难转换。)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
答案 0 :(得分:4)
处理数据库返回的null,您可以使用以下代码来解决它
char *localityChars = (char *)sqlite3_column_text(init_statement, 12);
if (localityChars ==null)
self.Locality = nil;
else
self.Locality = [NSString stringWithUTF8String: localityChars];
答案 1 :(得分:2)
sqlite3_column_text
将返回空指针。你需要检查一下。