Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: DBI Invalid Cursor State when PRINT statements are embedded in SQL

by terra incognita (Pilgrim)
on Oct 18, 2004 at 19:17 UTC ( [id://400286]=note: print w/replies, xml ) Need Help??


in reply to Re^2: DBI Invalid Cursor State when PRINT statements are embedded in SQL
in thread DBI Invalid Cursor State when PRINT statements are embedded in SQL

Your DBA is right. Here is the output from ODBC test. ODBC test seems to know that this is a partial success and returns the rowset as well the “error message”.
PRINT '...begin' select * from foo.bar.mytable SQLExecDirect: In: hstmt = 0x00991FB8, szSqlStr = "", cbSqlStr = -3 Return: SQL_SUCCESS_WITH_INFO=1 stmt: szSqlState = "01000", *pfNativeError = 0, *pcbErrorMsg = 55, +*ColumnNumber = -1, *RowNumber = 1 MessageText = "[Microsoft][ODBC SQL Server Driver][SQL Server]...b +egin" Get Data All: -1 rows affected by INSERT/UPDATE/DELETE or other statement. "col1", "col2", "col3" 1, "row1", "row1" 2, "row2", "row2" 2 rows fetched from 3 columns.
MS SQL Server help also mentions that you have to call SQLError right after statement is executed.

The timing of calling SQLError is critical when output from PRINT or RAISERROR statements are included in a result set. The call to SQLError to retrieve the PRINT or RAISERROR output must be made immediately after the statement that receives SQL_ERROR or SQL_SUCCESS_WITH_INFO. This is straightforward when only a single SQL statement is executed, as in the examples above. In these cases, the call to SQLExecDirect or SQLExecute returns SQL_ERROR or SQL_SUCCESS_WITH_INFO and SQLError can then be called. It is less straightforward when coding loops to handle the output of a batch of SQL statements or when executing SQL Server stored procedures.

Replies are listed 'Best First'.
Re^4: DBI Invalid Cursor State when PRINT statements are embedded in SQL
by JamesNC (Chaplain) on Oct 18, 2004 at 19:55 UTC
    This was helpful... but any idea how can I capture both the SQL_SUCCESS_WITH_INFO __AND__ the results of the select? I see $dbh->errstr has MicrosoftODBC SQL Server DriverSQL Server...begin(SQL-01000) when the PRINT statement is run all alone, but get the cursor error when it is run with the select... arrgh...
      Hello guys.

      I researched this one and found a site with a solution that works. It is pretty helpful, but seems a little hard to use the statements for what they were meant for, logically organizing the output. I am still working to trap the PRINT statements in a meaningful way so that they appear in the data (array or output file) the way that the DBA meant them to.

      If anyone reading this is an error trapping guru it would be nice to know how to trap these statements in a meaningful way. I don't really understand how that second while loop does what it does. For now, I can only seem to get them to appear on the console.

      Here is the link to the page that breaks it all down:

      http://www.easysoft.com/developer/languages/perl/sql_server_unix_tutorial.html#print_statement_status_messages

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-03-28 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found