android - Statement.executeInsert() 返回值

标签 android sql sqlite

假设我有 ProductVersion Table:

CREATE TABLE ProductVersion 
(
   Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
   PrvVersionName NOT NULL
);

我有这段代码可以在此表上执行INSERT:

   SQLiteDatabase database = this.getWritableDatabase();
   String sql = "INSERT INTO ProductVersion (PrvVersionName) VALUES (?);";

   SQLiteStatement s = database.compileStatement(sql);
   s.bindString(1, data.getVersionName());

   long id = s.executeInsert();
   s.close();

我的问题是,从 s.executeInsert() 返回的值是否与我在执行此 INSERT 后使用 "SELECT last_insert_rowid();" 查询相同?

最佳答案

executeInsert() 将返回插入行的 ID

来自文档

SQLiteStatement.executeInsert ()

Execute this SQL statement and return the ID of the row inserted due to this call. The SQL statement should be an INSERT for this to be a useful call.

关于android - Statement.executeInsert() 返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50459681/

相关文章:

java - 安卓 : How to create HMAC MD5 string?

SQL - 使用 BLOBS 查询

mysql - 关联同一个表中的两列

sql - sqlite根据列条件创建新行

sqlite - 在哪里可以找到旧 SQLite 版本的源存档?

android - 如何在android中检测图像文件

android - React native + Axios 不会跨请求保留 cookie

php - 错误域 = NSCocoaErrorDomain 代码 = 3840“JSON 文本未以数组或对象开头

postgresql - 你如何在 PostgreSQL 中创建虚拟表?

android - 如何通过单击按钮填充 EditText?