GSAK (Geocaching Swiss Army Knife)
Contents - Index

DataSave (command)

DATASAVE <Data=DB field(s)>

The DATASAVE and DATARESTORE commands go hand in hand. Currently they only apply to the "Caches" table. Basically, they allow you to save and restore the contents of any database variable (within the "Caches" table). Any valid database variable can be entered here, and you can have multiples by separating each with a ; (semi colon). There can be several applications for this.

1. The ability to save user and macro flags, change them, then restore to their original state. This would be useful when writing a macro for other users and you want to use the user and/or macro flag, but then clean up by restoring the flags to the original state the user had them

DATASAVE data=$d_UserFlag;$d_MacroFlag
your commands here
DATARESTORE data=$d_UserFlag;$d_MacroFlag

2. The ability to restore the contents of just a specific field after some operation that has updated the whole database

However, I must point out a few properties of these commands and they must be fully understood to get maximum use out of them.

1. Both commands respect your current filter. This means when doing a save only the waypoints in your current filter will have the corresponding columns saved. When doing a restore, this means that only the waypoints in the current filter can be changed - even though your corresponding save may have included the whole database. The implications of this are very significant and should be understood fully. If you plan to save and restore data for the whole database, make sure you issue a CANCELFILTER before each corresponding command. 

2. Visibility. The saved data is persistent, even after a shutdown of GSAK. 

3. You must have saved a variable before you can restore it. However, when saving multiple database variables you don't have to issue a restore command that has ALL the variables you saved. You can do them one at a time if you like and in any order you like.

4. Only waypoints that have a matching code will have the data restored. For example if you did a save of the whole database, then deleted some waypoints, then did a restore, only the waypoints left in the database would have information restored. This also means you must watch out for the scenario where you change the actual waypoint code after doing a save. For example, let us say you only have one waypoint in the database with the code of AAAAAA. You do a SAVEDATA command with many database variables. Now you change the code to BBBBBB then do a DATARESTORE. In this situation there will not be any data restored because waypoint code AAAAAA no longer exists.

5. Save/Restore commands are not global and work at the database level. That is, each database has a separate copy of the saved variables.   

Note: Using Sqlite you can effectively do the same thing, but have greater control so as to remove some of the limitations above (ignoring the current filter for example)

For example, saving and restoring the userflag for the whole database regardless of the current filter:

#Save UserFlags for the whole database
$status = sqlite("sql","create table UserFlagSave as select code,userflag from caches")
$status = sqlite("sql","create unique index UserFlagCode on UserFlagSave (code)") # not required, but recommended as this will speed up the update (especially noticeable if the database is large)
# do some action that updates user flags
#Now restore userflags for the whole database
$status = sqlite("sql","update caches set userflag = (select userflag from UserFlagSave where UserflagSave.code = Caches.code)")
$status = sqlite("sql","drop table UserFlagSave")

Alpha List         Category List

Copyright 2004-2016 CWE Computer Services  
Privacy Policy Contact