1# 2013-07-11 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. 12# 13# This file tests the "query_only" pragma. 14# 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18 19do_execsql_test queryonly-1.1 { 20 CREATE TABLE t1(a); 21 INSERT INTO t1 VALUES(123),(456); 22 SELECT a FROM t1 ORDER BY a; 23} {123 456} 24do_execsql_test queryonly-1.2 { 25 PRAGMA query_only; 26} {0} 27do_execsql_test queryonly-1.3 { 28 PRAGMA query_only=ON; 29 PRAGMA query_only; 30} {1} 31do_test queryonly-1.4 { 32 catchsql {INSERT INTO t1 VALUES(789);} 33} {1 {attempt to write a readonly database}} 34do_test queryonly-1.5 { 35 catchsql {DELETE FROM t1;} 36} {1 {attempt to write a readonly database}} 37do_test queryonly-1.6 { 38 catchsql {UPDATE t1 SET a=a+1;} 39} {1 {attempt to write a readonly database}} 40do_test queryonly-1.7 { 41 catchsql {CREATE TABLE t2(b);} 42} {1 {attempt to write a readonly database}} 43do_test queryonly-1.8 { 44 catchsql {CREATE INDEX t1a ON t1(a);} 45} {1 {attempt to write a readonly database}} 46do_test queryonly-1.9 { 47 catchsql {DROP TABLE t1;} 48} {1 {attempt to write a readonly database}} 49do_test queryonly-1.10 { 50 catchsql {ANALYZE;} 51} {1 {attempt to write a readonly database}} 52do_execsql_test queryonly-1.11 { 53 SELECT a FROM t1 ORDER BY a; 54} {123 456} 55 56do_execsql_test queryonly-2.2 { 57 PRAGMA query_only; 58} {1} 59do_execsql_test queryonly-2.3 { 60 PRAGMA query_only=OFF; 61 PRAGMA query_only; 62} {0} 63do_execsql_test queryonly-2.4 { 64 INSERT INTO t1 VALUES(789); 65 SELECT a FROM t1 ORDER BY a; 66} {123 456 789} 67do_execsql_test queryonly-2.5 { 68 UPDATE t1 SET a=a+1; 69 SELECT a FROM t1 ORDER BY a; 70} {124 457 790} 71 72finish_test 73