Skip to content

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

@pydanny

Description

@pydanny

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, this is expected behavior:

For the purposes of this routine, an INSERT is considered to be successful even if it is subsequently rolled back.


Get last rowid

SELECT last_insert_rowid();

0

Now do the transaction and check the row id:

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

1

Roll the transaction back and check the table and rowid:

ROLLBACK;
SELECT last_insert_rowid();

1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions