Ray Mosley wrote:
AS a DB rookie, I have replaced the .txt files in an Tcl/Tk application with
a SQLite database, so it still reads very much like file I/O. While in a
loop I wrote several records to my files, so now I simply do an INSERT.
I keep reading that you optimize performance by using transactions, so how
do I do that?
Do I simply create a string that is my SQL statements, and how do I commit
the changes - never having done that in the past? My code kind of looks
like:
set tran_string "BEGIN TRANSACTION\n"
foreach ...
append tran_string "<my-insert-statement>\n"
append tran_string "END TRANSACTION\nCOMMIT TRANSACTION"
DB eval "$tran_string"
Thanks for the help.
I'm don't know tcl/tk, but as a general rule, if you're doing a group of
inserts, then doing
DB eval "begin"
foreach ....
DB eval "<my-insert-statement>"
DB eval "commit"
is the quickest way to do it, and the cleanest looking as far as code
goes. This does mean that
if there is an error, then none of the inserts will be committed, so all
the work will not be saved.
If there are lots of inserts you're doing, you may want to commit every
thousand inserts or so.
John