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)除了粗体代码之外,一切都很好。当我运行应用程序时,抛出下面的异常。我的数据库中有一个表和一行,id (整数),name (varchar),desc (varchar) (我使用SQLite管理器创建了我的表)。
2-) SQLite管理器中的文本类型是什么?那是NSString吗?另外,如何将字符串值(在表中)放入NSMutableArray?(我真的很难转换。)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
发布于 2011-01-30 05:19:07
要处理数据库返回的null,可以使用以下代码来处理
char *localityChars = (char *)sqlite3_column_text(init_statement, 12);
if (localityChars ==null)
self.Locality = nil;
else
self.Locality = [NSString stringWithUTF8String: localityChars];
发布于 2010-04-20 00:46:56
当该列为空时,sqlite3_column_text
将返回一个空指针。你需要检查一下这个。
https://stackoverflow.com/questions/2669145
复制相似问题