Posted to tcl by colin at Tue Sep 10 00:27:56 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. variable max_prepcache
  5. if {[dict exists $stmts $stmt]} {
  6. set s [dict get $stmts $stmt]
  7. if {$max_prepcache > 0} {
  8. # move matched element to end of cache (for LRU)
  9. dict unset stmts $stmt
  10. dict set stmts $stmt $s
  11. }
  12. } else {
  13. set s [my db prepare $stmt]
  14. dict set stmts $stmt $s
  15. if {$max_prepcache > 0 && [dict size $stmts] > $max_prepcache} {
  16. Debug.session {removing LRU cached statement}
  17. set stmts [lrange $stmts 2 end]
  18. }
  19. }
  20. return $s
  21. }