Posted to tcl by colin at Fri Oct 18 05:38:18 GMT 2013view pretty
# prep - prepare a stmt or reused an already cached stmt method prep {stmt} { variable stmts ;# here are some statements we prepared earlier if {![info exists stmts]} { set stmts {} } variable max_prepcache if {[dict exists $stmts $stmt]} { set s [dict get $stmts $stmt] if {$max_prepcache > 0} { # move matched element to end of cache (for LRU) dict unset stmts $stmt dict set stmts $stmt $s } } else { set s [my db prepare $stmt] dict set stmts $stmt $s if {$max_prepcache > 0 && [dict size $stmts] > $max_prepcache} { Debug.session {removing LRU cached statement} set stmts [lrange $stmts 2 end] } } return $s }