SQLite Forum

Recover Database
Login
Let me recap what I've understood what has been said:
a) you can nest save points;
b) save points may have a begin-instruction.

What about a little experiment. Here is my code for the experiment:
  1 SAVEPOINT "A";
  2 CREATE TABLE T1 (X TEXT  NOT NULL DEFAULT "");
  3 
  4 SAVEPOINT "B";
  5 INSERT INTO T1 (X)
  6 VALUES ("A"), ("B");
  7 SELECT "What was inserted?";
  8 SELECT * FROM T1;
  9 BEGIN;
 10         INSERT INTO T1 (X)
 11         SELECT "C";
 12         SELECT "What was inserted?";
 13         SELECT * FROM T1;
 14         ROLLBACK;
 15         SELECT "What was inserted?";
 16         SELECT * FROM T1;
 17 END;
 18 DELETE FROM T1;
 19 SELECT "What was inserted?";
 20 SELECT * FROM T1;
 21 ROLLBACK;
 22 SELECT "What was inserted?";
 23 SELECT * FROM T1;
 24 

save as 't1.sql' and execute sqlite3 t1.db < t1.sql

Here is the result:
What was inserted?
A
B
Error: near line 9: cannot start a transaction within a transaction
What was inserted?
A
B
C
What was inserted?
Error: near line 16: no such table: T1 (→ Rolled the database back to save point A
Error: near line 17: cannot commit - no transaction is active
Error: near line 18: no such table: T1
What was inserted?
Error: near line 20: no such table: T1
Error: near line 21: cannot rollback - no transaction is active
What was inserted?
Error: near line 23: no such table: T1

I think the behavior is different from what I've understood, and I think it isn't compliant with what is stipulated on this page https://sqlite.org/lang_savepoint.html