解决中文乱码问题的参考代码如下:
NSMutableArray *rs = [NSMutableArray array];
sqlite3_stmt *statement = NULL;
NSString *sqlStr = @"SELECT * FROM rightMenu WHERE available = 'Y'";
if (sqlite3_prepare_v2(db, [sqlStr UTF8String], -1, &statement, NULL)==SQLITE_OK) {
@try {
while (sqlite3_step(statement)==SQLITE_ROW) {
NSInteger i = 0;
RightMenu *rm = [RightMenu new];
rm.viewCtrlClass = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, i++)];
rm.menuTitle = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, i++)];
rm.menuIcon = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, i++)];
rm.menuIndex = sqlite3_column_int(statement, i++);
[rs addObject:rm];
}
}
@catch (NSException *exception) {
NSLog(@"failed to get rightMenu");
}
@finally {
sqlite3_finalize(statement);
}
}