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

I have a very typical problem: i am using DBI sybase: and i have a query of the form
use database go select * from table go
now i have to split the query at go and execute both the queries in the same order. the procedure which i am using is split at "go" using the split function and storing in an array. now i am accessing each element of the array and excuting it using the execute in DBI and getting the rows using fetch. but since the use database statement wont return rows its giving me eror at the fetch statment say no statment executed at that line. How do i stop it from giving me that error. I tried using if statement like
if (sth->fetch()) { code here }
but still giving me that error on the line of fetch. Please help out of this grave problem. thanks - Turumkhan

Replies are listed 'Best First'.
Re: how to catch the query retunin no rows.
by Arguile (Hermit) on Jun 08, 2001 at 03:21 UTC
    Update:

    Oops, read that over again and see what you're saying. You're accepting SQL from a form as if it was command line. What about adding if ($sth->rows) beforehand? Then the fetch would only run if there were rows returned. Alternately allow the user to select the db they want to use beforehand, and use it the DBI->connect() string. I'm way too new at DBI and Perl in general to really answer that... and here I though there was finally a question I could answer...*sigh*

    Now Irrelevant Info:

    Firstly you don't have to "use database" as an SQL command like you would from a command line interface.

    my $dbh = DBI->connect('DBI:DBMS_module:database_name');

    This will create a connection to the DBMS, if you need to supply a username and password (suggested) then pass them as well.

    my $dbh = DBI->connect('DBI:DBMS_module:database_name', 'username', 'p +assword');

    The next issue is you never have to throw a go command in, these are implicit when you call any method to fetch the data you want. I simply don't have the experience w/ DBI to answer past this with as much confidence or as well as the following sources: