Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / types3.test
blob0ff346ce281db3147f5e97cef93f5623f549170c
1 # 2005 June 25
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The focus
12 # of this file is testing the interaction of SQLite manifest types
13 # with Tcl dual-representations.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # A variable with only a string representation comes in as TEXT
20 do_test types3-1.1 {
21   set V {}
22   append V x
23   concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
24 } {string text}
26 # A variable with an integer representation comes in as INTEGER
27 do_test types3-1.2 {
28   set V [expr {int(1+2)}]
29   concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
30 } {int integer}
31 set V [expr {1+12345678012345}]
32 if {[tcl_variable_type V]=="wideInt"} {
33   do_test types3-1.3 {
34     set V [expr {1+123456789012345}]
35     concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
36   } {wideInt integer}
37 } else {
38   do_test types3-1.3 {
39     set V [expr {1+123456789012345}]
40     concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
41   } {int integer}
44 # A double variable comes in as REAL
45 do_test types3-1.4 {
46   set V [expr {1.0+1}]
47   concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
48 } {double real}
50 # A byte-array variable comes in a BLOB if it has no string representation
51 # or as TEXT if there is a string representation.
53 do_test types3-1.5 {
54   set V [binary format a3 abc]
55   concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
56 } {bytearray blob}
57 do_test types3-1.6 {
58   set V "abc"
59   binary scan $V a3 x
60   concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
61 } {bytearray text}
63 # Check to make sure return values are of the right types.
65 ifcapable bloblit {
66   do_test types3-2.1 {
67     set V [db one {SELECT x'616263'}]
68     tcl_variable_type V
69   } bytearray
71 do_test types3-2.2 {
72   set V [db one {SELECT 123}]
73   tcl_variable_type V
74 } int
75 set Vx [expr {1+wide(123456789123456)}]
76 do_test types3-2.3 {
77   set V [db one {SELECT 1234567890123456}]
78   tcl_variable_type V
79 } [tcl_variable_type Vx]
80 do_test types3-2.4.1 {
81   set V [db one {SELECT 1234567890123456.1}]
82   tcl_variable_type V
83 } double
84 do_test types3-2.4.2 {
85   set V [db one {SELECT 1234567890123.456}]
86   tcl_variable_type V
87 } double
88 do_test types3-2.5 {
89   set V [db one {SELECT '1234567890123456.0'}]
90   tcl_variable_type V
91 } {}
92 do_test types3-2.6 {
93   set V [db one {SELECT NULL}]
94   tcl_variable_type V
95 } {}
97 # See https://sqlite.org/forum/forumpost/3776b48e71
99 # On a text-affinity comparison of two values where one of
100 # the values has both MEM_Str and a numeric type like MEM_Int,
101 # make sure that only the MEM_Str representation is used.
103 sqlite3_create_function db
104 do_execsql_test types3-3.1 {
105   DROP TABLE IF EXISTS t1;
106   CREATE TABLE t1(x TEXT PRIMARY KEY);
107   INSERT INTO t1 VALUES('1');
108   SELECT * FROM t1 WHERE NOT x=upper(1);
109 } {}
110 do_execsql_test types3-3.2 {
111   SELECT * FROM t1 WHERE NOT x=add_text_type(1);
112 } {}
113 do_execsql_test types3-3.3 {
114   SELECT * FROM t1 WHERE NOT x=add_int_type('1');
115 } {}
116 do_execsql_test types3-3.4 {
117   DELETE FROM t1;
118   INSERT INTO t1 VALUES(1.25);
119   SELECT * FROM t1 WHERE NOT x=add_real_type('1.25');
120 } {}
121 do_execsql_test types3-3.5 {
122   SELECT * FROM t1 WHERE NOT x=add_text_type(1.25);
123 } {}
125 finish_test