私はSQLiteデータベースを使用しています。問題は、データがベースに書き込まれないということです。 NSLogは私に "All ok"を表示し、insertSQL
も正しいですが、データベースのレコードはまだ発生していません。私のコード:SQLiteデータベースへの書き込み。奇妙なもの
-(void)saveMessage:(id)sender
{
sqlite3 *database;
databaseName = @"BlogDatabase.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:@"insert into \"main\".\"MessagesData\" (\"MessageText\", \"MessageDate\") values ('%@', '%@');", _textField.text, [[NSDate alloc] init]];
NSLog(@"%@", insertSQL);
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, insert_stmt, -1, &compiledStatement, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}else{
if (sqlite3_step(compiledStatement) == SQLITE_DONE)
{
NSLog(@"All ok");
} else {
NSLog(@"FAIL");
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
あなたが探しているデータベース。アプリDB? –