xref: /sqlite-3.40.0/test/bind2.test (revision 252fe67b)
1# 2022 Feb 10
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#
12
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15set testprefix bind2
16
17
18# Test that using bind_value() on a REAL sqlite3_value that was stored
19# as an INTEGER works properly.
20#
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#
25do_execsql_test 1.0 {
26  CREATE TABLE t1(a REAL);
27  INSERT INTO t1 VALUES(42.0);
28  SELECT * FROM t1;
29} {42.0}
30
31do_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}
37sqlite3_finalize $stmt
38
39proc preup {args} {
40  set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
41  sqlite3_bind_value_from_preupdate $stmt 1 old 0
42  sqlite3_step $stmt
43  lappend ::reslist [sqlite3_column_text $stmt 0]
44  sqlite3_reset $stmt
45  sqlite3_bind_value_from_preupdate $stmt 1 new 0
46  sqlite3_step $stmt
47  lappend ::reslist [sqlite3_column_text $stmt 0]
48  sqlite3_finalize $stmt
49}
50db preupdate hook preup
51
52do_test 1.2 {
53  set ::reslist [list]
54  execsql { UPDATE t1 SET a=43; }
55  set ::reslist
56} {42.0 43.0}
57
58finish_test
59