【问题标题】:iOS - SQLite not updating but prepare and step are successfully executingiOS - SQLite 未更新但准备和步骤已成功执行
【发布时间】:2012-12-14 20:08:27
【问题描述】:

标题几乎是我所拥有的所有信息,因为我找不到代码问题。下面代码中使用的同一数据库实例能够成功插入、删除和选择,但此功能不起作用。不返回错误码(始终为0),执行此函数后程序继续名义上运行。

这是表格信息:

reminder (uniqueID integer primary key autoincrement, title text not null, details text, time integer)

有问题的代码:

- (void) updateEntryData:(ReminderData *)data
{
    sqlite3_stmt *statement; 
    char *updateCommand = "UPDATE reminder SET title = '?', details = '?', time = ?    WHERE uniqueID = ?";

    int e = sqlite3_prepare_v2(database, updateCommand, -1, &statement, nil);
    if(e != SQLITE_OK) {
        NSLog(@"Problem with updateEntryWithUniqueID");
        NSLog(@"Error Code: %d, message '%s'", e, sqlite3_errmsg(database));
        return;
    }

    sqlite3_bind_text(statement, 1, [data.title UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(statement, 2, [data.details UTF8String], -1, SQLITE_TRANSIENT); 
    sqlite3_bind_int(statement, 3, [data.time timeIntervalSince1970]);
    sqlite3_bind_int(statement, 4, data.uniqueID);
    NSLog(@"\nID: %d\nTitle: %@\nDetails: %@\nTime: %@", data.uniqueID, data.title, data.details, data.time);

    if(sqlite3_step(statement) != SQLITE_DONE) {
        NSLog(@"Problems updating entry in reminder");
    }

    /* Finished */ 
    sqlite3_finalize(statement);
}

任何帮助将不胜感激;我难住了。

编辑:忘记提及使用的 sql 命令在进入 sqlite 控制台时有效。

【问题讨论】:

    标签: objective-c ios sql sqlite


    【解决方案1】:

    只需删除参数周围的单引号即可。包装占位符将使其成为一个值,而不是一个参数。

    char *updateCommand = "UPDATE reminder SET title = ?, details = ? .....";
    

    【讨论】:

    • 是的,我知道这会很愚蠢!谢谢你。当它允许我时,我会接受你的回答:)
    猜你喜欢
    • 2019-02-08
    • 2020-12-20
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2019-07-11
    • 2017-08-06
    • 2012-07-06
    相关资源
    最近更新 更多