GSAK (Geocaching Swiss Army Knife)
Contents - Index

Transaction (command)

Transaction <Action=Begin|End|Rollback>

Use to speed up multiple database variable updates on all tables. 

Action - Begin = start a transaction. End = finish the transaction and commit the changes to disk.Rollback = rollback all changes made to the start of the transaction. 

Warning: Native Sqlite Begin/commit/Rollback should really only be used when you are *not* using the GSAK default database (that is, when you open a database that is not the current database). If possible it is always better to use the Transaction command. Surprisingly, native Sqlite does not provide any way for you to know you are currently in a transaction. This could cause conflicts and crashes if your macro is called by another macro and you are both using transactions. Use of the "Transaction" command allows GSAK to keep an internal indicator that enables you to test if you are in a transaction ( you can use the Intransaction() function)

Database variable updates have been converted over in the macro language to transparently work via the SQL "update" statement. However this means that any time you update a database variable you are doing a write to the hard disk.

Take the following sample code that just keeps replacing the value of the log text 100 times (run this on a test database only)
 

timer status=on
table active=logs scope=parent
$x = 0
While $x < 100
$x = $x + 1
$d_ltext = "xxxx"
endwhile
timer status=off

 


So on my system this takes nearly a whopping 6 seconds!!!

What we need to do is wrap this code inside a transaction

So now our code should look like:
 

timer status=on
table active=logs scope=parent
transaction action=begin
$x = 0
While $x < 100
$x = $x + 1
$d_ltext = "xxxx"
endwhile
transaction action=end
timer status=off

 


A huge difference!!!  

Note: When updating GSAK database variables, the transaction command should always be used in preference to the native Sqlite transactions (more information)

Alpha List         Category List







Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact