eval.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # 2008 July 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 experiments with recursion using the "test_eval()" SQL function
  14. # in order to make sure that SQLite is reentrant.
  15. #
  16. # $Id: eval.test,v 1.2 2008/10/13 10:37:50 danielk1977 Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # Create a table to work with.
  20. #
  21. do_test eval-1.1 {
  22. execsql {
  23. CREATE TABLE t1(x INTEGER PRIMARY KEY);
  24. INSERT INTO t1 VALUES(1);
  25. INSERT INTO t1 VALUES(2);
  26. INSERT INTO t1 SELECT x+2 FROM t1;
  27. INSERT INTO t1 SELECT x+4 FROM t1;
  28. INSERT INTO t1 SELECT x+8 FROM t1;
  29. INSERT INTO t1 SELECT x+16 FROM t1;
  30. INSERT INTO t1 SELECT x+32 FROM t1;
  31. INSERT INTO t1 SELECT x+64 FROM t1;
  32. INSERT INTO t1 SELECT x+128 FROM t1;
  33. INSERT INTO t1 SELECT x+256 FROM t1;
  34. SELECT count(*), max(x) FROM t1;
  35. }
  36. } {512 512}
  37. do_test eval-1.2 {
  38. execsql {
  39. SELECT x, test_eval('SELECT max(x) FROM t1 WHERE x<' || x) FROM t1 LIMIT 5
  40. }
  41. } {1 {} 2 1 3 2 4 3 5 4}
  42. # Delete a row out from under a read cursor in the middle of
  43. # collecting the arguments for a single row in a result set.
  44. # Verify that subsequent rows come out as NULL.
  45. #
  46. do_test eval-2.1 {
  47. execsql {
  48. CREATE TABLE t2(x,y);
  49. INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
  50. SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2;
  51. }
  52. } {1 {} {} 2 {} {} 3 {} {} 4 {} {}}
  53. do_test eval-2.2 {
  54. execsql {
  55. SELECT * FROM t2
  56. }
  57. } {}
  58. # Modify a row while it is being read.
  59. #
  60. do_test eval-3.1 {
  61. execsql {
  62. INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
  63. SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2;
  64. }
  65. } {1 {} 102 2 {} 103 3 {} 104 4 {} 105}
  66. do_test eval-4.1 {
  67. execsql { SELECT test_eval('SELECT "abcdefghij"') }
  68. } {abcdefghij}
  69. finish_test