tkt3346.test 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # 2008 September 1
  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. #
  12. # This file implements regression tests for SQLite library. The
  13. # focus of this file is testing the fix for ticket #3346
  14. #
  15. # $Id: tkt3346.test,v 1.3 2008/12/09 13:12:57 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. do_test tkt3346-1.1 {
  19. db eval {
  20. CREATE TABLE t1(a,b);
  21. INSERT INTO t1 VALUES(2,'bob');
  22. INSERT INTO t1 VALUES(1,'alice');
  23. INSERT INTO t1 VALUES(3,'claire');
  24. SELECT *, ( SELECT y FROM (SELECT x.b='alice' AS y) )
  25. FROM ( SELECT * FROM t1 ) AS x;
  26. }
  27. } {2 bob 0 1 alice 1 3 claire 0}
  28. do_test tkt3346-1.2 {
  29. db eval {
  30. SELECT b FROM (SELECT * FROM t1) AS x
  31. WHERE (SELECT y FROM (SELECT x.b='alice' AS y))=0
  32. }
  33. } {bob claire}
  34. do_test tkt3346-1.3 {
  35. db eval {
  36. SELECT b FROM (SELECT * FROM t1 ORDER BY a) AS x
  37. WHERE (SELECT y FROM (SELECT a||b y FROM t1 WHERE t1.b=x.b))=(x.a||x.b)
  38. }
  39. } {alice bob claire}
  40. do_test tkt3346-1.4 {
  41. db eval {
  42. SELECT b FROM (SELECT * FROM t1 ORDER BY a) AS x
  43. WHERE (SELECT y FROM (SELECT a||b y FROM t1 WHERE t1.b=x.b))=('2'||x.b)
  44. }
  45. } {bob}
  46. # Ticket #3530
  47. #
  48. # As shown by ticket #3346 above (see also ticket #3298) it is important
  49. # that a subquery in the result-set be able to look up through multiple
  50. # FROM levels in order to view tables in the FROM clause at the top level.
  51. #
  52. # But ticket #3530 shows us that a subquery in the FROM clause should not
  53. # be able to look up to higher levels:
  54. #
  55. do_test tkt3346-2.1 {
  56. catchsql {
  57. CREATE TABLE t2(a);
  58. INSERT INTO t2 VALUES(1);
  59. SELECT * FROM (SELECT * FROM t1 WHERE 1=x.a) AS x;
  60. }
  61. } {1 {no such column: x.a}}
  62. finish_test