Posted to tcl by colin at Fri Oct 18 05:38:18 GMT 2013view raw

  1. # prep - prepare a stmt or reused an already cached stmt
  2. method prep {stmt} {
  3. variable stmts ;# here are some statements we prepared earlier
  4. if {![info exists stmts]} {
  5. set stmts {}
  6. }
  7. variable max_prepcache
  8. if {[dict exists $stmts $stmt]} {
  9. set s [dict get $stmts $stmt]
  10. if {$max_prepcache > 0} {
  11. # move matched element to end of cache (for LRU)
  12. dict unset stmts $stmt
  13. dict set stmts $stmt $s
  14. }
  15. } else {
  16. set s [my db prepare $stmt]
  17. dict set stmts $stmt $s
  18. if {$max_prepcache > 0 && [dict size $stmts] > $max_prepcache} {
  19. Debug.session {removing LRU cached statement}
  20. set stmts [lrange $stmts 2 end]
  21. }
  22. }
  23. return $s
  24. }