# # This little snipit of NeoWebScript will remove any duplicate or # otherwise corrupted records from a NeoTrack data file. # # To use this snipit, simply set the name of the NeoTrack data file # to be mended in the old_file variable below and then execute the # snipit either from within a web page or from your online # NeoWebScript interpreter. # # NOTE: this little snipit also includes a check for duplicate keys # in the NeoTrack file being fixed. This is related to an # earlier problem that has not been seen in a while... # but just to be safe .... # # If you have any problems, drop me a note at hav@hav.com # hav 12-13-96 # # # put your NeoTrack data file name below # NOTE: the default data file name is NeoTrack as shown here # set old_file NeoTrack #============ this is the cleanup code ============= set temp_file NewNeoTrack catch {filerm db $temp_file} set totnum 0 ; # total number of record keys in the old file set num_copied 0 ; # number of good records copied set last_key "" ; # dummy used for avoiding duplicate record keys # # now read each record for which a key exists in the old file # if the record can be read, then copy it to the new file # # NOTE: this snipit illustrates how the keys can be sorted # though, in this case, there is really no need for sorting # foreach key [lsort -decreasing -ascii [dbkeys $old_file]] { incr totnum if {$key != $last_key} { ; # also check for and skip duplicate records catch {unset darray} if {[dbfetch $old_file $key darray] > 0} { dbstore $temp_file $key darray incr num_copied } } set last_key $key } # # finally, if there were any good records copied over # then replace the old file with the new file # # NOTE: if ALL records are somehow bad, then you can # simply remove the old NeoTrack file using the # filerm command shown below # if {$num_copied > 0} { filerm db $old_file ; # remove the old file just to be safe filemv db $temp_file $old_file ; # rename the new file to the old file } html "Done!
Retained $num_copied of $totnum records

\n"