我真的一直在寻找答案,但我没有找到我的答案:(
问题是非英文字符(法语和希腊语),只有英文字符可以正常工作。
我从一个 sqlite 数据库中取出东西,它与英文字符完美匹配,但与法语或希腊字符不匹配。
这个时候就出错了:
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
这返回 false,因此程序不会继续。
我已经阅读了有关 UTF-8 和 UTF-16 的内容。
UTF-8 是 sqlite3_open,UTF-16 是 sqlite3_open16。
当我使用sqlite3_open16
时,它根本不打开。
我必须打开带有法语字符的数据库和一个带有希腊字符的数据库。
有谁知道该怎么做?
这是我打开数据库的代码:
startLanguage = the language where I start with, this is also the database name.
databasePath = the path to the database file. e.g.: /Users/joeranbosma/Library/Application Support/iPhone Simulator/5.0/Applications/80C89C95-418D-487F-B697-6BEA4B0DAA66/Documents/frans.sql
-(void) readWordsFromDatabase {
// Setup the database object
sqlite3 *database;
// Init the words Array
words = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
NSString *mySQLstatement = [@"select * from " stringByAppendingString:startLanguage];
const char *sqlStatement = [mySQLstatement UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_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
NSString *woordA = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *woordB = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
// Create a new word object with the data from the database
Word *word = [[Word alloc] initWithWordA:woordA wordB:woordB];
// Word *words = [[Word alloc] initWithWordName:aName description:aDescription url:aImageUrl];
// Add the word object to the words Array
[words addObject:word];
[word release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
编辑 1
我找到了解决方案!
如果您将所有内容放入一个文件中,并制作多个表,则它可以工作。
我很想知道为什么会这样,所以如果有人知道我会很感激