Hey guys,
I am having an sqlite issue I can't figure out. I can connect to the db, select and get the data back but it isn't in the correct format. The code looks correct to me just not sure what I am doing wrong. Here is a small snippet of the code that gets the results.
static sqlite3_stmt *select_stmt = nil;
if (select_stmt == nil) {
static char *sql = "SELECT id, name FROM table ORDER BY name DESC";
if (sqlite3_prepare_v2(database, sql, -1, &select_stmt, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement '%s'.", sqlite3_errmsg(database));
return;
}
}
while (sqlite3_step(select_stmt) == SQLITE_ROW) {
NSNumber *pk = [NSNumber numberWithInt: sqlite3_column_int(select_stmt,0)];
NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_stmt, 1)];
NSLog(@"id=%i", id);
NSLog(@"name=%s", name);
}
Console Results:
pk=1094496
name=à 8åa
should be:
pk=1
name=test
I get results back but the name above prints as "name=à 8åa". The same goes for any other type, primary key ints are coming back as 7 digit numbers. Any ideas I'm at a loss.
Thanks