I'm trying to open a SQLite file and I have upload it to my projects but I always get an error no such table: Words
while I can get the result in sql app.
When I debug I see that I can't enter if (sqlite3_prepare_v2(database, SqlCommand, -1, &selectstmt, NULL) == SQLITE_OK)
Please where would be my issue?
My code:
- (void)GetData{
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
_databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"wordsDb.sqlite"]];
sqlite3 *database;
sqlite3_stmt *selectstmt;
if(sqlite3_open([_databasePath UTF8String], &database) == SQLITE_OK) {
NSString *sqlString = [NSString stringWithFormat:@"SELECT words FROM Words"];
NSLog(@"getCurrentUserInfo:%@",sqlString);
const char *SqlCommand = [sqlString UTF8String];
if (sqlite3_prepare_v2(database, SqlCommand, -1, &selectstmt, NULL) == SQLITE_OK) {
NSLog(@"success!");
while (sqlite3_step(selectstmt) == SQLITE_ROW) {
NSString *userInfoStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
NSLog(@"select result:%@",userInfoStr);
}
}
else
{
NSLog(@"%s",sqlite3_errmsg(database));
}
sqlite3_finalize(selectstmt);
}
sqlite3_close (database);
}
Aucun commentaire:
Enregistrer un commentaire