Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

BUG in DB_Utils.pm

Quote Reply
BUG in DB_Utils.pm
I think I found the reason why the modification of uploads don't work. It's a problem of the sub copy_attach.

foreach my $attach (@$alist) {
$sth->execute ($lid, $lid . ".fil", $attach->{FileName}, $attach->{FileType}, $attach->{FileSize});
$name = $sth->{mysql_insertid} | | $sth->{insertid};
$file = $LINKS{temp_attach_dir} . "/" . $attach->{ServerName};
$new = $LINKS{attach_dir} . "/" . $name . ".fil";
rename ($file, $new) or die..

The attachement file gets added to the database with the Name $Lid.fil where $Lid is the ID of the link!
The file gets renamend to $InsertID.fil where $InsertID is the ID of the attachement.

My problem is that when adding the recordset I dont know the InsertID? Or is there a way of getting it before the execute(...) command?

Can anybody help on this?
Quote Reply
Re: BUG in DB_Utils.pm In reply to
Can you replace copy_attach with:

Code:
sub copy_attach {
# --------------------------------------------------------
# Move an attachment from Validate to Links table.
#
my ($ldb, $vdb, $lid, $vid) = @_;
my ($query, $query2, $sth, $sth2, $file, $new, $aid, $alist);

$alist = $vdb->list_attach($vid);
$query = qq!
INSERT INTO Links_Attach (DataID, FileName, FileType, FileSize)
VALUES (?, ?, ?, ?)
!;
$query2 = qq!
UPDATE Links_Attach SET ServerName = ? WHERE ID = ?
!;
$sth = $ldb->prepare ($query);
$sth2 = $ldb->prepare ($query);
foreach my $attach (@$alist) {
$sth->execute ($lid, $attach->{FileType}, $attach->{FileSize});
$aid = $sth->{mysql_insertid} | | $sth->{insertid};
$sth2->execute ($aid . ".fil", $aid);
$file = $LINKS{temp_attach_dir} . "/" . $attach->{ServerName};
$new = $LINKS{attach_dir} . "/" . $aid . ".fil";
rename ($file, $new) or die "Can't rename '$file' to '$new' ($!)";
if (-e $file) {
unlink $file or die "Can't unlink '$file' ($!)";
}
}
}

and give it a try?

Cheers,

Alex
Quote Reply
Re: BUG in DB_Utils.pm In reply to
Hi Alex

Thank you for the help.

there where to bugs:

Code:
$sth->execute ($lid, $attach->{FileType}, $attach->{FileSize});

Replace with:
$sth->execute ($lid, $attach->{FileName}, $attach->{FileType}, $attach->{FileSize});

and Code:
$aid = $sth->{mysql_insertid} | | $sth->{insertid};

Replace with:
$aid = $sth->{mysql_insertid} | | $sth->{insertid};
(Well the forums software always seems to add a space between the two "| |". If anybody cuts and pastes the code he should check that theres no space between the two "| |")

I works fine now.

Regards, Alexander

[This message has been edited by Alex404 (edited February 01, 2000).]

[This message has been edited by Alex404 (edited February 01, 2000).]