Add the json_pretty(J) function for pretty-printing of JSON. An optional
[sqlite.git] / test / tkt4018.test
blob77582a5c41d8834888b9c0afd7ec3498ddcb56f3
1 # 2009 August 20
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to verify that ticket #4018 has been
14 # fixed.  
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 do_not_use_codec
21 proc testsql {sql} {
22   set fd [open tf_main.tcl w]
23   puts $fd [subst -nocommands {
24     sqlite3_test_control_pending_byte 0x0010000
25     sqlite3 db test.db
26     set rc [catch { db eval {$sql} } msg]
27     puts -nonewline "[set rc] {[set msg]}"
28     flush stdout
29     exit
30   }]
31   close $fd
32   set fd [open "| [info nameofexec] ./tf_main.tcl" r] 
33   set res [read $fd]
34   close $fd
35   return $res
38 do_test tkt4018-1.1 {
39   execsql {
40     CREATE TABLE t1(a, b);
41     BEGIN;
42     SELECT * FROM t1;
43   }
44 } {}
46 # The database is locked by connection [db]. Open and close a second
47 # connection to test.db 10000 times. If file-descriptors are not being
48 # reused, then the process will quickly exceed its maximum number of
49 # file descriptors (1024 by default on linux).
50 do_test tkt4018-1.2 {
51   for {set i 0} {$i < 10000} {incr i} {
52     sqlite3 db2 test.db
53     db2 close
54   }
55 } {}
57 # Now check that connection [db] is still holding a SHARED lock by
58 # having a second process try to write the db.
59 do_test tkt4018-1.3 {
60   testsql {INSERT INTO t1 VALUES(3, 4)}
61 } {1 {database is locked}}
63 # Sanity checking. Have [db] release the lock and then retry the
64 # INSERT from the previous test case.
65 do_test tkt4018-1.4 {
66   db eval COMMIT
67   testsql {INSERT INTO t1 VALUES(3, 4)}
68 } {0 {}}
70 # Check that reusing a file descriptor cannot change a read-only 
71 # connection into a read-write connection.
72 do_test tkt4018-2.1 {
73   sqlite3 db2 test.db
74   execsql {INSERT INTO t1 VALUES(1, 2)} db2
75 } {}
76 do_test tkt4018-2.2 {
77   execsql {
78     BEGIN;
79     SELECT * FROM t1 ORDER BY a;
80   }
81 } {1 2 3 4}
82 do_test tkt4018-2.3 {
83   db2 close
84   sqlite3 db2 test.db -readonly 1
85   execsql COMMIT
86   catchsql {INSERT INTO t1 VALUES(5, 6)} db2
87 } {1 {attempt to write a readonly database}}
88 db2 close
90 finish_test