Describe failed for NUM_OF_FIELDS when using odbc_exec_direct (MS SQL Server / DBI::ODBC)



Hi,

I'm trying to write MS SQL Server support for a generic perl module
used to execute arbitrary SQL statements and then return the array
reference for the result set (if one exists). My basic idea was to do
in following way:

my $sth = $dbh->prepare($clause);
$sth->execute();

return if ($sth->{NUM_OF_FIELDS} == 0);
return @{$sth->fetchall_arrayref()};

But I also want to be able to create temporary tables using this same
routine (for example with select ... into #tmp). This is not possible
in MS SQL when prepare + execute is used. Changing the behavior of
execute method to use SQLExecDirect will solve this problem (by
setting $dbh->{odbc_exec_direct} = 1). But this causes following error
message:

Describe failed during DBI::st=HASH(0x19c2048)->FETCH(NUM_OF_FIELDS,0)

The script works ok, but is there any way to get rid of this error
message? I tried to read all the documentation, but I could not figure
out any other way to check if the statement contains any result sets
than using the NUM_OF_FIELDS.

Versions in use:

This is perl, v5.8.8 built for MSWin32-x86-multi-thread
Binary build 822 [280952] provided by ActiveState http://www.ActiveState.com
DBD-ODBC: ODBC Driver for DBI Version: 1.13
SQL Native Client 2005.90.3042.00

Thanks in advance for any help, Toni
.



Relevant Pages

  • Re: Describe failed for NUM_OF_FIELDS when using odbc_exec_direct (MS SQL Server / DBI::ODBC)
    ... I'm trying to write MS SQL Server support for a generic perl module ... used to execute arbitrary SQL statements and then return the array ... in MS SQL when prepare + execute is used. ...
    (perl.dbi.users)
  • Re: Describe failed for NUM_OF_FIELDS when using odbc_exec_direct (MS SQL Server / DBI::ODBC)
    ... I'm trying to write MS SQL Server support for a generic perl module ... used to execute arbitrary SQL statements and then return the array ... in MS SQL when prepare + execute is used. ... is caused by DBD::ODBC calling SQLNumResultCols after SQLMoreResults says there are no more results and the ODBC driver manager is returning a function sequence error for the second call. ...
    (perl.dbi.users)
  • Re: Opinions on approach, please...
    ... Create a data layer program per table, ... number of bind variable tokens in your dynamic SQL. ... then simply EXECUTE that without passing it any parameters? ... Hard code WHERE clauses. ...
    (comp.lang.cobol)
  • Re: SQL Injection- Bypassing magic_quotes
    ... Because i was trying to execute: ... Don't terminate the query and you most ... Or try something like bobcat or one of the other SQL injection tools out ... Chief Information Security Officer ...
    (Pen-Test)
  • Re: Describe failed for NUM_OF_FIELDS when using odbc_exec_direct (MS SQL Server / DBI::ODBC)
    ... I'm trying to write MS SQL Server support for a generic perl module ... used to execute arbitrary SQL statements and then return the array ... in MS SQL when prepare + execute is used. ... is caused by DBD::ODBC calling SQLNumResultCols after SQLMoreResults says there are no more results and the ODBC driver manager is returning a function sequence error for the second call. ...
    (perl.dbi.users)