os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab4.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2006 June 10
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library. The
sl@0
    12
# focus is on testing the following virtual table methods:
sl@0
    13
#
sl@0
    14
#     xBegin
sl@0
    15
#     xSync
sl@0
    16
#     xCommit
sl@0
    17
#     xRollback
sl@0
    18
#
sl@0
    19
# $Id: vtab4.test,v 1.3 2008/07/12 14:52:21 drh Exp $
sl@0
    20
sl@0
    21
set testdir [file dirname $argv0]
sl@0
    22
source $testdir/tester.tcl
sl@0
    23
sl@0
    24
unset -nocomplain echo_module
sl@0
    25
unset -nocomplain echo_module_sync_fail
sl@0
    26
sl@0
    27
ifcapable !vtab {
sl@0
    28
  finish_test
sl@0
    29
  return
sl@0
    30
}
sl@0
    31
sl@0
    32
# Register the echo module
sl@0
    33
db cache size 0
sl@0
    34
register_echo_module [sqlite3_connection_pointer db]
sl@0
    35
sl@0
    36
do_test vtab4-1.1 {
sl@0
    37
  execsql {
sl@0
    38
    CREATE TABLE treal(a PRIMARY KEY, b, c);
sl@0
    39
    CREATE VIRTUAL TABLE techo USING echo(treal);
sl@0
    40
  }
sl@0
    41
} {}
sl@0
    42
sl@0
    43
# Test an INSERT, UPDATE and DELETE statement on the virtual table
sl@0
    44
# in an implicit transaction. Each should result in a single call
sl@0
    45
# to xBegin, xSync and xCommit.
sl@0
    46
#
sl@0
    47
do_test vtab4-1.2 {
sl@0
    48
  set echo_module [list]
sl@0
    49
  execsql {
sl@0
    50
    INSERT INTO techo VALUES(1, 2, 3);
sl@0
    51
  }
sl@0
    52
  set echo_module
sl@0
    53
} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
sl@0
    54
do_test vtab4-1.3 {
sl@0
    55
  set echo_module [list]
sl@0
    56
  execsql {
sl@0
    57
    UPDATE techo SET a = 2;
sl@0
    58
  }
sl@0
    59
  set echo_module
sl@0
    60
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
sl@0
    61
        xBegin     echo(treal)                    \
sl@0
    62
        xFilter    {SELECT rowid, * FROM 'treal'} \
sl@0
    63
        xSync      echo(treal)                    \
sl@0
    64
        xCommit    echo(treal)                    \
sl@0
    65
]
sl@0
    66
do_test vtab4-1.4 {
sl@0
    67
  set echo_module [list]
sl@0
    68
  execsql {
sl@0
    69
    DELETE FROM techo;
sl@0
    70
  }
sl@0
    71
  set echo_module
sl@0
    72
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
sl@0
    73
        xBegin     echo(treal)                    \
sl@0
    74
        xFilter    {SELECT rowid, * FROM 'treal'} \
sl@0
    75
        xSync      echo(treal)                    \
sl@0
    76
        xCommit    echo(treal)                    \
sl@0
    77
]
sl@0
    78
sl@0
    79
# Ensure xBegin is not called more than once in a single transaction.
sl@0
    80
#
sl@0
    81
do_test vtab4-2.1 {
sl@0
    82
  set echo_module [list]
sl@0
    83
  execsql {
sl@0
    84
    BEGIN;
sl@0
    85
    INSERT INTO techo VALUES(1, 2, 3);
sl@0
    86
    INSERT INTO techo VALUES(4, 5, 6);
sl@0
    87
    INSERT INTO techo VALUES(7, 8, 9);
sl@0
    88
    COMMIT;
sl@0
    89
  }
sl@0
    90
  set echo_module
sl@0
    91
} {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
sl@0
    92
sl@0
    93
# Try a transaction with two virtual tables.
sl@0
    94
#
sl@0
    95
do_test vtab4-2.2 {
sl@0
    96
  execsql {
sl@0
    97
    CREATE TABLE sreal(a, b, c UNIQUE);
sl@0
    98
    CREATE VIRTUAL TABLE secho USING echo(sreal);
sl@0
    99
  }
sl@0
   100
  set echo_module [list]
sl@0
   101
  execsql {
sl@0
   102
    BEGIN;
sl@0
   103
    INSERT INTO secho SELECT * FROM techo;
sl@0
   104
    DELETE FROM techo;
sl@0
   105
    COMMIT;
sl@0
   106
  }
sl@0
   107
  set echo_module
sl@0
   108
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
sl@0
   109
        xBegin     echo(sreal)                    \
sl@0
   110
        xFilter    {SELECT rowid, * FROM 'treal'} \
sl@0
   111
        xBestIndex {SELECT rowid, * FROM 'treal'} \
sl@0
   112
        xBegin     echo(treal)                    \
sl@0
   113
        xFilter    {SELECT rowid, * FROM 'treal'} \
sl@0
   114
        xSync   echo(sreal)                       \
sl@0
   115
        xSync   echo(treal)                       \
sl@0
   116
        xCommit echo(sreal)                       \
sl@0
   117
        xCommit echo(treal)                       \
sl@0
   118
]
sl@0
   119
do_test vtab4-2.3 {
sl@0
   120
  execsql {
sl@0
   121
    SELECT * FROM secho;
sl@0
   122
  }
sl@0
   123
} {1 2 3 4 5 6 7 8 9}
sl@0
   124
do_test vtab4-2.4 {
sl@0
   125
  execsql {
sl@0
   126
    SELECT * FROM techo;
sl@0
   127
  }
sl@0
   128
} {}
sl@0
   129
sl@0
   130
# Try an explicit ROLLBACK on a transaction with two open virtual tables.
sl@0
   131
do_test vtab4-2.5 {
sl@0
   132
  set echo_module [list]
sl@0
   133
  execsql {
sl@0
   134
    BEGIN;
sl@0
   135
    INSERT INTO techo SELECT * FROM secho;
sl@0
   136
    DELETE FROM secho;
sl@0
   137
    ROLLBACK;
sl@0
   138
  }
sl@0
   139
  set echo_module
sl@0
   140
} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
sl@0
   141
        xBegin     echo(treal)                    \
sl@0
   142
        xFilter    {SELECT rowid, * FROM 'sreal'} \
sl@0
   143
        xBestIndex {SELECT rowid, * FROM 'sreal'} \
sl@0
   144
        xBegin     echo(sreal)                    \
sl@0
   145
        xFilter    {SELECT rowid, * FROM 'sreal'} \
sl@0
   146
        xRollback  echo(treal)                    \
sl@0
   147
        xRollback  echo(sreal)                    \
sl@0
   148
]
sl@0
   149
do_test vtab4-2.6 {
sl@0
   150
  execsql {
sl@0
   151
    SELECT * FROM secho;
sl@0
   152
  }
sl@0
   153
} {1 2 3 4 5 6 7 8 9}
sl@0
   154
do_test vtab4-2.7 {
sl@0
   155
  execsql {
sl@0
   156
    SELECT * FROM techo;
sl@0
   157
  }
sl@0
   158
} {}
sl@0
   159
sl@0
   160
do_test vtab4-3.1 {
sl@0
   161
  set echo_module [list]
sl@0
   162
  set echo_module_sync_fail treal
sl@0
   163
  catchsql {
sl@0
   164
    INSERT INTO techo VALUES(1, 2, 3);
sl@0
   165
  }
sl@0
   166
} {1 {unknown error}}
sl@0
   167
do_test vtab4-3.2 {
sl@0
   168
  set echo_module
sl@0
   169
} {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)}
sl@0
   170
sl@0
   171
do_test vtab4-3.3 {
sl@0
   172
  set echo_module [list]
sl@0
   173
  set echo_module_sync_fail sreal
sl@0
   174
  catchsql {
sl@0
   175
    BEGIN;
sl@0
   176
    INSERT INTO techo SELECT * FROM secho;
sl@0
   177
    DELETE FROM secho;
sl@0
   178
    COMMIT;
sl@0
   179
  }
sl@0
   180
  set echo_module
sl@0
   181
} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
sl@0
   182
        xBegin     echo(treal)                    \
sl@0
   183
        xFilter    {SELECT rowid, * FROM 'sreal'} \
sl@0
   184
        xBestIndex {SELECT rowid, * FROM 'sreal'} \
sl@0
   185
        xBegin     echo(sreal)                    \
sl@0
   186
        xFilter    {SELECT rowid, * FROM 'sreal'} \
sl@0
   187
        xSync      echo(treal)                    \
sl@0
   188
        xSync      echo(sreal)                    \
sl@0
   189
        xRollback  echo(treal)                    \
sl@0
   190
        xRollback  echo(sreal)                    \
sl@0
   191
]
sl@0
   192
sl@0
   193
finish_test