DBI and Signals

2001-11-12 Thread Mark Riehl

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




DBI and Signals

2001-09-19 Thread Mark Riehl

All - I'm running Perl 5.6.0 and DBI 1.14 under Win2k.  I've got a problem
with signals.  It seems as if I can't catch any signals (e.g., Ctrl-C) after
making a connection to my database (MySQL).  I need to manually use the Task
Manager (Ctrl - Alt - Del) to stop the process.

I've deleted all unnecessary code, including the database query itself (yes,
the same problem occurs if a query is left in place).  If I comment out the
connect and disconnect statements, I don't have any problems catching the
signal.

I need this set up inside the while loop because this code will eventually
be part of a server, accepting client connections from Perl and C++ clients.

Any suggestions?

Thanks,
Mark

*

Here's the code I'm running (it will run if you adjust $dbstring, user, and
password):

#!perl -w

use strict;
use diagnostics;
use DBI;

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

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

  my $result = query_db();
  print $result;

  sleep(2);
}

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;

  return ($result);
}

sub catch_int { 
  my $sig = shift;

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


--
Mark Riehl
Agile Communications, Inc.
Email: [EMAIL PROTECTED]