假設您已經存儲在您的sqlite的分貝的字符串爲UTF-8的數據,你會從你的查詢結果中提取,並做出一個NSString像這樣:
#import <sqlite3.h>
// Open the db
sqlite3 *db;
int result = sqlite3_open("path/to/your/db", &db);
// Prepare your query
sqlite3_stmt *statement;
result = sqlite3_prepare_v2(db, "select * from table where...;", -1, &statement, NULL);
// Process each row of the response
while (SQLITE_ROW == ((result = sqlite3_step(statement))))
{
NSString *string = @"";
// Pull out a given column as a text result
char *c = sqlite3_column_text(statement, yourStringColumnIndex);
// Make an NSString out of it
if (c)
string = [NSString stringWithUTF8String:c];
NSLog(@"%@", string);
}
// Release the prepared statement and close the db
sqlite3_finalize(statement);
sqlite3_close(db);
很顯然,你應該檢查錯誤的結果並適當迴應。
謝謝!這是我需要的 – user1486548 2012-08-01 13:37:17