Posted to tcl by colin at Tue Sep 10 00:20:41 GMT 2013view raw

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