Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2014-12-21 00:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (100 votes), past polls