iOS - SQLite没有更新,但准备和步骤正在成功执行

时间:2021-09-05 02:05:28

The title is pretty much all the information I have because I cannot find an issue with the code. The same instance of database that is being used in the code below is able to successfully insert, delete and select, but this function does not work. No error code is retured(Always 0), and the program continues to run nominally after executing this function.

标题几乎是我所有的信息,因为我找不到代码的问题。下面代码中使用的数据库实例能够成功地插入、删除和选择,但是这个函数不起作用。没有错误代码被重新执行(总是0),程序在执行这个函数之后继续名义上运行。

Here is the table information:

这是表格信息:

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

Code in question:

代码的问题:

- (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);
}

Any help would be greatly appreciated; I am stumped.

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

Edit: Forgot to mention that the sql command used works when entered into the sqlite console.

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

1 个解决方案

#1


5  

Just remove the single quotes around the parameters. Wrapping the placeholders will make it a value and not a parameter anymore.

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

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

#1


5  

Just remove the single quotes around the parameters. Wrapping the placeholders will make it a value and not a parameter anymore.

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

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