From: Donal K. F. <don...@ma...> - 2014-03-28 11:04:41
|
On 27/03/2014 17:09, Lars Hellström wrote: > That code seems to be leaking prepared statements. Have you tried doing > $insert close > at the end of the loop? A driver imposing a limit of having at most 65536 > prepared statements active at any time does not seem unreasonable, but it > probably should throw an error when failing to create another. Reasonable. > Better yet: use bound variables for the variable data in your statement. > Then you only need to call [db prepare] once (possibly saving your program > the effort of having to recompile the SQL statement for each iteration of > the loop). Beyond reasonable; utterly mandatory. set sql "INSERT INTO $table (date, ip, port, called, calling, nas, statustype, sessionid, sessiontime, terminatecause, porttype) VALUES (:date, :ip, :port, :called, :calling, :nas, :statustype, :sessionid, :sessiontime, :terminatecause, :porttype)" set insert [db prepare $sql] try { lassign $line date ip port called calling nas statustype sessionid sessiontime terminatecause porttype $insert execute } finally { $insert close } Faster and safer; what's not to like? > Come to think of it, you also leak resultset objects. Use the allrows method > instead of the execute method. Closing the statement will close the resultsets hanging off it; TDBC gets that right. Donal. |