Query returns -1 if row present (DBI, SQL Server 2000)



Hello,

I am using the DBI module to interface with a SQL Server 2000 database
-- connection, INSERT, UPDATE, and SELECT (when 0 rows exist in
resultset) are fine. However, if the resultset contains a row, a
value of -1 is returned. The query is very simple:

my $sth = $dbh->prepare(q{SELECT TOP 1 id FROM host WHERE ip = ?});
$sth->execute($ip);
print "Looked up $ip: " . $sth->rows . " ($DBI::errstr)\n";

if ($sth->rows == 0) {
# do something
}

elsif ($sth->rows > 0) {
# do something else
}

else {
# error
}

I do not believe this to is a permission problem with SQL Server as
the initial SELECT runs and jumps properly when $sth->rows is 0.
However the code always ends up in the else block if a row is returned
from the initial SELECT. The SELECT query also runs fine in Query
Analyzer when entered manually. Oh, it may also be worth mentioning
that $DBI::errstr is empty after the execute call for the initial
SELECT query.

TIA.

.



Relevant Pages

  • Re: Query from ms sql server question
    ... For example, in my worksheet, there a cell which user will enter the production number and macro will perform an automatic connection to sql server and query the table base on the production number and retrieve the data base on the production alone and place it on the excel sheet. ...
    (microsoft.public.excel.programming)
  • Re: When do selects execute for multiple resultsets
    ... SQL Server executes each query and stops when its ... When the first resultset is ... The CommandTimeout is measured from the time you execute the query until the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ANSI_WARNINGS error in Stored Procedure
    ... The error says to set these options for your _connection_ not for the query. ... > I have a linked Server on my regular SQL server, and when I try to create ... a stored procedure that reads from the linked server, ...
    (microsoft.public.sqlserver.security)
  • Re: Problem with blank entries being filled with other values
    ... We have a table in SQL Server ... We run a Make Table query within Access, which produces a table in Access ... The connection via DDE worked. ... >> in the Counter field are replaced with values from this field in other ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Help: inappropriate OLEDB timeout:
    ... the Connection object is using ... > The application was developed using the SQLOLEDB provider. ... All I know is that a query starts to time out after 30 seconds. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.data.oledb)