xref: /sqlite-3.40.0/test/types3.test (revision 4dcbdbff)
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# $Id: types3.test,v 1.1 2005/06/25 19:31:48 drh Exp $
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# A variable with only a string representation comes in as TEXT
22do_test types3-1.1 {
23  set V {}
24  append V {}
25  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
26} {string text}
27
28# A variable with an integer representation comes in as INTEGER
29do_test types3-1.2 {
30  set V [expr {1+2}]
31  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
32} {int integer}
33do_test types3-1.3 {
34  set V [expr {1+123456789012345}]
35  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
36} {wideInt integer}
37
38# A double variable comes in as REAL
39do_test types3-1.4 {
40  set V [expr {1.0+1}]
41  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
42} {double real}
43
44# A byte-array variable comes in a BLOB if it has no string representation
45# or as TEXT if there is a string representation.
46#
47do_test types3-1.5 {
48  set V [binary format a3 abc]
49  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
50} {bytearray blob}
51do_test types3-1.6 {
52  set V "abc"
53  binary scan $V a3 x
54  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
55} {bytearray text}
56
57# Check to make sure return values are of the right types.
58#
59do_test types3-2.1 {
60  set V [db one {SELECT x'616263'}]
61  tcl_variable_type V
62} bytearray
63do_test types3-2.2 {
64  set V [db one {SELECT 123}]
65  tcl_variable_type V
66} int
67do_test types3-2.3 {
68  set V [db one {SELECT 1234567890123456}]
69  tcl_variable_type V
70} wideInt
71do_test types3-2.4 {
72  set V [db one {SELECT 1234567890123456.0}]
73  tcl_variable_type V
74} double
75do_test types3-2.5 {
76  set V [db one {SELECT '1234567890123456.0'}]
77  tcl_variable_type V
78} {}
79do_test types3-2.6 {
80  set V [db one {SELECT NULL}]
81  tcl_variable_type V
82} {}
83
84finish_test
85