Kirill has asked for the wisdom of the Perl Monks concerning the following question:

Hello!
I have such a problem. I am not sure that it is related to perl, but as long as I am using it, I decided to post a question here.
I'm using an ODBC for connection the DB with Perl. Here's such a simple example:
my $result; $db = new Win32::ODBC("DSN=DSNName;UID=$login;PWD=$pass") or die; print "Connected to DB! \n"; $db->Sql ("Select name from person"); while ($db->FetchRow) { $result = $db->Data(); print "Result is - $result"; }
The problem is that when I am using it for a simple queries, that doesn't take much time - it's fine. It connects to the DB, executes the query and returns the result data.
But if it is a big query, that needs some time to be executed (at least several minutes) - than the script returns no result to me. It looks like it even doesn't get inside the "while". How can it be?
Is it possible, that there's some time limit? Like a session limit or whatever?
Did anyone happen to face with problems like this? I would appreciate any help.

Thanks a lot.
Waiting for your replies.

Replies are listed 'Best First'.
Re: Perl + ODBC + long time queries
by Corion (Patriarch) on Sep 18, 2010 at 09:58 UTC

    ODBC has a query timeout. I'm not sure how to set it through Win32::ODBC, but likely it involves a sequence of $db->SetStmtOption and information taken from ODBC SQLSetStmtAttr. I'm not sure whether DBI offers a better API, but at least DBI has RaiseError, which turns database errors into Perl errors and thus makes error detection much easier.

    Also see the Win32::ODBC FAQ on how to implement error checking with the ->Sql call.