sl@0: # 2006 June 10 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus is on testing the following virtual table methods: sl@0: # sl@0: # xBegin sl@0: # xSync sl@0: # xCommit sl@0: # xRollback sl@0: # sl@0: # $Id: vtab4.test,v 1.3 2008/07/12 14:52:21 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: unset -nocomplain echo_module sl@0: unset -nocomplain echo_module_sync_fail sl@0: sl@0: ifcapable !vtab { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Register the echo module sl@0: db cache size 0 sl@0: register_echo_module [sqlite3_connection_pointer db] sl@0: sl@0: do_test vtab4-1.1 { sl@0: execsql { sl@0: CREATE TABLE treal(a PRIMARY KEY, b, c); sl@0: CREATE VIRTUAL TABLE techo USING echo(treal); sl@0: } sl@0: } {} sl@0: sl@0: # Test an INSERT, UPDATE and DELETE statement on the virtual table sl@0: # in an implicit transaction. Each should result in a single call sl@0: # to xBegin, xSync and xCommit. sl@0: # sl@0: do_test vtab4-1.2 { sl@0: set echo_module [list] sl@0: execsql { sl@0: INSERT INTO techo VALUES(1, 2, 3); sl@0: } sl@0: set echo_module sl@0: } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)} sl@0: do_test vtab4-1.3 { sl@0: set echo_module [list] sl@0: execsql { sl@0: UPDATE techo SET a = 2; sl@0: } sl@0: set echo_module sl@0: } [list xBestIndex {SELECT rowid, * FROM 'treal'} \ sl@0: xBegin echo(treal) \ sl@0: xFilter {SELECT rowid, * FROM 'treal'} \ sl@0: xSync echo(treal) \ sl@0: xCommit echo(treal) \ sl@0: ] sl@0: do_test vtab4-1.4 { sl@0: set echo_module [list] sl@0: execsql { sl@0: DELETE FROM techo; sl@0: } sl@0: set echo_module sl@0: } [list xBestIndex {SELECT rowid, * FROM 'treal'} \ sl@0: xBegin echo(treal) \ sl@0: xFilter {SELECT rowid, * FROM 'treal'} \ sl@0: xSync echo(treal) \ sl@0: xCommit echo(treal) \ sl@0: ] sl@0: sl@0: # Ensure xBegin is not called more than once in a single transaction. sl@0: # sl@0: do_test vtab4-2.1 { sl@0: set echo_module [list] sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO techo VALUES(1, 2, 3); sl@0: INSERT INTO techo VALUES(4, 5, 6); sl@0: INSERT INTO techo VALUES(7, 8, 9); sl@0: COMMIT; sl@0: } sl@0: set echo_module sl@0: } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)} sl@0: sl@0: # Try a transaction with two virtual tables. sl@0: # sl@0: do_test vtab4-2.2 { sl@0: execsql { sl@0: CREATE TABLE sreal(a, b, c UNIQUE); sl@0: CREATE VIRTUAL TABLE secho USING echo(sreal); sl@0: } sl@0: set echo_module [list] sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO secho SELECT * FROM techo; sl@0: DELETE FROM techo; sl@0: COMMIT; sl@0: } sl@0: set echo_module sl@0: } [list xBestIndex {SELECT rowid, * FROM 'treal'} \ sl@0: xBegin echo(sreal) \ sl@0: xFilter {SELECT rowid, * FROM 'treal'} \ sl@0: xBestIndex {SELECT rowid, * FROM 'treal'} \ sl@0: xBegin echo(treal) \ sl@0: xFilter {SELECT rowid, * FROM 'treal'} \ sl@0: xSync echo(sreal) \ sl@0: xSync echo(treal) \ sl@0: xCommit echo(sreal) \ sl@0: xCommit echo(treal) \ sl@0: ] sl@0: do_test vtab4-2.3 { sl@0: execsql { sl@0: SELECT * FROM secho; sl@0: } sl@0: } {1 2 3 4 5 6 7 8 9} sl@0: do_test vtab4-2.4 { sl@0: execsql { sl@0: SELECT * FROM techo; sl@0: } sl@0: } {} sl@0: sl@0: # Try an explicit ROLLBACK on a transaction with two open virtual tables. sl@0: do_test vtab4-2.5 { sl@0: set echo_module [list] sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO techo SELECT * FROM secho; sl@0: DELETE FROM secho; sl@0: ROLLBACK; sl@0: } sl@0: set echo_module sl@0: } [list xBestIndex {SELECT rowid, * FROM 'sreal'} \ sl@0: xBegin echo(treal) \ sl@0: xFilter {SELECT rowid, * FROM 'sreal'} \ sl@0: xBestIndex {SELECT rowid, * FROM 'sreal'} \ sl@0: xBegin echo(sreal) \ sl@0: xFilter {SELECT rowid, * FROM 'sreal'} \ sl@0: xRollback echo(treal) \ sl@0: xRollback echo(sreal) \ sl@0: ] sl@0: do_test vtab4-2.6 { sl@0: execsql { sl@0: SELECT * FROM secho; sl@0: } sl@0: } {1 2 3 4 5 6 7 8 9} sl@0: do_test vtab4-2.7 { sl@0: execsql { sl@0: SELECT * FROM techo; sl@0: } sl@0: } {} sl@0: sl@0: do_test vtab4-3.1 { sl@0: set echo_module [list] sl@0: set echo_module_sync_fail treal sl@0: catchsql { sl@0: INSERT INTO techo VALUES(1, 2, 3); sl@0: } sl@0: } {1 {unknown error}} sl@0: do_test vtab4-3.2 { sl@0: set echo_module sl@0: } {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)} sl@0: sl@0: do_test vtab4-3.3 { sl@0: set echo_module [list] sl@0: set echo_module_sync_fail sreal sl@0: catchsql { sl@0: BEGIN; sl@0: INSERT INTO techo SELECT * FROM secho; sl@0: DELETE FROM secho; sl@0: COMMIT; sl@0: } sl@0: set echo_module sl@0: } [list xBestIndex {SELECT rowid, * FROM 'sreal'} \ sl@0: xBegin echo(treal) \ sl@0: xFilter {SELECT rowid, * FROM 'sreal'} \ sl@0: xBestIndex {SELECT rowid, * FROM 'sreal'} \ sl@0: xBegin echo(sreal) \ sl@0: xFilter {SELECT rowid, * FROM 'sreal'} \ sl@0: xSync echo(treal) \ sl@0: xSync echo(sreal) \ sl@0: xRollback echo(treal) \ sl@0: xRollback echo(sreal) \ sl@0: ] sl@0: sl@0: finish_test