mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Add tests (and fixes) for the virtual table transaction interface. (CVS 3265)
FossilOrigin-Name: 8a5b121f2f26bebe3f1164bc2f504d29b74400f4
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: auth.test,v 1.35 2006/06/17 06:31:19 danielk1977 Exp $
|
||||
# $Id: auth.test,v 1.36 2006/06/17 09:39:56 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -2225,7 +2225,6 @@ do_test auth-4.2 {
|
||||
} {115 117}
|
||||
do_test auth-4.3 {
|
||||
set authargs {}
|
||||
breakpoint
|
||||
execsql {
|
||||
UPDATE v1 SET x=1 WHERE x=117
|
||||
}
|
||||
|
192
test/vtab4.test
Normal file
192
test/vtab4.test
Normal file
@ -0,0 +1,192 @@
|
||||
# 2006 June 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus is on testing the following virtual table methods:
|
||||
#
|
||||
# xBegin
|
||||
# xSync
|
||||
# xCommit
|
||||
# xRollback
|
||||
#
|
||||
# $Id: vtab4.test,v 1.1 2006/06/17 09:39:56 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
ifcapable !vtab {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Register the echo module
|
||||
db cache size 0
|
||||
register_echo_module [sqlite3_connection_pointer db]
|
||||
|
||||
do_test vtab4-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE treal(a PRIMARY KEY, b, c);
|
||||
CREATE VIRTUAL TABLE techo USING echo(treal);
|
||||
}
|
||||
} {}
|
||||
|
||||
# Test an INSERT, UPDATE and DELETE statement on the virtual table
|
||||
# in an implicit transaction. Each should result in a single call
|
||||
# to xBegin, xSync and xCommit.
|
||||
#
|
||||
do_test vtab4-1.2 {
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
INSERT INTO techo VALUES(1, 2, 3);
|
||||
}
|
||||
set echo_module
|
||||
} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
|
||||
do_test vtab4-1.3 {
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
UPDATE techo SET a = 2;
|
||||
}
|
||||
set echo_module
|
||||
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
|
||||
xBegin echo(treal) \
|
||||
xFilter {SELECT rowid, * FROM 'treal'} \
|
||||
xSync echo(treal) \
|
||||
xCommit echo(treal) \
|
||||
]
|
||||
do_test vtab4-1.4 {
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
DELETE FROM techo;
|
||||
}
|
||||
set echo_module
|
||||
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
|
||||
xBegin echo(treal) \
|
||||
xFilter {SELECT rowid, * FROM 'treal'} \
|
||||
xSync echo(treal) \
|
||||
xCommit echo(treal) \
|
||||
]
|
||||
|
||||
# Ensure xBegin is not called more than once in a single transaction.
|
||||
#
|
||||
do_test vtab4-2.1 {
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO techo VALUES(1, 2, 3);
|
||||
INSERT INTO techo VALUES(4, 5, 6);
|
||||
INSERT INTO techo VALUES(7, 8, 9);
|
||||
COMMIT;
|
||||
}
|
||||
set echo_module
|
||||
} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
|
||||
|
||||
# Try a transaction with two virtual tables.
|
||||
#
|
||||
do_test vtab4-2.2 {
|
||||
execsql {
|
||||
CREATE TABLE sreal(a, b, c UNIQUE);
|
||||
CREATE VIRTUAL TABLE secho USING echo(sreal);
|
||||
}
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO secho SELECT * FROM techo;
|
||||
DELETE FROM techo;
|
||||
COMMIT;
|
||||
}
|
||||
set echo_module
|
||||
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
|
||||
xBegin echo(sreal) \
|
||||
xFilter {SELECT rowid, * FROM 'treal'} \
|
||||
xBestIndex {SELECT rowid, * FROM 'treal'} \
|
||||
xBegin echo(treal) \
|
||||
xFilter {SELECT rowid, * FROM 'treal'} \
|
||||
xSync echo(sreal) \
|
||||
xSync echo(treal) \
|
||||
xCommit echo(sreal) \
|
||||
xCommit echo(treal) \
|
||||
]
|
||||
do_test vtab4-2.3 {
|
||||
execsql {
|
||||
SELECT * FROM secho;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9}
|
||||
do_test vtab4-2.4 {
|
||||
execsql {
|
||||
SELECT * FROM techo;
|
||||
}
|
||||
} {}
|
||||
|
||||
# Try an explicit ROLLBACK on a transaction with two open virtual tables.
|
||||
do_test vtab4-2.5 {
|
||||
set echo_module [list]
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO techo SELECT * FROM secho;
|
||||
DELETE FROM secho;
|
||||
ROLLBACK;
|
||||
}
|
||||
set echo_module
|
||||
} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
|
||||
xBegin echo(treal) \
|
||||
xFilter {SELECT rowid, * FROM 'sreal'} \
|
||||
xBestIndex {SELECT rowid, * FROM 'sreal'} \
|
||||
xBegin echo(sreal) \
|
||||
xFilter {SELECT rowid, * FROM 'sreal'} \
|
||||
xRollback echo(treal) \
|
||||
xRollback echo(sreal) \
|
||||
]
|
||||
do_test vtab4-2.6 {
|
||||
execsql {
|
||||
SELECT * FROM secho;
|
||||
}
|
||||
} {1 2 3 4 5 6 7 8 9}
|
||||
do_test vtab4-2.7 {
|
||||
execsql {
|
||||
SELECT * FROM techo;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test vtab4-3.1 {
|
||||
set echo_module [list]
|
||||
set echo_module_sync_fail treal
|
||||
catchsql {
|
||||
INSERT INTO techo VALUES(1, 2, 3);
|
||||
}
|
||||
} {1 {unknown error}}
|
||||
do_test vtab4-3.2 {
|
||||
set echo_module
|
||||
} {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)}
|
||||
|
||||
breakpoint
|
||||
do_test vtab4-3.3 {
|
||||
set echo_module [list]
|
||||
set echo_module_sync_fail sreal
|
||||
catchsql {
|
||||
BEGIN;
|
||||
INSERT INTO techo SELECT * FROM secho;
|
||||
DELETE FROM secho;
|
||||
COMMIT;
|
||||
}
|
||||
set echo_module
|
||||
} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
|
||||
xBegin echo(treal) \
|
||||
xFilter {SELECT rowid, * FROM 'sreal'} \
|
||||
xBestIndex {SELECT rowid, * FROM 'sreal'} \
|
||||
xBegin echo(sreal) \
|
||||
xFilter {SELECT rowid, * FROM 'sreal'} \
|
||||
xSync echo(treal) \
|
||||
xSync echo(sreal) \
|
||||
xRollback echo(treal) \
|
||||
xRollback echo(sreal) \
|
||||
]
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user