interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / types3.test

124 lines · 3509 bytes Raw Blame History
1# 2005 June 25
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# 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.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# A variable with only a string representation comes in as TEXT
20do_test types3-1.1 {
21 set V [format %s xxxxx]
22 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
23} {text}
24
25# A variable with an integer representation comes in as INTEGER
26do_test types3-1.2 {
27 set V [expr {int(1+2)}]
28 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
29} {int integer}
30set V [expr {1+12345678012345}]
31if {[tcl_variable_type V]=="wideInt"} {
32 do_test types3-1.3 {
33 set V [expr {1+123456789012345}]
34 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
35 } {wideInt integer}
36} else {
37 do_test types3-1.3 {
38 set V [expr {1+123456789012345}]
39 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
40 } {int integer}
41}
42
43# A double variable comes in as REAL
44do_test types3-1.4 {
45 set V [expr {1.0+1}]
46 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
47} {double real}
48
49# A byte-array variable comes in a BLOB if it has no string representation
50# or as TEXT if there is a string representation.
51#
52do_test types3-1.5 {
53 set V [binary format a3 abc]
54 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
55} {bytearray blob}
56do_test types3-1.6 {
57 set V "abc"
58 binary scan $V a3 x
59 concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
60} {bytearray text}
61
62# Check to make sure return values are of the right types.
63#
64ifcapable bloblit {
65 do_test types3-2.1 {
66 set V [db one {SELECT x'616263'}]
67 tcl_variable_type V
68 } bytearray
69}
70do_test types3-2.2 {
71 set V [db one {SELECT 123}]
72 tcl_variable_type V
73} int
74set Vx [expr {1+wide(123456789123456)}]
75do_test types3-2.3 {
76 set V [db one {SELECT 1234567890123456}]
77 tcl_variable_type V
78} [tcl_variable_type Vx]
79do_test types3-2.4.1 {
80 set V [db one {SELECT 1234567890123456.1}]
81 tcl_variable_type V
82} double
83do_test types3-2.4.2 {
84 set V [db one {SELECT 1234567890123.456}]
85 tcl_variable_type V
86} double
87do_test types3-2.5 {
88 set V [db one {SELECT '1234567890123456.0'}]
89 tcl_variable_type V
90} {}
91do_test types3-2.6 {
92 set V [db one {SELECT NULL}]
93 tcl_variable_type V
94} {}
95
96# See https://sqlite.org/forum/forumpost/3776b48e71
97#
98# On a text-affinity comparison of two values where one of
99# the values has both MEM_Str and a numeric type like MEM_Int,
100# make sure that only the MEM_Str representation is used.
101#
102sqlite3_create_function db
103do_execsql_test types3-3.1 {
104 DROP TABLE IF EXISTS t1;
105 CREATE TABLE t1(x TEXT PRIMARY KEY);
106 INSERT INTO t1 VALUES('1');
107 SELECT * FROM t1 WHERE NOT x=upper(1);
108} {}
109do_execsql_test types3-3.2 {
110 SELECT * FROM t1 WHERE NOT x=add_text_type(1);
111} {}
112do_execsql_test types3-3.3 {
113 SELECT * FROM t1 WHERE NOT x=add_int_type('1');
114} {}
115do_execsql_test types3-3.4 {
116 DELETE FROM t1;
117 INSERT INTO t1 VALUES(1.25);
118 SELECT * FROM t1 WHERE NOT x=add_real_type('1.25');
119} {}
120do_execsql_test types3-3.5 {
121 SELECT * FROM t1 WHERE NOT x=add_text_type(1.25);
122} {}
123
124finish_test