Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / bind2.test
blob1ebf35c2e006cd9f5d8468146faf6374360b2650
1 # 2022 Feb 10
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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix bind2
18 # Test that using bind_value() on a REAL sqlite3_value that was stored
19 # as an INTEGER works properly.
21 #   1.1: An IntReal value read from a table,
22 #   1.2: IntReal values obtained via the sqlite3_preupdate_old|new() 
23 #        interfaces.
24
25 do_execsql_test 1.0 { 
26   CREATE TABLE t1(a REAL);
27   INSERT INTO t1 VALUES(42.0);
28   SELECT * FROM t1;
29 } {42.0}
31 do_test 1.1 {
32   set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
33   sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1"
34   sqlite3_step $stmt
35   sqlite3_column_text $stmt 0
36 } {42.0}
37 sqlite3_finalize $stmt
39 ifcapable !preupdate {
40   finish_test
41   return
44 proc preup {args} {
45   set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
46   sqlite3_bind_value_from_preupdate $stmt 1 old 0
47   sqlite3_step $stmt
48   lappend ::reslist [sqlite3_column_text $stmt 0]
49   sqlite3_reset $stmt
50   sqlite3_bind_value_from_preupdate $stmt 1 new 0
51   sqlite3_step $stmt
52   lappend ::reslist [sqlite3_column_text $stmt 0]
53   sqlite3_finalize $stmt
55 db preupdate hook preup
57 do_test 1.2 {
58   set ::reslist [list]
59   execsql { UPDATE t1 SET a=43; }
60   set ::reslist
61 } {42.0 43.0}
63 finish_test