Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here is the Solution:
Martin Evans on the dbi-user mailing list was able to finally find the source of this error, here is the text of his reply:

I analysed your log and did the same thing in ODBCTest which used to come with MDAC and it fails in the same way: SQLPrepare(print 's' select count(*) from table print 'e') SQLNumResultCols() returns SQL_ERROR and invalid cursor state. so, I'm afraid, there is no bug in DBD::ODBC and the problem is in the MS SQL Server driver. Interestingly, our ODBC-ODBC Bridge makes you code almost work because it inserts a call to SQLNumParams between the SQLPrepare and the SQLNumResultCols and that puts the MS SQL Server Driver into a different state. I say "almost" because it does appear to hightlight another bug in the MS SQL Server driver later on where SQLMoreResults returns SQL_NO_DATA but a later call to SQLNumResultCols returns 1 column and this persuades DBD::ODBC there is a column and it fails on a call to SQLDescribeCol (because SQLNumResultCols lied and there is no result-set). Your only choice is to take the prints out.

I ended up building DBI 1.45 and DBD::ODBC 1.11 on my machine.
I was still able to achieve the desired result by using a suggestion our DBA made of substituting a SELECT everywhere there is a PRINT and that seems to work nicely. For statements that return multiple result sets I ended up using the following:

#!C:/perl/bin/perl -w #DBI 1.45 #DBD::ODBC 1.11 use DBI; $dbh = DBI->connect("dbi:ODBC:tmpDB", 'username','password', { PrintError => 1, RaiseError =>0, LongReadLen => 65536, odbc_async_exec => 1, odbc_err_handler => \&errSub } ); $command = qq/ select 'start' select name = 'dbi-user' select 'end' /; $sth = $dbh->prepare($command); die $DBI::errstr unless $sth; my $rc = $sth->execute(); do { my @row; while (@row = $sth->fetchrow_array()) { print join(",", @row), "\n"; } } while ($sth->{odbc_more_results}); $dbh->disconnect; sub errSub { my ($state, $msg) = @_; # Strip out all of the driver ID stuff $msg =~ s/^(\[[\w\s]*\])+//; my $err_text .= $msg."\n"; print "Err($state):",$err_text; }
Thanks to all who responded.

JamesNC

In reply to Re: DBI Invalid Cursor State when PRINT statements are embedded in SQL by JamesNC
in thread DBI Invalid Cursor State when PRINT statements are embedded in SQL by JamesNC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found