dan | 252fe67 | 2022-02-09 18:42:15 +0000 | [diff] [blame] | 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 | |
| 13 | set testdir [file dirname $argv0] |
| 14 | source $testdir/tester.tcl |
| 15 | set 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 | # |
| 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} |
| 30 | |
| 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 |
| 38 | |
drh | fa3ee3b | 2022-02-11 12:06:37 +0000 | [diff] [blame] | 39 | ifcapable !preupdate { |
| 40 | finish_test |
| 41 | return |
| 42 | } |
| 43 | |
dan | 252fe67 | 2022-02-09 18:42:15 +0000 | [diff] [blame] | 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 |
| 54 | } |
| 55 | db preupdate hook preup |
| 56 | |
| 57 | do_test 1.2 { |
| 58 | set ::reslist [list] |
| 59 | execsql { UPDATE t1 SET a=43; } |
| 60 | set ::reslist |
| 61 | } {42.0 43.0} |
| 62 | |
| 63 | finish_test |