[EMAIL PROTECTED] [[EMAIL PROTECTED]] wrote:
> 
> The script I'm using is basically this ....
> 
>     $dbname = "dbi:Sybase:server=$ENV{SYBASE_DB_SERVER};".
>                   "database=$ENV{SYBASE_DB_NAME}";
>     .
>     .
> 
>     my $dbh=DBI->connect($dbname,$username,$password,
>            { RaiseError => 1, AutoCommit => 1})
>      or die "Couldn't connect to database: " . DBI->errstr;
> 
>     my $selsql = "select count(*) from $table";

$dbh->trace(2); can be pretty helpful to see what sql is actually
being sent to the database - are you sure that $selsql contains
what you expect?  I usually put

   $dbh->trace(2);

above my "prepare" and "execute" of the sql in question, and then
put a

   $dbh->trace(0);

after.

Seems to me $table may need single quotes around it - I think
that will make it ok if $table contains a tablename that has
spaces in it.  Try putting single quotes around $table, like

    my $selsql = "select count(*) from '$table'";

> 
> I have tried both of the following:
> 
>    my $count = $dbh->do($selsql);   # returns -1

I think(?) the DBI perldocs point out that you can't use "do"
with a SELECT.  I'm not entirely sure about this, and I don't
have time to check the docs.

> 
> 
>    my $count = $dbh->selectrow_array($selsql);    #returns 0

I'm not familiar with selectrow_array - for SELECT's, I always
do "prepare" and "execute" and some form of "fetch".  I can't
be much help here, but try the "trace" stuff I mentioned above.

> I have a similar version of this running against a DB2 database and it
> works fine.

Different database drivers treat some thing differently.

HTH.

-- 
Hardy Merrill
Senior Software Engineer
Red Hat, Inc.

Reply via email to