Here is my code to add a table in my existing database. My code reaches to success callback of sqlite3_prepare_v2 and gives the log table created, but when I open my sqlite database using terminal, I see that there were no tables created. My database table name is fz1.sqlite declared by pragma by this: #define kDBName @"fz1.sqlite"
-(sqlite3 *)mydb:(NSString *)query{
static sqlite3 *database;
static sqlite3_stmt *enableForeignKey;
if (database == NULL) {
sqlite3 *newDBconnection;
// first get the path for the document directory of the application
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dbpath = [paths objectAtIndex:0];
NSString *path = [dbpath stringByAppendingPathComponent:kDBName];
if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
database = newDBconnection;
if (sqlite3_prepare_v2(database,[query UTF8String], -1, &enableForeignKey, NULL) != SQLITE_OK) {
NSLog(@"ERROR IN PRAGMA!");
}
else{
sqlite3_exec(database, [query UTF8String], NULL, NULL, NULL);
NSLog(@"faiz's table created");
}
sqlite3_finalize(enableForeignKey);
} else {
NSLog(@"Error in opening database :(");
database = NULL;
}
}
return database;
}