1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab4.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,193 @@
1.4 +# 2006 June 10
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus is on testing the following virtual table methods:
1.16 +#
1.17 +# xBegin
1.18 +# xSync
1.19 +# xCommit
1.20 +# xRollback
1.21 +#
1.22 +# $Id: vtab4.test,v 1.3 2008/07/12 14:52:21 drh Exp $
1.23 +
1.24 +set testdir [file dirname $argv0]
1.25 +source $testdir/tester.tcl
1.26 +
1.27 +unset -nocomplain echo_module
1.28 +unset -nocomplain echo_module_sync_fail
1.29 +
1.30 +ifcapable !vtab {
1.31 + finish_test
1.32 + return
1.33 +}
1.34 +
1.35 +# Register the echo module
1.36 +db cache size 0
1.37 +register_echo_module [sqlite3_connection_pointer db]
1.38 +
1.39 +do_test vtab4-1.1 {
1.40 + execsql {
1.41 + CREATE TABLE treal(a PRIMARY KEY, b, c);
1.42 + CREATE VIRTUAL TABLE techo USING echo(treal);
1.43 + }
1.44 +} {}
1.45 +
1.46 +# Test an INSERT, UPDATE and DELETE statement on the virtual table
1.47 +# in an implicit transaction. Each should result in a single call
1.48 +# to xBegin, xSync and xCommit.
1.49 +#
1.50 +do_test vtab4-1.2 {
1.51 + set echo_module [list]
1.52 + execsql {
1.53 + INSERT INTO techo VALUES(1, 2, 3);
1.54 + }
1.55 + set echo_module
1.56 +} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
1.57 +do_test vtab4-1.3 {
1.58 + set echo_module [list]
1.59 + execsql {
1.60 + UPDATE techo SET a = 2;
1.61 + }
1.62 + set echo_module
1.63 +} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
1.64 + xBegin echo(treal) \
1.65 + xFilter {SELECT rowid, * FROM 'treal'} \
1.66 + xSync echo(treal) \
1.67 + xCommit echo(treal) \
1.68 +]
1.69 +do_test vtab4-1.4 {
1.70 + set echo_module [list]
1.71 + execsql {
1.72 + DELETE FROM techo;
1.73 + }
1.74 + set echo_module
1.75 +} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
1.76 + xBegin echo(treal) \
1.77 + xFilter {SELECT rowid, * FROM 'treal'} \
1.78 + xSync echo(treal) \
1.79 + xCommit echo(treal) \
1.80 +]
1.81 +
1.82 +# Ensure xBegin is not called more than once in a single transaction.
1.83 +#
1.84 +do_test vtab4-2.1 {
1.85 + set echo_module [list]
1.86 + execsql {
1.87 + BEGIN;
1.88 + INSERT INTO techo VALUES(1, 2, 3);
1.89 + INSERT INTO techo VALUES(4, 5, 6);
1.90 + INSERT INTO techo VALUES(7, 8, 9);
1.91 + COMMIT;
1.92 + }
1.93 + set echo_module
1.94 +} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
1.95 +
1.96 +# Try a transaction with two virtual tables.
1.97 +#
1.98 +do_test vtab4-2.2 {
1.99 + execsql {
1.100 + CREATE TABLE sreal(a, b, c UNIQUE);
1.101 + CREATE VIRTUAL TABLE secho USING echo(sreal);
1.102 + }
1.103 + set echo_module [list]
1.104 + execsql {
1.105 + BEGIN;
1.106 + INSERT INTO secho SELECT * FROM techo;
1.107 + DELETE FROM techo;
1.108 + COMMIT;
1.109 + }
1.110 + set echo_module
1.111 +} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
1.112 + xBegin echo(sreal) \
1.113 + xFilter {SELECT rowid, * FROM 'treal'} \
1.114 + xBestIndex {SELECT rowid, * FROM 'treal'} \
1.115 + xBegin echo(treal) \
1.116 + xFilter {SELECT rowid, * FROM 'treal'} \
1.117 + xSync echo(sreal) \
1.118 + xSync echo(treal) \
1.119 + xCommit echo(sreal) \
1.120 + xCommit echo(treal) \
1.121 +]
1.122 +do_test vtab4-2.3 {
1.123 + execsql {
1.124 + SELECT * FROM secho;
1.125 + }
1.126 +} {1 2 3 4 5 6 7 8 9}
1.127 +do_test vtab4-2.4 {
1.128 + execsql {
1.129 + SELECT * FROM techo;
1.130 + }
1.131 +} {}
1.132 +
1.133 +# Try an explicit ROLLBACK on a transaction with two open virtual tables.
1.134 +do_test vtab4-2.5 {
1.135 + set echo_module [list]
1.136 + execsql {
1.137 + BEGIN;
1.138 + INSERT INTO techo SELECT * FROM secho;
1.139 + DELETE FROM secho;
1.140 + ROLLBACK;
1.141 + }
1.142 + set echo_module
1.143 +} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
1.144 + xBegin echo(treal) \
1.145 + xFilter {SELECT rowid, * FROM 'sreal'} \
1.146 + xBestIndex {SELECT rowid, * FROM 'sreal'} \
1.147 + xBegin echo(sreal) \
1.148 + xFilter {SELECT rowid, * FROM 'sreal'} \
1.149 + xRollback echo(treal) \
1.150 + xRollback echo(sreal) \
1.151 +]
1.152 +do_test vtab4-2.6 {
1.153 + execsql {
1.154 + SELECT * FROM secho;
1.155 + }
1.156 +} {1 2 3 4 5 6 7 8 9}
1.157 +do_test vtab4-2.7 {
1.158 + execsql {
1.159 + SELECT * FROM techo;
1.160 + }
1.161 +} {}
1.162 +
1.163 +do_test vtab4-3.1 {
1.164 + set echo_module [list]
1.165 + set echo_module_sync_fail treal
1.166 + catchsql {
1.167 + INSERT INTO techo VALUES(1, 2, 3);
1.168 + }
1.169 +} {1 {unknown error}}
1.170 +do_test vtab4-3.2 {
1.171 + set echo_module
1.172 +} {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)}
1.173 +
1.174 +do_test vtab4-3.3 {
1.175 + set echo_module [list]
1.176 + set echo_module_sync_fail sreal
1.177 + catchsql {
1.178 + BEGIN;
1.179 + INSERT INTO techo SELECT * FROM secho;
1.180 + DELETE FROM secho;
1.181 + COMMIT;
1.182 + }
1.183 + set echo_module
1.184 +} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
1.185 + xBegin echo(treal) \
1.186 + xFilter {SELECT rowid, * FROM 'sreal'} \
1.187 + xBestIndex {SELECT rowid, * FROM 'sreal'} \
1.188 + xBegin echo(sreal) \
1.189 + xFilter {SELECT rowid, * FROM 'sreal'} \
1.190 + xSync echo(treal) \
1.191 + xSync echo(sreal) \
1.192 + xRollback echo(treal) \
1.193 + xRollback echo(sreal) \
1.194 +]
1.195 +
1.196 +finish_test