gpt4 book ai didi

cocoa - sql语句sqlite3_column_text有什么问题?

转载 作者:行者123 更新时间:2023-12-03 16:17:44 25 4
gpt4 key购买 nike

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 Manager 创建了表)。

2-) SQLite Manager 中的文本类型是什么?那是 NSString 吗?另外,如何将字符串值(在表中)放入 NSMutableArray 中? (我真的很难转换。)

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'

最佳答案

要处理数据库返回的null,可以使用下面的代码来处理


char *localityChars = (char *)sqlite3_column_text(init_statement, 12);

if (localityChars ==null)
self.Locality = nil;
else
self.Locality = [NSString stringWithUTF8String: localityChars];

关于cocoa - sql语句sqlite3_column_text有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2669145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com