📄 expr.test
字号:
test_expr expr-6.63 {t1=NULL, t2='a*?c'} {t1 GLOB t2} {{}}test_expr expr-6.64 {t1='ac', t2=NULL} {t1 GLOB t2} {{}}test_expr expr-6.65 {t1=NULL, t2='a*?c'} {t1 NOT GLOB t2} {{}}test_expr expr-6.66 {t1='ac', t2=NULL} {t1 NOT GLOB t2} {{}}# Check that the affinity of a CAST expression is calculated correctly.ifcapable cast { test_expr expr-6.67 {t1='01', t2=1} {t1 = t2} 0 test_expr expr-6.68 {t1='1', t2=1} {t1 = t2} 1 test_expr expr-6.69 {t1='01', t2=1} {CAST(t1 AS INTEGER) = t2} 1}test_expr expr-case.1 {i1=1, i2=2} \ {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} netest_expr expr-case.2 {i1=2, i2=2} \ {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} eqtest_expr expr-case.3 {i1=NULL, i2=2} \ {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} netest_expr expr-case.4 {i1=2, i2=NULL} \ {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} netest_expr expr-case.5 {i1=2} \ {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} twotest_expr expr-case.6 {i1=1} \ {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} onetest_expr expr-case.7 {i1=2} \ {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} errortest_expr expr-case.8 {i1=3} \ {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} errortest_expr expr-case.9 {i1=3} \ {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} errortest_expr expr-case.10 {i1=3} \ {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END} {{}}test_expr expr-case.11 {i1=null} \ {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 3 END} 3test_expr expr-case.12 {i1=1} \ {CASE i1 WHEN 1 THEN null WHEN 2 THEN 'two' ELSE 3 END} {{}}test_expr expr-case.13 {i1=7} \ { CASE WHEN i1 < 5 THEN 'low' WHEN i1 < 10 THEN 'medium' WHEN i1 < 15 THEN 'high' ELSE 'error' END} medium# The sqliteExprIfFalse and sqliteExprIfTrue routines are only# executed as part of a WHERE clause. Create a table suitable# for testing these functions.#execsql {DROP TABLE test1}execsql {CREATE TABLE test1(a int, b int);}for {set i 1} {$i<=20} {incr i} { execsql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])"}execsql "INSERT INTO test1 VALUES(NULL,0)"do_test expr-7.1 { execsql {SELECT * FROM test1 ORDER BY a}} {{} 0 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576}proc test_expr2 {name expr result} { do_test $name [format { execsql {SELECT a FROM test1 WHERE %s ORDER BY a} } $expr] $result}test_expr2 expr-7.2 {a<10 AND a>8} {9}test_expr2 expr-7.3 {a<=10 AND a>=8} {8 9 10}test_expr2 expr-7.4 {a>=8 AND a<=10} {8 9 10}test_expr2 expr-7.5 {a>=20 OR a<=1} {1 20}test_expr2 expr-7.6 {b!=4 AND a<=3} {1 3}test_expr2 expr-7.7 {b==8 OR b==16 OR b==32} {3 4 5}test_expr2 expr-7.8 {NOT b<>8 OR b==1024} {3 10}test_expr2 expr-7.9 {b LIKE '10%'} {10 20}test_expr2 expr-7.10 {b LIKE '_4'} {6}test_expr2 expr-7.11 {a GLOB '1?'} {10 11 12 13 14 15 16 17 18 19}test_expr2 expr-7.12 {b GLOB '1*4'} {10 14}test_expr2 expr-7.13 {b GLOB '*1[456]'} {4}test_expr2 expr-7.14 {a ISNULL} {{}}test_expr2 expr-7.15 {a NOTNULL AND a<3} {1 2}test_expr2 expr-7.16 {a AND a<3} {1 2}test_expr2 expr-7.17 {NOT a} {}test_expr2 expr-7.18 {a==11 OR (b>1000 AND b<2000)} {10 11}test_expr2 expr-7.19 {a<=1 OR a>=20} {1 20}test_expr2 expr-7.20 {a<1 OR a>20} {}test_expr2 expr-7.21 {a>19 OR a<1} {20}test_expr2 expr-7.22 {a!=1 OR a=100} \ {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}test_expr2 expr-7.23 {(a notnull AND a<4) OR a==8} {1 2 3 8}test_expr2 expr-7.24 {a LIKE '2_' OR a==8} {8 20}test_expr2 expr-7.25 {a GLOB '2?' OR a==8} {8 20}test_expr2 expr-7.26 {a isnull OR a=8} {{} 8}test_expr2 expr-7.27 {a notnull OR a=8} \ {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}test_expr2 expr-7.28 {a<0 OR b=0} {{}}test_expr2 expr-7.29 {b=0 OR a<0} {{}}test_expr2 expr-7.30 {a<0 AND b=0} {}test_expr2 expr-7.31 {b=0 AND a<0} {}test_expr2 expr-7.32 {a IS NULL AND (a<0 OR b=0)} {{}}test_expr2 expr-7.33 {a IS NULL AND (b=0 OR a<0)} {{}}test_expr2 expr-7.34 {a IS NULL AND (a<0 AND b=0)} {}test_expr2 expr-7.35 {a IS NULL AND (b=0 AND a<0)} {}test_expr2 expr-7.32 {(a<0 OR b=0) AND a IS NULL} {{}}test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}}test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {}test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {}test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1}test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1}test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1}test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1}test_expr2 expr-7.40 {((a<2 OR a IS NULL) AND b<3) OR b>1e10} {{} 1}test_expr2 expr-7.41 {a BETWEEN -1 AND 1} {1}test_expr2 expr-7.42 {a NOT BETWEEN 2 AND 100} {1}test_expr2 expr-7.43 {(b+1234)||'this is a string that is at least 32 characters long' BETWEEN 1 AND 2} {}test_expr2 expr-7.44 {123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a BETWEEN '123a' AND '123b'} {}test_expr2 expr-7.45 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123b')<0} {}test_expr2 expr-7.46 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123z')>0} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}test_expr2 expr-7.50 {((a between 1 and 2 OR 0) AND 1) OR 0} {1 2}test_expr2 expr-7.51 {((a not between 3 and 100 OR 0) AND 1) OR 0} {1 2}ifcapable subquery { test_expr2 expr-7.52 {((a in (1,2) OR 0) AND 1) OR 0} {1 2} test_expr2 expr-7.53 \ {((a not in (3,4,5,6,7,8,9,10) OR 0) AND a<11) OR 0} {1 2}}test_expr2 expr-7.54 {((a>0 OR 0) AND a<3) OR 0} {1 2}ifcapable subquery { test_expr2 expr-7.55 {((a in (1,2) OR 0) IS NULL AND 1) OR 0} {{}} test_expr2 expr-7.56 \ {((a not in (3,4,5,6,7,8,9,10) IS NULL OR 0) AND 1) OR 0} {{}}}test_expr2 expr-7.57 {((a>0 IS NULL OR 0) AND 1) OR 0} {{}}test_expr2 expr-7.58 {(a||'')<='1'} {1}test_expr2 expr-7.59 {LIKE('10%',b)} {10 20}test_expr2 expr-7.60 {LIKE('_4',b)} {6}test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19}test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14}test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4}# Test the CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP expressions.#set sqlite_current_time 1157124849do_test expr-8.1 { execsql {SELECT CURRENT_TIME}} {15:34:09}do_test expr-8.2 { execsql {SELECT CURRENT_DATE}} {2006-09-01}do_test expr-8.3 { execsql {SELECT CURRENT_TIMESTAMP}} {{2006-09-01 15:34:09}}ifcapable datetime { do_test expr-8.4 { execsql {SELECT CURRENT_TIME==time('now');} } 1 do_test expr-8.5 { execsql {SELECT CURRENT_DATE==date('now');} } 1 do_test expr-8.6 { execsql {SELECT CURRENT_TIMESTAMP==datetime('now');} } 1}set sqlite_current_time 0do_test expr-9.1 { execsql {SELECT round(-('-'||'123'))}} 123.0# Test an error message that can be generated by the LIKE expressiondo_test expr-10.1 { catchsql {SELECT 'abc' LIKE 'abc' ESCAPE ''}} {1 {ESCAPE expression must be a single character}}do_test expr-10.2 { catchsql {SELECT 'abc' LIKE 'abc' ESCAPE 'ab'}} {1 {ESCAPE expression must be a single character}}# If we specify an integer constant that is bigger than the largest# possible integer, code the integer as a real number.#do_test expr-11.1 { execsql {SELECT typeof(9223372036854775807)}} {integer}do_test expr-11.2 { execsql {SELECT typeof(00000009223372036854775807)}} {integer}do_test expr-11.3 { execsql {SELECT typeof(+9223372036854775807)}} {integer}do_test expr-11.4 { execsql {SELECT typeof(+000000009223372036854775807)}} {integer}do_test expr-11.5 { execsql {SELECT typeof(9223372036854775808)}} {real}do_test expr-11.6 { execsql {SELECT typeof(00000009223372036854775808)}} {real}do_test expr-11.7 { execsql {SELECT typeof(+9223372036854775808)}} {real}do_test expr-11.8 { execsql {SELECT typeof(+0000009223372036854775808)}} {real}do_test expr-11.11 { execsql {SELECT typeof(-9223372036854775808)}} {integer}do_test expr-11.12 { execsql {SELECT typeof(-00000009223372036854775808)}} {integer}do_test expr-11.13 { execsql {SELECT typeof(-9223372036854775809)}} {real}do_test expr-11.14 { execsql {SELECT typeof(-00000009223372036854775809)}} {real}# These two statements used to leak memory (because of missing %destructor# directives in parse.y).do_test expr-12.1 { catchsql { SELECT (CASE a>4 THEN 1 ELSE 0 END) FROM test1; }} {1 {near "THEN": syntax error}}do_test expr-12.2 { catchsql { SELECT (CASE WHEN a>4 THEN 1 ELSE 0) FROM test1; }} {1 {near ")": syntax error}}finish_test
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -