/ Check-in [d4a26bb6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test cases designed to exercise all syntax diagram paths in lang_expr.html
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d4a26bb629bc739a4bca16b5a876199aa9ecda43
User & Date: dan 2010-08-16 18:26:31
Context
2010-08-16
19:23
Add tests for different page sizes to wal.test. Including 64K pages. check-in: d95bcc05 user: dan tags: trunk
18:26
Add test cases designed to exercise all syntax diagram paths in lang_expr.html check-in: d4a26bb6 user: dan tags: trunk
16:31
Fix a typo in a comment in wal.c. No code changes. check-in: d854a3d4 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/e_expr.test.

609
610
611
612
613
614
615
616












































































































































































































617


  list [sqlite3_column_type $stmt 0] \
       [sqlite3_column_type $stmt 1] \
       [sqlite3_column_type $stmt 2] \
       [sqlite3_column_type $stmt 3] 
} {NULL NULL NULL NULL}
do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK













































































































































































































finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

  list [sqlite3_column_type $stmt 0] \
       [sqlite3_column_type $stmt 1] \
       [sqlite3_column_type $stmt 2] \
       [sqlite3_column_type $stmt 3] 
} {NULL NULL NULL NULL}
do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK

#-------------------------------------------------------------------------
# "Test" the syntax diagrams in lang_expr.html.
#
# EVIDENCE-OF: R-04177-20688 -- syntax diagram signed-number
#
do_execsql_test e_expr-12.1.1 { SELECT 0, +0, -0 } {0 0 0}
do_execsql_test e_expr-12.1.2 { SELECT 1, +1, -1 } {1 1 -1}
do_execsql_test e_expr-12.1.3 { SELECT 2, +2, -2 } {2 2 -2}
do_execsql_test e_expr-12.1.4 { 
  SELECT 1.4, +1.4, -1.4 
} {1.4 1.4 -1.4}
do_execsql_test e_expr-12.1.5 { 
  SELECT 1.5e+5, +1.5e+5, -1.5e+5 
} {150000.0 150000.0 -150000.0}
do_execsql_test e_expr-12.1.6 { 
  SELECT 0.0001, +0.0001, -0.0001 
} {0.0001 0.0001 -0.0001}

# EVIDENCE-OF: R-30740-26723 -- syntax diagram literal-value
#
set sqlite_current_time 1
do_execsql_test e_expr-12.2.1 {SELECT 123}               {123}
do_execsql_test e_expr-12.2.2 {SELECT 123.4e05}          {12340000.0}
do_execsql_test e_expr-12.2.3 {SELECT 'abcde'}           {abcde}
do_execsql_test e_expr-12.2.4 {SELECT X'414243'}         {ABC}
do_execsql_test e_expr-12.2.5 {SELECT NULL}              {{}}
do_execsql_test e_expr-12.2.6 {SELECT CURRENT_TIME}      {00:00:01}
do_execsql_test e_expr-12.2.7 {SELECT CURRENT_DATE}      {1970-01-01}
do_execsql_test e_expr-12.2.8 {SELECT CURRENT_TIMESTAMP} {{1970-01-01 00:00:01}}
set sqlite_current_time 0

# EVIDENCE-OF: R-57598-59332 -- syntax diagram expr
#
file delete -force test.db2
execsql {
  ATTACH 'test.db2' AS dbname;
  CREATE TABLE dbname.tblname(cname);
}

proc glob {args} {return 1}
db function glob glob
db function match glob
db function regexp glob

foreach {tn expr} {
  1 123
  2 123.4e05
  3 'abcde'
  4 X'414243'
  5 NULL
  6 CURRENT_TIME
  7 CURRENT_DATE
  8 CURRENT_TIMESTAMP

  9 ?
 10 ?123
 11 @hello
 12 :world
 13 $tcl
 14 $tcl(array)
  
  15 cname
  16 tblname.cname
  17 dbname.tblname.cname

  18 "+ EXPR"
  19 "- EXPR"
  20 "NOT EXPR"
  21 "~ EXPR"

  22 "EXPR1 || EXPR2"
  23 "EXPR1 * EXPR2"
  24 "EXPR1 / EXPR2"
  25 "EXPR1 % EXPR2"
  26 "EXPR1 + EXPR2"
  27 "EXPR1 - EXPR2"
  28 "EXPR1 << EXPR2"
  29 "EXPR1 >> EXPR2"
  30 "EXPR1 & EXPR2"
  31 "EXPR1 | EXPR2"
  32 "EXPR1 < EXPR2"
  33 "EXPR1 <= EXPR2"
  34 "EXPR1 > EXPR2"
  35 "EXPR1 >= EXPR2"
  36 "EXPR1 = EXPR2"
  37 "EXPR1 == EXPR2"
  38 "EXPR1 != EXPR2"
  39 "EXPR1 <> EXPR2"
  40 "EXPR1 IS EXPR2"
  41 "EXPR1 IS NOT EXPR2"
  42 "EXPR1 AND EXPR2"
  43 "EXPR1 OR EXPR2"
 
  44 "count(*)"
  45 "count(DISTINCT EXPR)"
  46 "substr(EXPR, 10, 20)"
  47 "changes()"
 
  48 "( EXPR )"
 
  49 "CAST ( EXPR AS integer )"
  50 "CAST ( EXPR AS 'abcd' )"
  51 "CAST ( EXPR AS 'ab$ $cd' )"
 
  52 "EXPR COLLATE nocase"
  53 "EXPR COLLATE binary"
 
  54 "EXPR1 LIKE EXPR2"
  55 "EXPR1 LIKE EXPR2 ESCAPE EXPR"
  56 "EXPR1 GLOB EXPR2"
  57 "EXPR1 GLOB EXPR2 ESCAPE EXPR"
  58 "EXPR1 REGEXP EXPR2"
  59 "EXPR1 REGEXP EXPR2 ESCAPE EXPR"
  60 "EXPR1 MATCH EXPR2"
  61 "EXPR1 MATCH EXPR2 ESCAPE EXPR"
  62 "EXPR1 NOT LIKE EXPR2"
  63 "EXPR1 NOT LIKE EXPR2 ESCAPE EXPR"
  64 "EXPR1 NOT GLOB EXPR2"
  65 "EXPR1 NOT GLOB EXPR2 ESCAPE EXPR"
  66 "EXPR1 NOT REGEXP EXPR2"
  67 "EXPR1 NOT REGEXP EXPR2 ESCAPE EXPR"
  68 "EXPR1 NOT MATCH EXPR2"
  69 "EXPR1 NOT MATCH EXPR2 ESCAPE EXPR"
 
  70 "EXPR ISNULL"
  71 "EXPR NOTNULL"
  72 "EXPR NOT NULL"
 
  73 "EXPR1 IS EXPR2"
  74 "EXPR1 IS NOT EXPR2"

  75 "EXPR NOT BETWEEN EXPR1 AND EXPR2"
  76 "EXPR BETWEEN EXPR1 AND EXPR2"

  77 "EXPR NOT IN (SELECT cname FROM tblname)"
  78 "EXPR NOT IN (1)"
  79 "EXPR NOT IN (1, 2, 3)"
  80 "EXPR NOT IN tblname"
  81 "EXPR NOT IN dbname.tblname"
  82 "EXPR IN (SELECT cname FROM tblname)"
  83 "EXPR IN (1)"
  84 "EXPR IN (1, 2, 3)"
  85 "EXPR IN tblname"
  86 "EXPR IN dbname.tblname"

  87 "EXISTS (SELECT cname FROM tblname)"
  88 "NOT EXISTS (SELECT cname FROM tblname)"

  89 "CASE EXPR WHEN EXPR1 THEN EXPR2 ELSE EXPR END"
  90 "CASE EXPR WHEN EXPR1 THEN EXPR2 END"
  91 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END"
  92 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END"
  93 "CASE WHEN EXPR1 THEN EXPR2 ELSE EXPR END"
  94 "CASE WHEN EXPR1 THEN EXPR2 END"
  95 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END"
  96 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END"
} {

  # If the expression string being parsed contains "EXPR2", then replace
  # string "EXPR1" and "EXPR2" with arbitrary SQL expressions. If it 
  # contains "EXPR", then replace EXPR with an arbitrary SQL expression.
  # 
  set elist [list $expr]
  if {[string match *EXPR2* $expr]} {
    set elist [list]
    foreach {e1 e2} { cname "34+22" } {
      lappend elist [string map [list EXPR1 $e1 EXPR2 $e2] $expr]
    }
  } 
  if {[string match *EXPR* $expr]} {
    set elist2 [list]
    foreach el $elist {
      foreach e { cname "34+22" } {
        lappend elist2 [string map [list EXPR $e] $el]
      }
    }
    set elist $elist2
  }

  set x 0
  foreach e $elist {
    incr x
    do_test e_expr-12.3.$tn.$x { 
      set rc [catch { execsql "SELECT $e FROM tblname" } msg]
    } {0}
  }
}

# EVIDENCE-OF: R-49462-56079 -- syntax diagram raise-function
#
foreach {tn raiseexpr} {
  1 "RAISE(IGNORE)"
  2 "RAISE(ROLLBACK, 'error message')"
  3 "RAISE(ABORT, 'error message')"
  4 "RAISE(FAIL, 'error message')"
} {
  do_execsql_test e_expr-12.4.$tn "
    CREATE TRIGGER dbname.tr$tn BEFORE DELETE ON tblname BEGIN
      SELECT $raiseexpr ;
    END;
  " {}
}


finish_test