summaryrefslogtreecommitdiffstats
path: root/test/bind2.test
blob: 1ebf35c2e006cd9f5d8468146faf6374360b2650 (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
# 2022 Feb 10
#
# 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.
#
#***********************************************************************
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix bind2


# Test that using bind_value() on a REAL sqlite3_value that was stored
# as an INTEGER works properly.
#
#   1.1: An IntReal value read from a table,
#   1.2: IntReal values obtained via the sqlite3_preupdate_old|new() 
#        interfaces.
# 
do_execsql_test 1.0 { 
  CREATE TABLE t1(a REAL);
  INSERT INTO t1 VALUES(42.0);
  SELECT * FROM t1;
} {42.0}

do_test 1.1 {
  set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
  sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1"
  sqlite3_step $stmt
  sqlite3_column_text $stmt 0
} {42.0}
sqlite3_finalize $stmt

ifcapable !preupdate {
  finish_test
  return
}

proc preup {args} {
  set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
  sqlite3_bind_value_from_preupdate $stmt 1 old 0
  sqlite3_step $stmt
  lappend ::reslist [sqlite3_column_text $stmt 0]
  sqlite3_reset $stmt
  sqlite3_bind_value_from_preupdate $stmt 1 new 0
  sqlite3_step $stmt
  lappend ::reslist [sqlite3_column_text $stmt 0]
  sqlite3_finalize $stmt
}
db preupdate hook preup

do_test 1.2 {
  set ::reslist [list]
  execsql { UPDATE t1 SET a=43; }
  set ::reslist
} {42.0 43.0}

finish_test