我真的找到了答案,但我找不到答案:(
问题是非英语字符(法语和希腊语),只有英文字符才能正常工作。
我从一个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
我找到了解决方案!
如果你把所有东西都放在一个文件中,并制作多个表就行了。
我很想知道为什么会这样,所以如果有人知道我会很感激