PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/sqlite/test/tkt-b72787b1.test

#
Unknown | 77 lines | 71 code | 6 blank | 0 comment | 0 complexity | 139a99c84c385f210cef9a126d85f715 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # 2011 February 21
  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 verify that ticket [b72787b1a7] has been
  14. # fixed. From the ticket:
  15. #
  16. # The sqlite3ExpirePreparedStatements routine marks all statements
  17. # as expired. This includes statements that are not expired.
  18. #
  19. # Steps to reproduce:
  20. #
  21. # * Prepare a statement (A)
  22. # * Alter the schema to invalidate cookie in A
  23. # * Prepare a statement (B)
  24. # * Run B and have A run as part of B
  25. # * A will find a bad cookie and cause *all* statements
  26. # to be expired including the currently running B by calling
  27. # sqlite3ExpirePreparedStatements
  28. # * When control returns to B it will then abort
  29. #
  30. # The bug is that sqlite3ExpirePreparedStatements expires all statements.
  31. # Note that B was prepared after the schema change and hence is perfectly
  32. # valid and then is marked as expired while running.
  33. #
  34. set testdir [file dirname $argv0]
  35. source $testdir/tester.tcl
  36. unset -nocomplain ::STMT
  37. proc runsql {} {
  38. db eval {CREATE TABLE IF NOT EXISTS t4(q)}
  39. sqlite3_step $::STMT
  40. set rc [sqlite3_column_int $::STMT 0]
  41. sqlite3_reset $::STMT
  42. return $rc
  43. }
  44. do_test tkt-b72787b1.1 {
  45. db eval {
  46. CREATE TABLE t1(x);
  47. INSERT INTO t1 VALUES(1);
  48. INSERT INTO t1 VALUES(2);
  49. CREATE TABLE t2(y);
  50. INSERT INTO t2 SELECT x+2 FROM t1;
  51. INSERT INTO t2 SELECT x+4 FROM t1;
  52. }
  53. db func runsql ::runsql
  54. set DB [sqlite3_connection_pointer db]
  55. set sql {SELECT max(x) FROM t1}
  56. set ::STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
  57. # The runsql() call on the second row of the first query will
  58. # cause all $::STMT to hit an expired cookie. Prior to the fix
  59. # for [b72787b1a7, the bad cookie would expire all statements, including
  60. # the following compound SELECT, which would cause a fault when the
  61. # second SELECT was reached. After the fix, the current statement
  62. # continues to completion.
  63. db eval {
  64. SELECT CASE WHEN y=3 THEN y+100 WHEN y==4 THEN runsql()+200
  65. ELSE 300+y END FROM t2
  66. UNION ALL
  67. SELECT * FROM t1;
  68. }
  69. } {103 202 305 306 1 2}
  70. sqlite3_finalize $::STMT
  71. finish_test