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