AnswerDotAI / AnswerDotAI/sqlite-minutils

`select last_insert_rowid()` doesn't account for ROLLBACK on transaction

Open
#22 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
17
Forks
9
PR merge metrics
No merged PRs in 30d

Description

We probably don't want to use the SQLIte function `last_insert_rowid()` to get the last_pk. Per the docs on [last_insert_rowid](https://www.sqlite.org/c3ref/last_insert_rowid.html), this is expected behavior:

> For the purposes of this routine, an [INSERT](https://www.sqlite.org/lang_insert.html) is considered to be successful even if it is subsequently rolled back.

---

Get last rowid

```sql
SELECT last_insert_rowid();
```

`0`

Now do the transaction and check the row id:

```sql
BEGIN TRANSACTION;
INSERT INTO users (username) VALUES ('puppy');
SELECT last_insert_rowid();
```

`1`

Roll the transaction back and check the table and rowid:

```sql
ROLLBACK;
SELECT last_insert_rowid();
```

`1`

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository file or test is named. Start by reproducing the transaction shown in the issue and read SQLite's last_insert_rowid documentation; done means a rolled-back insert no longer causes the library to report that rowid as the last primary key.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.