estoy haciendo actualmente los siguientes como parte de mi aplicación para iPhonecomportamiento SQLite en INSERT en el iPhone
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"cities.sqlite"];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into table (name, description, image) VALUES (?, ?, ?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 1, [name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [description UTF8String], -1, SQLITE_TRANSIENT);
NSData *dataForImage = UIImagePNGRepresentation(image);
sqlite3_bind_blob(compiledStatement, 3, [dataForImage bytes], [dataForImage length], SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE) {
NSLog(@"Error: %s", sqlite3_errmsg(database));
} else {
NSLog(@"Insert into row id = %d", sqlite3_last_insert_rowid(database));
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
Lo que me confunde es que si saco la sección,
if(sqlite3_step(compiledStatement) != SQLITE_DONE) {
NSLog(@"Error: %s", sqlite3_errmsg(database));
} else {
NSLog(@"Insert into row id = %d", sqlite3_last_insert_rowid(database));
}
la del INSERT no se guarda en la base de datos y se pierde. Supongo que me estoy perdiendo algo obvio aquí?
tengo curiosidad de la razón (s) para no usar la base de datos. – nicerobot
Normalmente uso algunos envoltorios alrededor de SQLite o, la mayoría de las veces, Core Data. Sin embargo, quería saber cómo usar la biblioteca directamente, así que ... –