Hello all,
I am working on an app that has to read Chinese words from an SQLite database. Initially I used a pretty basic way of retrieving the data from the db:
Code:
sqlite3 *Database(void)
{
//NSString *cards;
NSString *file = [[NSBundle mainBundle] pathForResource:@"chinese" ofType:@"db"];
if(sqlite3_open([file UTF8String], &database) == SQLITE_OK)
{
if(sqlite3_exec(database, "select chinTraditional from words where chap = '1'", dbCallBack, cards, NULL))
{
NSLog(@"Success");
}
else
NSLog(@"Q Fail");
return database;
}
where dbCallBack is :
Code:
int dbCallBack(void *na, int argc, char **argv, char **colName)
{
for(int i = 0; i < argc; i++)
{
NSLog([NSString stringWithFormat:@"Chinese = %C\n", argv[i] ? argv[i] : "NULL"]);
}
return 0;
}
I wanted to display the current Chinese word with NSLog, but I get wrong values.
I thought that the problem might be in argv being an array of chars, which are of smaller size than the one needed for unicode. I tried other using sqlite3_prepare_v2 instead and statements instead of this method but I was not sure how to proceed and whether this could get me out of the problem.
Could anyone lend me a hand, or give me a hint in how to proceed with the task of reading the Chinese characters from the database and assigning them to a variable that I can use elsewhere in the code?
Thanks a lot!
I have been looking for solutions for the past 3-4 hours and I could find anything that fixes my problem.