summaryrefslogtreecommitdiffstats
path: root/test/intreal.test
blob: d9ffe9909ef159720c7e69f25c04f9601f786a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 2019-05-03
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# Tests to exercise the MEM_IntReal representation of Mem objects.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::testprefix intreal

sqlite3_create_function db
do_execsql_test 100 {
  SELECT intreal(5);
} {5.0}
do_execsql_test 110 {
  SELECT intreal(5)=5, 6=intreal(6);
} {1 1}
do_execsql_test 120 {
  SELECT intreal(7)=7.0, 8.0=intreal(8);
} {1 1}
do_execsql_test 130 {
  SELECT typeof(intreal(9));
} {real}
do_execsql_test 140 {
  SELECT 'a'||intreal(11)||'z';
} {a11.0z}

do_execsql_test 150 {
  SELECT max(1.0,intreal(2),3.0), max(1,intreal(2),3);
} {3.0 3}
do_execsql_test 160 {
  SELECT max(1.0,intreal(4),3.0), max(1,intreal(4),3);
} {4.0 4.0}
do_execsql_test 170 {
  SELECT max(1.0,intreal(2),intreal(3),4.0),
         max(1,intreal(2),intreal(3),4);
} {4.0 4}
do_execsql_test 180 {
  SELECT max(1.0,intreal(5),intreal(3),4.0),
         max(1,intreal(5),intreal(3),4);
} {5.0 5.0}

#-------------------------------------------------------------------------
do_execsql_test 2.1 {
  CREATE TABLE t2(a REAL);
  INSERT INTO t2 VALUES( 836627109860825358 );
  SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
} {8.36}

do_execsql_test 2.2 {
  CREATE INDEX i2 ON t2(a);
  SELECT substr(a,1,4) FROM t2 WHERE a = CAST(836627109860825358 AS REAL);
} {8.36}

do_execsql_test 2.3 {
  CREATE TABLE t0 (c0);
  CREATE TABLE t1 (c1 REAL);
  INSERT INTO t1(c1) VALUES (8366271098608253588);
  INSERT INTO t0(c0) VALUES ('a');
}
set D [db one {SELECT c1 FROM t1}]

do_execsql_test 2.4 {
  SELECT * FROM t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
} $D

do_execsql_test 2.5 {
  SELECT * FROM t0, t1 WHERE (t1.c1 = CAST(8366271098608253588 AS REAL));
} [list a $D]

do_execsql_test 2.6 {
  SELECT * FROM t0, t1 
  WHERE (
        t1.c1 >= CAST(8366271098608253588 AS REAL) 
    AND t1.c1 <= CAST(8366271098608253588 AS REAL)
  );
} [list a $D]

# 2019-07-29 ticket ba2f4585cf495231
#
db close
sqlite3 db :memory:
do_execsql_test 3.0 {
  CREATE TABLE t0 (c0 REAL, c1);
  CREATE UNIQUE INDEX i0 ON t0(c1, 0 | c0);
  INSERT INTO t0(c0) VALUES (4750228396194493326), (0);
  UPDATE OR REPLACE t0 SET c0 = 'a', c1 = '';
  SELECT * FROM t0 ORDER BY t0.c1;
  PRAGMA integrity_check;
} {a {} ok}


reset_db
do_execsql_test 4.0 {
  CREATE TABLE t1(a REAL, b AS ('expr') ); 
}
do_execsql_test 4.1 {
  INSERT INTO t1 VALUES( REPLACE(0, '', 'expr') );
}
do_execsql_test 4.2 {
  INSERT INTO t1 SELECT REPLACE(4, '', 'expr');
}
do_execsql_test 4.3 {
  SELECT typeof(a), a FROM t1;
} {
  real 0.0
  real 4.0
}

finish_test