So I can't seem to figure out why my database is not updating with my insert query, could someone please check out my code and let me know if they see anything? Thanks so much in advanced.
-(void)connectSQL {
@try {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* dbPath = [documentsPath stringByAppendingPathComponent:@"UserDB1.sqlite"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:dbPath];
if (!fileExists) {
NSLog(@"Didn't find database");
NSString *dbSourcePath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"UserDB1.sqlite"];
//Here we copy our database to documents located on the users phone.
[[NSFileManager defaultManager] copyItemAtPath:dbSourcePath toPath:dbPath error:nil];
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
queryString = @"INSERT INTO FavoriteExercises ('ExerciseID','ExerciseType') VALUES ('1','strength')";
const char *sql = [queryString cStringUsingEncoding:NSASCIIStringEncoding];
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
sqlite3_finalize(sqlStatement);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
}
}
Thanks to anyone who tries to help.