我正试图在iphone上使用sqlite3在表格中插入一些数据... 我从各个步骤得到的所有错误代码表明操作应该是成功的,但事实上,表格仍然是空的...我想我错过了一些东西......
这里是代码:
sqlite3 *database = nil;
NSString *dbPath = [[[ NSBundle mainBundle ] resourcePath ] stringByAppendingPathComponent:@"placemarks.sql"];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){
sqlite3_stmt *insert_statement = nil;
//where int pk, varchar name,varchar description, blob picture
static char *sql = "INSERT INTO placemarks (pk, name, description, picture) VALUES(99,'nnnooooo','dddooooo', '');";
if (sqlite3_prepare_v2(database, sql, -1, &insert_statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
int success = sqlite3_step(insert_statement);
int finalized = sqlite3_finalize(insert_statement);
NSLog(@"success: %i finalized: %i",success, finalized);
NSAssert1(101, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
sqlit3_step returns 101, so SQLITE_DONE, which should be ok..
如果我在命令行中执行sql语句,它可以正常工作......
谁有个主意呢? 可能是因为写在placemarks.sql中有问题,因为它在资源文件夹中?RGDS
弗拉
答案 0 :(得分:0)
发现它是什么!我想...我无法修改资源文件夹中的* .sql,我必须先在应用程序的文档中复制并使用该副本!