Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stmt.run().lastInsertRowid is wrong with RANDOM ROWID #95

Open
ykuksenko opened this issue Mar 28, 2024 · 0 comments
Open

stmt.run().lastInsertRowid is wrong with RANDOM ROWID #95

ykuksenko opened this issue Mar 28, 2024 · 0 comments

Comments

@ykuksenko
Copy link

Hi, I am new to JS so it is possible I am missing something.

  • I am using the RANDOM ROWID feature with libsql. When this is enabled I cannot retrieve items using the lastInsertRowid property from stmt.run() commands after insertion. The lastInsertRowid is slightly off from the actual rowid. However using stmt.all() after a select * ... statement I can get the correct rowids.
  • Looking at the tests they do not seem to cover the BigInt/SafeIntegers use case.

Here is example code to reproduce the issue:

import Database from 'libsql';

const db = new Database(':memory:');
db.defaultSafeIntegers(true);
db.exec(`
  DROP TABLE IF EXISTS users;
  CREATE TABLE users (rowid INTEGER PRIMARY KEY, name TEXT) RANDOM ROWID;`);

const stmt_insert = db.prepare("INSERT INTO users(name) VALUES (?)");
const info_insert = stmt_insert.run('alma');
console.log([typeof info_insert.lastInsertRowid, info_insert.lastInsertRowid]);
const stmt_list = db.prepare("SELECT * from users");
const info_list = stmt_list.all()
console.log([typeof info_list[0].rowid ,info_list]);

and sample output:

$ node ex.js
[ 'number', 4504423795271622000 ]
[ 'bigint', [ { rowid: 4504423795271622254n, name: 'alma' } ] ]
@ykuksenko ykuksenko changed the title stmt.run() lastInsertRowid seems to produce only number type, not BigInt stmt.run().lastInsertRowid is wrong with RANDOM ROWID Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant