Posted to tcl by colin at Tue Sep 10 00:27:56 GMT 2013view raw
- # prep - prepare a stmt or reused an already cached stmt
- method prep {stmt} {
- variable stmts ;# here are some statements we prepared earlier
- 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
- }