Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI killing IIS

Status
Not open for further replies.

Zippeh

Programmer
Sep 24, 2002
56
GB
I have some code that executes an Insert to a database using DBI. When this exectue fails, I would like it to die gracefuly reversing the inserts that have taken place. Unfortunately, it dies a miserable death and takes IIS with it!

Has anybody else come across anything like this?

Code:
...

 $sqlstatement= qq{
      insert into items (parentid,title,description,archivedate,archiveid,imagename,status,indexed) values ($parentid,'$fields[2]','$fields[4]','$fields[3]',$archiveid,'$image',0,0)

  $sth = $db->prepare("$sqlstatement");
  $sth->execute or die "Wedi methu ar llinell $. , Wedi dad wneud yr ychwanegiadau\n";
...
 
You could
Code:
my $sqlcode = $sth->execute();
which should give you the return code. Also, as you are preparing your statement, use placeholders and pass the parameters on the execute. As well as being easier, this will protect you from SQL injection attacks.
 
Instead of "$sth->execute() or die" try "$sth->execute() or $sth->rollback"

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
I've changed it now so it calls a subroutine called "marw", which means die in welsh:

Code:
...
$sth = $db->prepare("$sqlstatement");
$sth->execute or marw($.);

sub marw {
  my $llinell = $_[0];
  $db->rollback();
  $db->disconnect();
  die "Wedi methu ar llinell $llinell. Wedi dad wneud yr ychwanegiadau\n";
}
...

I'm adding some code to check the length of the fields now.
 
It doesn't matter what I do, everything just seems to be killing IIS :(

How do you go about closing your scripts?? Is it just with a

Code:
$db->disconnect();

I'm talking about every script now, e.g. Inserts, Selects etc.

Any help at all would be very much welcome :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top