rdonly.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # 2007 April 24
  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 implements tests to make sure SQLite treats a database
  14. # as readonly if its write version is set to high.
  15. #
  16. # $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # Do not use a codec for tests in this file, as the database file is
  20. # manipulated directly using tcl scripts (using the [hexio_write] command).
  21. #
  22. do_not_use_codec
  23. # Create a database.
  24. #
  25. do_test rdonly-1.1 {
  26. execsql {
  27. CREATE TABLE t1(x);
  28. INSERT INTO t1 VALUES(1);
  29. SELECT * FROM t1;
  30. }
  31. } {1}
  32. # Changes the write version from 1 to 3. Verify that the database
  33. # can be read but not written.
  34. #
  35. do_test rdonly-1.2 {
  36. db close
  37. hexio_get_int [hexio_read test.db 18 1]
  38. } 1
  39. do_test rdonly-1.3 {
  40. hexio_write test.db 18 03
  41. sqlite3 db test.db
  42. execsql {
  43. SELECT * FROM t1;
  44. }
  45. } {1}
  46. do_test rdonly-1.4 {
  47. catchsql {
  48. INSERT INTO t1 VALUES(2)
  49. }
  50. } {1 {attempt to write a readonly database}}
  51. # Change the write version back to 1. Verify that the database
  52. # is read-write again.
  53. #
  54. do_test rdonly-1.5 {
  55. db close
  56. hexio_write test.db 18 01
  57. sqlite3 db test.db
  58. catchsql {
  59. INSERT INTO t1 VALUES(2);
  60. SELECT * FROM t1;
  61. }
  62. } {0 {1 2}}
  63. # Now, after connection [db] has loaded the database schema, modify the
  64. # write-version of the file (and the change-counter, so that the
  65. # write-version is reloaded). This way, SQLite does not discover that
  66. # the database is read-only until after it is locked.
  67. #
  68. set ro_version 02
  69. ifcapable wal { set ro_version 03 }
  70. do_test rdonly-1.6 {
  71. hexio_write test.db 18 $ro_version ; # write-version
  72. hexio_write test.db 24 11223344 ; # change-counter
  73. catchsql {
  74. INSERT INTO t1 VALUES(2);
  75. }
  76. } {1 {attempt to write a readonly database}}
  77. finish_test