Gossamer Forum
Home : Products : DBMan : Discussions :

Re: defragmenting DB

Quote Reply
Re: defragmenting DB In reply to
Elb--
I don't think there's any reason to renumber the database, but this is something that has come up so often, I've given up trying to talk people out of it.

wallaby --

You'll need to change the part of the script that writes to the .db file. The changes are in red below:

Code:

$i = 1;
open (DB, ">$db_script_path/$db_file_name") or ("Can't open: $db_script_path/$db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = split (/\Q$db_delim\E/o, $_);
print "Comparing: '$today' vs '$values[$removeby_field]' ... \n";
if ($today > (&date_to_unix($values[$dateadded_field]) + (86400 * $values[$removeby_field]))) {
print "Record(s) Deleted\n";
next;
}
$values[$db_key_pos] = $i;
++$i;
$line = join "$db_delim",@values;
print DB $line, "\n";

}
close DB;
open (ID, ">$db_id_file_name") or ("unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or ("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $i; # update counter.
close ID; # automatically removes file lock

Be sure you backup your database before you do this. It hasn't been tested, except for syntax errors.

JPD
http://www.jpdeni.com/dbman/
Subject Author Views Date
Thread defragmenting DB 4wallaby 6121 Jun 23, 2000, 4:03 AM
Thread Re: defragmenting DB
JPDeni 5990 Jun 23, 2000, 4:27 AM
Thread Re: defragmenting DB
4wallaby 5988 Jun 23, 2000, 7:21 AM
Thread Re: defragmenting DB
ELB 5985 Jun 23, 2000, 10:35 AM
Thread Re: defragmenting DB
JPDeni 5984 Jun 23, 2000, 2:02 PM
Thread Re: defragmenting DB
4wallaby 5961 Jun 26, 2000, 8:14 AM
Thread Re: defragmenting DB
JPDeni 5985 Jun 26, 2000, 2:18 PM
Thread Re: defragmenting DB
4wallaby 5953 Jun 26, 2000, 11:26 PM
Thread Re: defragmenting DB
JPDeni 5954 Jun 27, 2000, 12:07 AM
Thread Re: defragmenting DB
4wallaby 5949 Jun 27, 2000, 3:25 AM
Thread Re: defragmenting DB
JPDeni 5943 Jun 27, 2000, 11:42 AM
Post Re: defragmenting DB
4wallaby 5892 Jul 3, 2000, 2:22 AM