GSAK (Geocaching Swiss Army Knife)
Contents - Index

MacroDelete (command)

MacroDelete <Action=DelCurrent|DelScope|Commit>

The MacroDelete command now somewhat supersedes the Delete command and also enables you to delete records from the logs, waypoints, corrected and attributes tables

As the physical deleting of records is the "slow" part, this command is broken into two phases:

1. The flagging of records to delete (actions DelCurrent and DelScope)
2. The actual delete of those flagged records (action Commit)

This enables you to quickly flag records to delete, then finally do the physical delete to remove them when you are ready.

This command works on your currently active table, and "Action" has 3 possible values:

DelCurrent - Flag the current record for delete
DelScope - Flag all the records in the current scope for delete
Commit - Complete all flagged deletes. Note: Commit here relates specifically to this command only. That is, the physical update of the database is not actaully done until the current transaction (if there is one) is commited. 

As the "Caches" table does not really have a "scope" the use of DelScope when "Caches" is the active table, allows you to delete all records in your current subset/filter

Example 1 - Delete all child waypoints for the current cache
 

table active=waypoints scope=parent
macrodelete action=delscope
macrodelete action=commit

 
Example 2 - Delete all child waypoints for a filter. In this example we use a Mfilter just for caches with "river" in the name
 

Mfilter where=Regex("river",name)
If $_FilterCount > 0
  While not($_eol)
    table active=waypoints scope=parent
    macrodelete action=delscope
    # don't do the commit here because there may be more to do
    table active=caches
    goto position=next
  endwhile
  # now the slow part - physically remove all the deleted child waypoints
  table active=waypoints scope=all
  macrodelete action=commit
  table active=caches # not really required here, but should be included if you have more code after the endif
EndIf

 
Example 3 - Delete all child waypoints in the current database:
 

table active=waypoints scope=all
macrodelete action=delscope
macrodelete action=commit

 
Example 4 - Delete all Parking waypoints
 

table active=waypoints scope=all
while not($_eol)
  if $d_cType = "Parking Area"
    MacroDelete action=DelCurrent
  endif
  Goto Position=Next
EndWhile
# now remove the flagged deletes
MacroDelete action=commit

 
Note1: When you use the actions DelScope or DelCurrent, you are only flagging the record for delete in memory. The actual delete is not performed until you issue a Commit for the corresponding table. If you end your macro without doing a Commit, your flagged deletes will be cleared from memory and lost - effectively changing nothing in your database.

For those familiar with database languages, consider this a type of "transaction" where the changes are all (commit used) or nothing (no commit)

You can use the commit action anytime before the macro ends to complete the transaction.

If you have uncommitted deletes for the caches table and another table(s), make sure you do the commit for the other tables first.

That is, when doing deletes to multiple tables, always issue the commit for the caches table last (the order between logs and waypoints does not matter)

Like the Delete command, the MacroDelete command also cascades deletes when you commit deletes to the caches table. That is, when a cache is removed from the database, all corresponding waypoints and logs are also removed. 

Note2: when deleting logs, you should always follow up with the ResyncLogs command to make sure all log totals are correctly recalculated.

Also see the Delete command

Alpha List         Category List

Copyright 2004-2014 CWE Computer Services  
Privacy Policy Contact