queryonly.test 1.9 KB

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