sqlite聲明:
NSString *queryString = @"SELECT email.pk, email.sender_name, email.sender_address, search_email.subject, email.datetime, "
"LENGTH(email.attachments), SUBSTR(search_email.body,0,150), email.folder_num, t.threadid, t.numThreads FROM "
"email, search_email ,(select threadid, min( docid) as docid, count(*) as numThreads from search_email group by threadid) as t "
"WHERE t.docid = email.pk AND (email.folder_num = ? OR email.folder_num_1 = ? OR email.folder_num_2 = ? OR email.folder_num_3 = ?) AND email.pk = search_email.docid "
"ORDER BY email.datetime DESC;";
我用 sqlite3_column_text和sqlite3_column_int獲取的值都正確,但是在threadid處出現問題:
NSString* temp = @"";
const char *sqlVal = (const char *)sqlite3_column_text(folderSearchStmt, 1);
...
temp = @"";
sqlVal = (const char *)sqlite3_column_text(folderSearchStmt, 8);
if(sqlVal != nil)
temp = [NSString stringWithUTF8String:sqlVal];
[res setObject:temp forKey:@"threadID"];
如果我在aslVal加一個斷點,返回sqlVal = (const char*) 0x266c0a30 "1-87"
,但是隨後temp返回(__NSCFString*)0x27f7bff0 @<variable is not NSString>
需要拒絕無效的條目,如下:
const char *_abc = (char *) sqlite3_column_text(statement, 1);
NSString *_abcTemp;
if (_abc)
_abcTemp = _abc == NULL ? nil : [[NSString alloc] initWithUTF8String:_abc];
else
_abcTemp = [[NSString alloc] initWithString:@"Not a valid string"];