On Aug 10, 2009, at 9:21 PM, 田口 浩 wrote:
Hello,
I like to stop a long running SQL by the code:
my $sth = $dbh->prepare($stmt, { db2_query_timeout => 6 });
my $to = $sth->{db2_query_timeout};
print "end prepare, to=$to.\n";
But my script doesn't stop, and $to is 0.
My code is wrong?
DBI = 1.53 DBD::DB2 = 1.71, DB2 = v8.1
Regards,
Hirosi Taguti
Hirosi,
Here's how I effect a timeout on potentially long-running queries:
eval {
local $SIG{'ALRM'} = sub {
die "DB search timed out after $timeout seconds\n"
};
alarm $timeout if $timeout && $^O !~ /Win32/i;
$markers = $db->selectall_arrayref($select_sql, { Columns
=> {} });
alarm 0 unless $^O =~ /Win32/i;
};
if ( my $err = $@ ) {
print STDERR __PACKAGE__, "::db_search error: ",
"$err\nSQL=\n$select_sql";
croak( $err );
return wantarray ? () : undef;
}
HTH,
ky