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