persistentstorage/sqlite3api/TEST/TclScript/lock5.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 # 2008 June 28
       
     2 #
       
     3 # The author disclaims copyright to this source code.  In place of
       
     4 # a legal notice, here is a blessing:
       
     5 #
       
     6 #    May you do good and not evil.
       
     7 #    May you find forgiveness for yourself and forgive others.
       
     8 #    May you share freely, never taking more than you give.
       
     9 #
       
    10 #***********************************************************************
       
    11 # This file implements regression tests for SQLite library.  The
       
    12 # focus of this script is database locks.
       
    13 #
       
    14 # $Id: lock5.test,v 1.3 2008/09/24 09:12:47 danielk1977 Exp $
       
    15 
       
    16 set testdir [file dirname $argv0]
       
    17 source $testdir/tester.tcl
       
    18 
       
    19 # This file is only run if using the unix backend compiled with the
       
    20 # SQLITE_ENABLE_LOCKING_STYLE macro.
       
    21 db close
       
    22 if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
       
    23   finish_test
       
    24   return
       
    25 }
       
    26 db close
       
    27 
       
    28 do_test lock5-dotfile.1 {
       
    29   sqlite3 db test.db -vfs unix-dotfile
       
    30   execsql {
       
    31     BEGIN;
       
    32     CREATE TABLE t1(a, b);
       
    33   }
       
    34 } {}
       
    35 
       
    36 do_test lock5-dotfile.2 {
       
    37   file exists test.db.lock
       
    38 } {1}
       
    39 
       
    40 do_test lock5-dotfile.3 {
       
    41   execsql COMMIT
       
    42   file exists test.db.lock
       
    43 } {0}
       
    44 
       
    45 do_test lock5-dotfile.4 {
       
    46   sqlite3 db2 test.db -vfs unix-dotfile
       
    47   execsql {
       
    48     INSERT INTO t1 VALUES('a', 'b');
       
    49     SELECT * FROM t1;
       
    50   } db2
       
    51 } {a b}
       
    52 
       
    53 do_test lock5-dotfile.5 {
       
    54   execsql {
       
    55     BEGIN;
       
    56     SELECT * FROM t1;
       
    57   } db2
       
    58 } {a b}
       
    59 
       
    60 do_test lock5-dotfile.6 {
       
    61   file exists test.db.lock
       
    62 } {1}
       
    63 
       
    64 do_test lock5-dotfile.7 {
       
    65   catchsql { SELECT * FROM t1; }
       
    66 } {1 {database is locked}}
       
    67 
       
    68 do_test lock5-dotfile.8 {
       
    69   execsql {
       
    70     SELECT * FROM t1;
       
    71     ROLLBACK;
       
    72   } db2
       
    73 } {a b}
       
    74 
       
    75 do_test lock5-dotfile.9 {
       
    76   catchsql { SELECT * FROM t1; }
       
    77 } {0 {a b}}
       
    78 
       
    79 do_test lock5-dotfile.10 {
       
    80   file exists test.db.lock
       
    81 } {0}
       
    82 
       
    83 do_test lock5-dotfile.X {
       
    84   db2 close
       
    85   execsql {BEGIN EXCLUSIVE}
       
    86   db close
       
    87   file exists test.db.lock
       
    88 } {0}
       
    89 
       
    90 #####################################################################
       
    91 
       
    92 file delete -force test.db
       
    93 
       
    94 do_test lock5-flock.1 {
       
    95   sqlite3 db test.db -vfs unix-flock
       
    96   execsql {
       
    97     CREATE TABLE t1(a, b);
       
    98     BEGIN;
       
    99     INSERT INTO t1 VALUES(1, 2);
       
   100   }
       
   101 } {}
       
   102 
       
   103 # Make sure we are not accidentally using the dotfile locking scheme.
       
   104 do_test lock5-flock.2 {
       
   105   file exists test.db.lock
       
   106 } {0}
       
   107 
       
   108 do_test lock5-flock.3 {
       
   109   sqlite3 db2 test.db -vfs unix-flock
       
   110   catchsql { SELECT * FROM t1 } db2
       
   111 } {1 {database is locked}}
       
   112 
       
   113 do_test lock5-flock.4 {
       
   114   execsql COMMIT
       
   115   catchsql { SELECT * FROM t1 } db2
       
   116 } {0 {1 2}}
       
   117 
       
   118 do_test lock5-flock.5 {
       
   119   execsql BEGIN
       
   120   catchsql { SELECT * FROM t1 } db2
       
   121 } {0 {1 2}}
       
   122 
       
   123 do_test lock5-flock.6 {
       
   124   execsql {SELECT * FROM t1}
       
   125   catchsql { SELECT * FROM t1 } db2
       
   126 } {1 {database is locked}}
       
   127 
       
   128 do_test lock5-flock.7 {
       
   129   db close
       
   130   catchsql { SELECT * FROM t1 } db2
       
   131 } {0 {1 2}}
       
   132 
       
   133 do_test lock5-flock.8 {
       
   134   db2 close
       
   135 } {}
       
   136 
       
   137 #####################################################################
       
   138 
       
   139 do_test lock5-none.1 {
       
   140   sqlite3 db test.db -vfs unix-none
       
   141   sqlite3 db2 test.db -vfs unix-none
       
   142   execsql {
       
   143     BEGIN;
       
   144     INSERT INTO t1 VALUES(3, 4);
       
   145   }
       
   146 } {}
       
   147 do_test lock5-none.2 {
       
   148   execsql { SELECT * FROM t1 }
       
   149 } {1 2 3 4}
       
   150 do_test lock5-flock.3 {
       
   151   execsql { SELECT * FROM t1 } db2
       
   152 } {1 2}
       
   153 do_test lock5-none.4 {
       
   154   execsql { 
       
   155     BEGIN;
       
   156     SELECT * FROM t1;
       
   157   } db2
       
   158 } {1 2}
       
   159 do_test lock5-none.5 {
       
   160   execsql COMMIT
       
   161   execsql {SELECT * FROM t1} db2
       
   162 } {1 2}
       
   163 
       
   164 ifcapable memorymanage {
       
   165   do_test lock5-none.6 {
       
   166     sqlite3_release_memory 1000000
       
   167     execsql {SELECT * FROM t1} db2
       
   168   } {1 2 3 4}
       
   169 }
       
   170 
       
   171 do_test lock5-flock.X {
       
   172   db close
       
   173   db2 close
       
   174 } {}
       
   175 
       
   176 finish_test