AryaWu/sqlite
0
1# 2014-07-232#3# The author disclaims copyright to this source code. In place of4# 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 hexadecimal literals13 14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17 18proc hexlit1 {tnum val ans} {19 do_execsql_test hexlit-$tnum "SELECT $val" $ans20}21 22hexlit1 100 0x0 023hexlit1 101 0x0000000000000000000000000000000000000000000001 124hexlit1 102 0x2 225hexlit1 103 0x4 426hexlit1 104 0x8 827hexlit1 105 0x00000000000000000000000000000000000000000000010 1628hexlit1 103 0x20 3229hexlit1 106 0x40 6430hexlit1 107 0x80 12831hexlit1 108 0x100 25632hexlit1 109 0x200 51233hexlit1 110 0X400 102434hexlit1 111 0x800 204835hexlit1 112 0x1000 409636hexlit1 113 0x2000 819237hexlit1 114 0x4000 1638438hexlit1 115 0x8000 3276839hexlit1 116 0x10000 6553640hexlit1 117 0x20000 13107241hexlit1 118 0x40000 26214442hexlit1 119 0x80000 52428843hexlit1 120 0x100000 104857644hexlit1 121 0x200000 209715245hexlit1 122 0x400000 419430446hexlit1 123 0x800000 838860847hexlit1 124 0x1000000 1677721648hexlit1 125 0x2000000 3355443249hexlit1 126 0x4000000 6710886450hexlit1 127 0x8000000 13421772851hexlit1 128 0x10000000 26843545652hexlit1 129 0x20000000 53687091253hexlit1 130 0x40000000 107374182454hexlit1 131 0x80000000 214748364855hexlit1 132 0x100000000 429496729656hexlit1 133 0x200000000 858993459257hexlit1 134 0x400000000 1717986918458hexlit1 135 0x800000000 3435973836859hexlit1 136 0x1000000000 6871947673660hexlit1 137 0x2000000000 13743895347261hexlit1 138 0x4000000000 27487790694462hexlit1 139 0x8000000000 54975581388863hexlit1 140 0x10000000000 109951162777664hexlit1 141 0x20000000000 219902325555265hexlit1 142 0x40000000000 439804651110466hexlit1 143 0x80000000000 879609302220867hexlit1 144 0x100000000000 1759218604441668hexlit1 145 0x200000000000 3518437208883269hexlit1 146 0x400000000000 7036874417766470hexlit1 147 0x800000000000 14073748835532871hexlit1 148 0x1000000000000 28147497671065672hexlit1 149 0x2000000000000 56294995342131273hexlit1 150 0x4000000000000 112589990684262474hexlit1 151 0x8000000000000 225179981368524875hexlit1 152 0x10000000000000 450359962737049676hexlit1 153 0x20000000000000 900719925474099277hexlit1 154 0x40000000000000 1801439850948198478hexlit1 155 0x80000000000000 3602879701896396879hexlit1 156 0x100000000000000 7205759403792793680hexlit1 157 0x200000000000000 14411518807585587281hexlit1 158 0x400000000000000 28823037615171174482hexlit1 159 0x800000000000000 57646075230342348883hexlit1 160 0X1000000000000000 115292150460684697684hexlit1 161 0x2000000000000000 230584300921369395285hexlit1 162 0X4000000000000000 461168601842738790486hexlit1 163 0x8000000000000000 -922337203685477580887hexlit1 164 0XFFFFFFFFFFFFFFFF -188 89for {set n 1} {$n < 0x10} {incr n} {90 hexlit1 200.$n.1 0X[format %03X $n] $n91 hexlit1 200.$n.2 0x[format %03X $n] $n92 hexlit1 200.$n.3 0X[format %03x $n] $n93 hexlit1 200.$n.4 0x[format %03x $n] $n94}95 96# String literals that look like hex do not get cast or coerced.97#98do_execsql_test hexlit-300 {99 CREATE TABLE t1(x INT, y REAL);100 INSERT INTO t1 VALUES('1234','4567'),('0x1234','0x4567');101 SELECT typeof(x), x, typeof(y), y, '#' FROM t1 ORDER BY rowid;102} {integer 1234 real 4567.0 # text 0x1234 text 0x4567 #}103do_execsql_test hexlit-301 {104 SELECT CAST('0x1234' AS INTEGER);105} {0}106 107# Oversized hex literals are rejected108#109do_catchsql_test hexlist-400 {110 SELECT 0x10000000000000000;111} {1 {hex literal too big: 0x10000000000000000}}112do_catchsql_test hexlist-401 {113 SELECT DISTINCT 0x10000000000000000;114} {1 {hex literal too big: 0x10000000000000000}}115do_catchsql_test hexlist-402 {116 SELECT DISTINCT -0x08000000000000000;117} {1 {hex literal too big: -0x08000000000000000}}118do_catchsql_test hexlist-410 {119 DROP TABLE IF EXISTS t1;120 CREATE TABLE t1(x);121 INSERT INTO t1 VALUES(1+0x10000000000000000);122} {1 {hex literal too big: 0x10000000000000000}}123 124 125finish_test126 