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

method prep {stmt} {
	variable stmts	;# here are some statements we prepared earlier
	variable max_prepcache
	if {[info exists stmts($stmt)]} {
	    set s $stmts($stmt)
	    if {$max_prepcache > 0} {
		# move matched element to end of cache (for LRU)
		unset stmts($stmt)
		set stmts($stmt) $s
	    }
	} else {
	    set s [my db prepare $stmt]
	    set stmts($stmt) $s
	    if {$max_prepcache > 0 && [array size stmts] > $max_prepcache} {
		Debug.store {removing LRU cached statement}
		array set stmts [lrange [array get stmts] 2 end]
	    }
	}
	return $s
    }