【问题标题】:sqlite3 no insert is done after --> insert into --> SQLITE_DONEsqlite3 在 --> 插入 --> SQLITE_DONE 之后没有插入
【发布时间】: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

弗拉

【问题讨论】:

    标签: iphone insert sqlite


    【解决方案1】:

    找出它是什么!正如我所想...我无法修改资源文件夹中的 *.sql,我必须首先在应用程序的文档中制作一个副本并使用该副本!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2011-05-02
      相关资源
      最近更新 更多