1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add the new "bind_fallback" method to the "sqlite3" object in the TCL

interface.

FossilOrigin-Name: c7f70b6d96338dba201e005104e7f7148c1a8cd767ab05e35b44617c4c797bc5
This commit is contained in:
drh
2019-02-28 17:29:19 +00:00
parent 4ddf7f4211
commit c06ede105d
4 changed files with 164 additions and 38 deletions

View File

@ -42,7 +42,7 @@ do_test tcl-1.1.1 {
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
} {1 {bad option "bogus": must be authorizer, backup, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, deserialize, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, serialize, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}}
} {1 {bad option "bogus": must be authorizer, backup, bind_fallback, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, deserialize, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, serialize, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}}
do_test tcl-1.2.1 {
set v [catch {db cache bogus} msg]
lappend v $msg
@ -791,5 +791,60 @@ do_test 17.6.3 {
list [catch { db function xyz -n object ret } msg] $msg
} {1 {bad option "-n": must be -argcount, -deterministic or -returntype}}
finish_test
# 2019-02-28: The "bind_fallback" command.
#
do_test 18.100 {
unset -nocomplain bindings abc def ghi jkl mno e01 e02
set bindings(abc) [expr {1+2}]
set bindings(def) {hello}
set bindings(ghi) [expr {3.1415926*1.0}]
proc bind_callback {nm} {
global bindings
set n2 [string range $nm 1 end]
if {[info exists bindings($n2)]} {
return $bindings($n2)
}
if {[string match e* $n2]} {
error "no such variable: $nm"
}
return -code return {}
}
db bind_fallback bind_callback
db eval {SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi)}
} {3 integer hello text 3.1415926 real}
do_test 18.110 {
db eval {SELECT quote(@def), typeof(@def)}
} {X'68656C6C6F' blob}
do_execsql_test 18.120 {
SELECT typeof($mno);
} {null}
do_catchsql_test 18.130 {
SELECT $e01;
} {1 {no such variable: $e01}}
do_test 18.140 {
db bind_fallback
} {bind_callback}
do_test 18.200 {
db bind_fallback {}
db eval {SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi)}
} {{} null {} null {} null}
do_test 18.300 {
unset -nocomplain bindings
proc bind_callback {nm} {lappend ::bindings $nm}
db bind_fallback bind_callback
db eval {SELECT $abc, @def, $ghi(123), :mno}
set bindings
} {{$abc} @def {$ghi(123)} :mno}
do_test 18.900 {
set rc [catch {db bind_fallback a b} msg]
lappend rc $msg
} {1 {wrong # args: should be "db bind_fallback ?CALLBACK?"}}
do_test 18.910 {
db bind_fallback bind_fallback_does_not_exist
} {}
do_catchsql_test 19.911 {
SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi);
} {1 {invalid command name "bind_fallback_does_not_exist"}}
db bind_fallback {}
finish_test