0

这是我的 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"];

如果我在 sqlVal 上设置断点,它会返回sqlVal = (const char*) 0x266c0a30 "1-87" 但随后 temp 返回(__NSCFString*)0x27f7bff0 @<variable is not NSString>

有任何想法吗?

4

1 回答 1

0

必须拒绝这样的无效条目:

      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"];   
于 2013-01-28T11:56:00.193 回答