| 1 |
# 2024-01-19 |
| 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 tests for SQL literals |
| 13 |
|
| 14 |
|
| 15 |
set testdir [file dirname $argv0] |
| 16 |
source $testdir/tester.tcl |
| 17 |
set ::testprefix literal |
| 18 |
|
| 19 |
proc test_literal {tn lit type val} { |
| 20 |
do_execsql_test $tn.1 "SELECT typeof( $lit ), $lit" [list $type $val] |
| 21 |
|
| 22 |
ifcapable altertable { |
| 23 |
do_execsql_test $tn.2 " |
| 24 |
DROP TABLE IF EXISTS x1; |
| 25 |
CREATE TABLE x1(a); |
| 26 |
INSERT INTO x1 VALUES(123); |
| 27 |
ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ; |
| 28 |
SELECT typeof(b), b FROM x1; |
| 29 |
" [list $type $val] |
| 30 |
} |
| 31 |
|
| 32 |
do_execsql_test $tn.3 " |
| 33 |
DROP TABLE IF EXISTS x1; |
| 34 |
CREATE TABLE x1(a DEFAULT $lit); |
| 35 |
INSERT INTO x1 DEFAULT VALUES; |
| 36 |
SELECT typeof(a), a FROM x1; |
| 37 |
" [list $type $val] |
| 38 |
} |
| 39 |
|
| 40 |
proc test_literal_error {tn lit unrec} { |
| 41 |
do_catchsql_test $tn "SELECT $lit" "1 {unrecognized token: \"$unrec\"}" |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
test_literal 1.0 45 integer 45 |
| 46 |
test_literal 1.1 0xFF integer 255 |
| 47 |
test_literal 1.2 0xFFFFFFFF integer [expr 0xFFFFFFFF] |
| 48 |
test_literal 1.3 0x123FFFFFFFF integer [expr 0x123FFFFFFFF] |
| 49 |
test_literal 1.4 -0x123FFFFFFFF integer [expr -1 * 0x123FFFFFFFF] |
| 50 |
test_literal 1.5 0xFFFFFFFFFFFFFFFF integer -1 |
| 51 |
test_literal 1.7 0x7FFFFFFFFFFFFFFF integer [expr 0x7FFFFFFFFFFFFFFF] |
| 52 |
test_literal 1.8 -0x7FFFFFFFFFFFFFFF integer [expr -0x7FFFFFFFFFFFFFFF] |
| 53 |
test_literal 1.9 +0x7FFFFFFFFFFFFFFF integer [expr +0x7FFFFFFFFFFFFFFF] |
| 54 |
test_literal 1.10 -45 integer -45 |
| 55 |
test_literal 1.11 '0xFF' text 0xFF |
| 56 |
test_literal 1.12 '-0xFF' text -0xFF |
| 57 |
test_literal 1.13 -'0xFF' integer 0 |
| 58 |
test_literal 1.14 -9223372036854775808 integer -9223372036854775808 |
| 59 |
|
| 60 |
test_literal 2.1 1e12 real 1000000000000.0 |
| 61 |
test_literal 2.2 1.0 real 1.0 |
| 62 |
test_literal 2.3 1e1000 real Inf |
| 63 |
test_literal 2.4 -1e1000 real -Inf |
| 64 |
|
| 65 |
test_literal 3.1 1_000 integer 1000 |
| 66 |
test_literal 3.2 1.1_1 real 1.11 |
| 67 |
test_literal 3.3 1_0.1_1 real 10.11 |
| 68 |
test_literal 3.4 1e1_000 real Inf |
| 69 |
test_literal 3.5 12_3_456.7_8_9 real 123456.789 |
| 70 |
test_literal 3.6 9_223_372_036_854_775_807 integer 9223372036854775807 |
| 71 |
test_literal 3.7 9_223_372_036_854_775_808 real 9.22337203685478e+18 |
| 72 |
test_literal 3.8 -9_223_372_036_854_775_808 integer -9223372036854775808 |
| 73 |
|
| 74 |
foreach {tn lit unrec} { |
| 75 |
0 123a456 123a456 |
| 76 |
1 1_ 1_ |
| 77 |
2 1_.4 1_.4 |
| 78 |
3 1e_4 1e_4 |
| 79 |
4 1_e4 1_e4 |
| 80 |
5 1.4_e4 1.4_e4 |
| 81 |
6 1.4e+_4 1.4e |
| 82 |
7 1.4e-_4 1.4e |
| 83 |
8 1.4e4_ 1.4e4_ |
| 84 |
9 1.4_e4 1.4_e4 |
| 85 |
10 1.4e_4 1.4e_4 |
| 86 |
11 12__34 12__34 |
| 87 |
12 1234_ 1234_ |
| 88 |
13 12._34 12._34 |
| 89 |
14 12_.34 12_.34 |
| 90 |
15 12.34_ 12.34_ |
| 91 |
16 1.0e1_______2 1.0e1_______2 |
| 92 |
} { |
| 93 |
test_literal_error 4.$tn $lit $unrec |
| 94 |
} |
| 95 |
|
| 96 |
# dbsqlfuzz e3186a9e7826e9cd7f4085aa4452f8696485f9e1 |
| 97 |
# See tag-20240224-a and -b |
| 98 |
# |
| 99 |
do_catchsql_test 5.1 { |
| 100 |
SELECT 1 ORDER BY 2_3; |
| 101 |
} {1 {1st ORDER BY term out of range - should be between 1 and 1}} |
| 102 |
|
| 103 |
finish_test |