WODA: FAQs

 Related Files

Can I delete records from a related file when I delete a record?

here is how I solved the problem. It works great.

in exams.pl define:

$WBB{'afterTableModify'}='if ($Action =~ /^cgiDelete/)
{&DeleteLinkedRecords(students, "data:$rec{_id}");}';

sub DeleteLinkedRecords {
local($linkedtable, $search)=@_;

local($mes, $message);
local($ids)=&ROWS($linkedtable, "_id", $search);
foreach $id (split("\n", $ids)) {
undef $mes;
$mes = &LinkedRecDelete($linkedtable, $id);
if ($mes) {
$message .= "$mes<BR>";
}
else {
$message .= "record: $id from table $linkedtable deleted!<BR>";
}
}
print "<P>$message";
}

sub LinkedRecDelete {
local ($linkedtable, $id, $keepAttach)=@_;

if ($id eq '' || $id =~ m/^[\*\?\.]/) {
return("Cannot delete record with id=$id");
}

local($dir) = &wbTables('DIR',$linkedtable);

open (h,">>$dir/_data/fat.txt");
binmode(h);
print h "$id\t-1\n";
close(h);

if (!$keepAttach) {
chdir ("$dir/att") || return("Cannot chdir to $dir/att");
local(@all,$x);
@all = &glob("$id.*");
foreach $x (@all) {
unlink "$x" || return("Could not delete $x");
}
}

}

--
Dr. Claudio Rivetti

modify the informationdelete entire recordexplain the meaning of the fieldsbrowse recordsAdd a new questionHome page of this databaselogin Valid HTML 4.01 Transitional Valid CSS! Powered by WODA 4.6x trunk