All - I'm running under Win2k.  I know that signals aren't totally supported
under Windows, but I've got some questions related to DBI.

In the following script, I can't seem to catch the SIG INT after a
connection to the database is made (even w/o making any queries).  Without
the connect calls, I can catch a SIG INT without a problem.

Right now, the only way to stop this script is to use the task manager and
kill it - is there a better way to do this?

Thanks,
Mark

###################################################
#!perl -w

use strict;
use diagnostics;
use DBI;

my $quit = 0;
$SIG{INT} = \&catch_int;

while (!$quit) {
  print "in while()\n";

  # Comment out these two lines and it works fine.      
  ##################
  my $result = query_db();
  print $result;
  ##################

  my $i = 0;
  for ($i = 0; $i < 10; $i++) {
    sleep (1);
    print ". ";
  }
}

sub query_db {
   # Build the database connection string.
  my $dbstring = "DBI:mysql:database01:127.0.0.1:3306";

  # Connect to the database.
  my $dbh = DBI->connect($dbstring,"user","password")
    or die "Can't connect to mysql on 127.0.0.1: $DBI::errstr\n";

  # Assume result from the db is named result.
  my $result = "Test";

  print "Disconnecting \$dbh\n";
  $dbh->disconnect()
    or warn "Disconnection failed: $DBI::errstr\n";

  return ($result);
}

sub catch_int { 
  my $sig = shift;

  print "Caught $sig\n";
  $quit++;
}


--
Mark Riehl
Agile Communications, Inc.
Email: [EMAIL PROTECTED]
Business: (732) 528-9305
Fax: (732) 528-9308
Cell: (732) 996-7630

Reply via email to