javascript - 如何使用sqlite在插入查询中获取插入的行id?

标签 javascript sqlite cordova

INSERT INTO Student (id, FirstName, LastName, SpouseName, DOB, GenderId, Email ) 输出 Inserted.id 值 (hex( randomblob(4)) || '-' || hex( randomblob(2))|| '-' || '4' || substr( hex( randomblob(2)), 2) || '-'|| substr('AB89', 1 + (abs(random()) % 4) , 1) ||substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6)),?, ?, ?, ?, (从性别中选择 ID,其中姓名 ='女性'), ?;

OUTPUT Inserted.id 将检索 SQl 中最后插入的行 ID。 但是,Sqlite 我不知道 OUTPUT Inserted.id 是什么。

提前致谢。

最佳答案

您需要将其分成两个语句;首先是您的插入,然后紧接着 SELECT last_insert_rowid() 这将为您提供插入的行的 id。

请参阅documentation关于这是如何运作的;和 sql reference对于该功能也是如此。

关于javascript - 如何使用sqlite在插入查询中获取插入的行id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49022242/

相关文章:

c++ - 如何在sqlite3 c++中绑定(bind)日期时间函数

android - 创建安卓数据库表

cordova - Jquery-mobile 和 Phonegap 最佳技术

api - 如何在 phonegap 中实现 Google Auth?

javascript - "GET"获取脚本文本, "POST"结果为 "405 method not allowed",我 _did_methods=[ 'GET' , 'POST' ] (从 JavaScript 通过 Flask 到 Python)

javascript - Flatlist 在向其传递另一个数据后不会刷新

javascript - document.all [""+ object.getAttribute ("EndDate", true) + ""].value;不能在 Firefox 中工作

javascript - 在 UIWebView swift 中单击按钮时打开 ViewController

database - 合并具有相同主键的 SQLite3 表

javascript - 将mp3文件发送到MVC3应用程序并存储在sql server中