Iphone SQLite Databse with german umlauts results in NULL value
- by Daniel
Hi guys,
I'm quite new to the Iphone development and after search for an answer for 3 hours now, I hope that you guys can give me a hand.
My problem is that I have a SQLite Database with german umlauts. Looking at it with a SQLite browser tool shows me that the data is stored with german umlauts, correctly.
But selecting fields with german umlauts in it results in a NULL value.
I'm already using "stringWithUTF8String", so I don't get the point where the problem is placed.
Here is my code:
-(void) readSearchFromDatabase {
searchFlag = YES;
// Setup the database object
sqlite3 *database;
// Init the SCode Array
searchSCodes = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *wildcard =@"%";
// Setup the SQL Statement and compile it
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM scode WHERE ta LIKE '%@%@%@' OR descriptionde LIKE '%@%@%@' OR descriptionen LIKE '%@%@%@'", wildcard, searchBar.text, wildcard, wildcard, searchBar.text, wildcard, wildcard, searchBar.text, wildcard, wildcard, searchBar.text, wildcard];
//Creating a const char SQL Statement especially for SQLite
const char *sqlStatement = [sql 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 *aTa = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *aReport = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescriptionDE = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aDescriptionEN = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
//Results a NULL value
NSLog(@"Output: %@", aDescriptionDE);
// Create a new SCode object with the data from the database
SCode *searchSCode = [[SCode alloc] initWithTa:aTa report:aReport descriptionDE:aDescriptionDE descriptionEN:aDescriptionEN];
// Add the SCode object to the SCodes Array
[searchSCodes addObject:searchSCode];
[searchSCode release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}