So I am trying to work with SQLite in one of iPhone applications and I am using the sqlite3 library. I am able to access the database and even make a query; in fact the query accesses the exact data but for some reason the string I am getting back is a long integer and not the string I was looking for. Here is the database and code:
Filename: Package.sql Table Lessons LessonID VARCHAR(64) Primary Key | LessonName VARCHAR(100) | EntryDate (DATETIME) | Chrono VARCHAR (20) bfow02nso9xjdo40wksbfkekakoe29ak | Learning The History | 2010-08-05 16:24:35 | 0001
And the iPhone Code
... -(NSString *)getRow:(NSString *)tablename where:(NSString *)column equals:(NSString *)value { const char *query = [[[[[[[@"SELECT * FROM `" stringByAppendingString:tablename] stringByAppendingString:@"` WHERE `"] stringByAppendingString:column] stringByAppendingString:@"` = '"] stringByAppendingString:value] stringByAppendingString:@"';"] cStringUsingEncoding:NSUTF8StringEncoding]; NSString *result; if(sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK) { sqlite3_stmt *compiledQuery; if(sqlite3_prepare_v2(database, query, -1, &compiledQuery, NULL) == SQLITE_OK) { while(sqlite3_step(compiledQuery) == SQLITE_ROW) { NSString *str_temp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledQuery, 2)]; result = str_temp; } sqlite3_finalize(compiledQuery); } sqlite3_close(database); } return result; } ...
When the code executes:
CDatabase *db = [[CDatabase alloc]initWithDatabase:@"Package.sql"]; NSString *result = [db getRow:@"Lessons" where:@"Chrono" equals:@"0001"];
the returned value NSString *result has a value of "1,364,111". Why is it doing that??? It should be "Learning The History"