SQLite Web应用程序,从插入中获取行?

发布于 2024-12-20 15:17:31 字数 775 浏览 0 评论 0原文

我有这样的代码:

database.transaction(function(transaction) {
    transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
});

但我想做的是获取 row[]; (或者更具体地说 row[id])来自我刚刚插入的内容。

交易方法是否返回更多值?

更新:

我用变量插入它,标准 sqlite-webapp 方式。

    var todoInput = $('#todo').val();
    var descriptionInput = $('#description').val();
    var myDate = new Date();
    myDate.getMonth() + 1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();

    database.transaction(function(transaction) {
        transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
    });

I have this code:

database.transaction(function(transaction) {
    transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
});

But what I want to do is to get the row[]; (or more specifically row[id]) from what I just inserted.

Does the transaction method return any more values?

UPDATE:

I inserted it with variables, standard sqlite-webapp way.

    var todoInput = $('#todo').val();
    var descriptionInput = $('#description').val();
    var myDate = new Date();
    myDate.getMonth() + 1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();

    database.transaction(function(transaction) {
        transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

著墨染雨君画夕 2024-12-27 15:17:31

您需要在插入后立即返回 id。

将此 ;selectscope_identity() 添加到您的查询中。

那么你应该能够提取插入行的 id 并从那里执行你想要的操作。

you need to return the id straight after your insert.

add this ;select scope_identity() to your query.

then you should be able to pull out the id of the inserted row and do what you want from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文