Dear group,
We encountered a somewhat obscure scenario that leaves an sqlite database in a
corrupted state (tested with sqlite 3.8.8).
Our case deals with
- an in-memory database "db" with an attached file database "other.db".
- "db" starts a transaction,
- "db" tries to create a table in the attached "other.db" using "create table
... as select ...", but the "select" raises an error.
- "db" commits the transaction.
As a result, the attached database is corrupted. The corruption seems to take
place during the final commit.
The following Tcl script reproduces the problem:
------------------------
package require sqlite3
sqlite3 db :memory:
catch {file delete other.db}
sqlite3 odb other.db
odb eval {create table dummy(whatever text);}
puts "check that other.db is ok:[odb eval {select count(*) from dummy}]"
rename odb ""
db function myerror myerror
proc myerror args {error "deliberate error"}
db eval {attach [other.db] as other}
catch {
db transaction {
catch {
db eval {create table other.xxx as select myerror()}
}
# error "--- without this error the other.db gets corrupted ---"
}
}
sqlite3 odb2 other.db
puts "check that other.db is ok:[odb2 eval {select count(*) from dummy}]"
------------------------
This is the output:
------------------------
check that other.db is ok:0
malformed database schema (?)
while executing
"odb2 eval {select count(*) from dummy}"
invoked from within
"puts "check that other.db is ok:[odb2 eval {select count(*) from dummy}]""
(file "bugreport.tcl" line 26)
------------------------
If the commented line is activated the other.db is not corrupted.
Best Regards,
Christian