所以我似乎无法弄清楚为什么我的数据库没有使用我的插入查询进行更新,有人可以查看我的代码并告诉我他们是否看到了什么?非常感谢先进。
-(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);
}
}
感谢任何试图提供帮助的人。