1fce4da1bSdrh# 2014-07-23 2fce4da1bSdrh# 3fce4da1bSdrh# The author disclaims copyright to this source code. In place of 4fce4da1bSdrh# a legal notice, here is a blessing: 5fce4da1bSdrh# 6fce4da1bSdrh# May you do good and not evil. 7fce4da1bSdrh# May you find forgiveness for yourself and forgive others. 8fce4da1bSdrh# May you share freely, never taking more than you give. 9fce4da1bSdrh# 10fce4da1bSdrh#*********************************************************************** 11fce4da1bSdrh# 12fce4da1bSdrh# This file implements tests for hexadecimal literals 13fce4da1bSdrh 14fce4da1bSdrh 15fce4da1bSdrhset testdir [file dirname $argv0] 16fce4da1bSdrhsource $testdir/tester.tcl 17fce4da1bSdrh 18fce4da1bSdrhproc hexlit1 {tnum val ans} { 19fce4da1bSdrh do_execsql_test hexlit-$tnum "SELECT $val" $ans 20fce4da1bSdrh} 21fce4da1bSdrh 22fce4da1bSdrhhexlit1 100 0x0 0 23fce4da1bSdrhhexlit1 101 0x0000000000000000000000000000000000000000000001 1 24fce4da1bSdrhhexlit1 102 0x2 2 25fce4da1bSdrhhexlit1 103 0x4 4 26fce4da1bSdrhhexlit1 104 0x8 8 27fce4da1bSdrhhexlit1 105 0x00000000000000000000000000000000000000000000010 16 28fce4da1bSdrhhexlit1 103 0x20 32 29fce4da1bSdrhhexlit1 106 0x40 64 30fce4da1bSdrhhexlit1 107 0x80 128 31fce4da1bSdrhhexlit1 108 0x100 256 32fce4da1bSdrhhexlit1 109 0x200 512 33fce4da1bSdrhhexlit1 110 0X400 1024 34fce4da1bSdrhhexlit1 111 0x800 2048 35fce4da1bSdrhhexlit1 112 0x1000 4096 36fce4da1bSdrhhexlit1 113 0x2000 8192 37fce4da1bSdrhhexlit1 114 0x4000 16384 38fce4da1bSdrhhexlit1 115 0x8000 32768 39fce4da1bSdrhhexlit1 116 0x10000 65536 40fce4da1bSdrhhexlit1 117 0x20000 131072 41fce4da1bSdrhhexlit1 118 0x40000 262144 42fce4da1bSdrhhexlit1 119 0x80000 524288 43fce4da1bSdrhhexlit1 120 0x100000 1048576 44fce4da1bSdrhhexlit1 121 0x200000 2097152 45fce4da1bSdrhhexlit1 122 0x400000 4194304 46fce4da1bSdrhhexlit1 123 0x800000 8388608 47fce4da1bSdrhhexlit1 124 0x1000000 16777216 48fce4da1bSdrhhexlit1 125 0x2000000 33554432 49fce4da1bSdrhhexlit1 126 0x4000000 67108864 50fce4da1bSdrhhexlit1 127 0x8000000 134217728 51fce4da1bSdrhhexlit1 128 0x10000000 268435456 52fce4da1bSdrhhexlit1 129 0x20000000 536870912 53fce4da1bSdrhhexlit1 130 0x40000000 1073741824 54fce4da1bSdrhhexlit1 131 0x80000000 2147483648 55fce4da1bSdrhhexlit1 132 0x100000000 4294967296 56fce4da1bSdrhhexlit1 133 0x200000000 8589934592 57fce4da1bSdrhhexlit1 134 0x400000000 17179869184 58fce4da1bSdrhhexlit1 135 0x800000000 34359738368 59fce4da1bSdrhhexlit1 136 0x1000000000 68719476736 60fce4da1bSdrhhexlit1 137 0x2000000000 137438953472 61fce4da1bSdrhhexlit1 138 0x4000000000 274877906944 62fce4da1bSdrhhexlit1 139 0x8000000000 549755813888 63fce4da1bSdrhhexlit1 140 0x10000000000 1099511627776 64fce4da1bSdrhhexlit1 141 0x20000000000 2199023255552 65fce4da1bSdrhhexlit1 142 0x40000000000 4398046511104 66fce4da1bSdrhhexlit1 143 0x80000000000 8796093022208 67fce4da1bSdrhhexlit1 144 0x100000000000 17592186044416 68fce4da1bSdrhhexlit1 145 0x200000000000 35184372088832 69fce4da1bSdrhhexlit1 146 0x400000000000 70368744177664 70fce4da1bSdrhhexlit1 147 0x800000000000 140737488355328 71fce4da1bSdrhhexlit1 148 0x1000000000000 281474976710656 72fce4da1bSdrhhexlit1 149 0x2000000000000 562949953421312 73fce4da1bSdrhhexlit1 150 0x4000000000000 1125899906842624 74fce4da1bSdrhhexlit1 151 0x8000000000000 2251799813685248 75fce4da1bSdrhhexlit1 152 0x10000000000000 4503599627370496 76fce4da1bSdrhhexlit1 153 0x20000000000000 9007199254740992 77fce4da1bSdrhhexlit1 154 0x40000000000000 18014398509481984 78fce4da1bSdrhhexlit1 155 0x80000000000000 36028797018963968 79fce4da1bSdrhhexlit1 156 0x100000000000000 72057594037927936 80fce4da1bSdrhhexlit1 157 0x200000000000000 144115188075855872 81fce4da1bSdrhhexlit1 158 0x400000000000000 288230376151711744 82fce4da1bSdrhhexlit1 159 0x800000000000000 576460752303423488 83fce4da1bSdrhhexlit1 160 0X1000000000000000 1152921504606846976 84fce4da1bSdrhhexlit1 161 0x2000000000000000 2305843009213693952 85fce4da1bSdrhhexlit1 162 0X4000000000000000 4611686018427387904 86fce4da1bSdrhhexlit1 163 0x8000000000000000 -9223372036854775808 873b9fab1cSmistachkinhexlit1 164 0XFFFFFFFFFFFFFFFF -1 88fce4da1bSdrh 893b9fab1cSmistachkinfor {set n 1} {$n < 0x10} {incr n} { 903b9fab1cSmistachkin hexlit1 200.$n.1 0X[format %03X $n] $n 913b9fab1cSmistachkin hexlit1 200.$n.2 0x[format %03X $n] $n 923b9fab1cSmistachkin hexlit1 200.$n.3 0X[format %03x $n] $n 933b9fab1cSmistachkin hexlit1 200.$n.4 0x[format %03x $n] $n 943b9fab1cSmistachkin} 95fce4da1bSdrh 969296c18aSdrh# String literals that look like hex do not get cast or coerced. 979296c18aSdrh# 989296c18aSdrhdo_execsql_test hexlit-300 { 999296c18aSdrh CREATE TABLE t1(x INT, y REAL); 1009296c18aSdrh INSERT INTO t1 VALUES('1234','4567'),('0x1234','0x4567'); 1019296c18aSdrh SELECT typeof(x), x, typeof(y), y, '#' FROM t1 ORDER BY rowid; 1029296c18aSdrh} {integer 1234 real 4567.0 # text 0x1234 text 0x4567 #} 1039296c18aSdrhdo_execsql_test hexlit-301 { 1049296c18aSdrh SELECT CAST('0x1234' AS INTEGER); 1059296c18aSdrh} {0} 106fce4da1bSdrh 1079296c18aSdrh# Oversized hex literals are rejected 1089296c18aSdrh# 1099296c18aSdrhdo_catchsql_test hexlist-400 { 1109296c18aSdrh SELECT 0x10000000000000000; 1119296c18aSdrh} {1 {hex literal too big: 0x10000000000000000}} 1127060ef92Sdrhdo_catchsql_test hexlist-401 { 1137060ef92Sdrh SELECT DISTINCT 0x10000000000000000; 1147060ef92Sdrh} {1 {hex literal too big: 0x10000000000000000}} 115*77320ea4Sdrhdo_catchsql_test hexlist-402 { 116*77320ea4Sdrh SELECT DISTINCT -0x08000000000000000; 117*77320ea4Sdrh} {1 {hex literal too big: -0x08000000000000000}} 118126a6e26Sdrhdo_catchsql_test hexlist-410 { 119126a6e26Sdrh DROP TABLE IF EXISTS t1; 120126a6e26Sdrh CREATE TABLE t1(x); 121126a6e26Sdrh INSERT INTO t1 VALUES(1+0x10000000000000000); 122126a6e26Sdrh} {1 {hex literal too big: 0x10000000000000000}} 123fce4da1bSdrh 124fce4da1bSdrh 125fce4da1bSdrhfinish_test 126