【发布时间】:2011-02-06 00:41:21
【问题描述】:
我正在尝试在 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有问题,因为它在resources文件夹里?
rgds
弗拉
【问题讨论】: