PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/sqlite/test/lock3.test

#
Unknown | 79 lines | 70 code | 9 blank | 0 comment | 0 complexity | dd61348c50ff2742103be066fc587125 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # 2001 September 15
  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. The
  12. # focus of this script is database locks and the operation of the
  13. # DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the
  14. # BEGIN command.
  15. #
  16. # $Id: lock3.test,v 1.4 2009/03/28 15:04:24 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # Establish two connections to the same database. Put some
  20. # sample data into the database.
  21. #
  22. do_test lock3-1.1 {
  23. file mkdir tempdir/t1/t2/t3
  24. sqlite3 db2 ./tempdir/t1//t2/./t3//./../..//./../../tempdir/..//test.db//
  25. execsql {
  26. CREATE TABLE t1(a);
  27. INSERT INTO t1 VALUES(1);
  28. }
  29. execsql {
  30. SELECT * FROM t1
  31. } db2
  32. } 1
  33. # Get a deferred lock on the database using one connection. The
  34. # other connection should still be able to write.
  35. #
  36. do_test lock3-2.1 {
  37. execsql {BEGIN DEFERRED TRANSACTION}
  38. execsql {INSERT INTO t1 VALUES(2)} db2
  39. execsql {END TRANSACTION}
  40. execsql {SELECT * FROM t1}
  41. } {1 2}
  42. # Get an immediate lock on the database using one connection. The
  43. # other connection should be able to read the database but not write
  44. # it.
  45. #
  46. do_test lock3-3.1 {
  47. execsql {BEGIN IMMEDIATE TRANSACTION}
  48. catchsql {SELECT * FROM t1} db2
  49. } {0 {1 2}}
  50. do_test lock3-3.2 {
  51. catchsql {INSERT INTO t1 VALUES(3)} db2
  52. } {1 {database is locked}}
  53. do_test lock3-3.3 {
  54. execsql {END TRANSACTION}
  55. } {}
  56. # Get an exclusive lock on the database using one connection. The
  57. # other connection should be unable to read or write the database.
  58. #
  59. do_test lock3-4.1 {
  60. execsql {BEGIN EXCLUSIVE TRANSACTION}
  61. catchsql {SELECT * FROM t1} db2
  62. } {1 {database is locked}}
  63. do_test lock3-4.2 {
  64. catchsql {INSERT INTO t1 VALUES(3)} db2
  65. } {1 {database is locked}}
  66. do_test lock3-4.3 {
  67. execsql {END TRANSACTION}
  68. } {}
  69. catch {db2 close}
  70. finish_test