程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> string-sqlite sqlite3_column_text返回變量

string-sqlite sqlite3_column_text返回變量

編輯:編程綜合問答
sqlite sqlite3_column_text返回變量

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"];  
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved