I don't understand something. I am executing a sybase stored procedure. While testing, I am forcing various error conditions. In a couple cases I am puzzled about the outcome.

Here is the execute statement. I was getting results I did not understand, so I decided to capture $retCode and take a look at it. I also repeated the printf statement so I could see err and errstr even when the error handler was not executed.

# Execute query and handle error condition. Capture $retCode for later examination.

$retCode = $sth->execute() ||
printf("<BR>##### Trouble with dbh->execute():<br>" .
 "dbh->err= '%s'<br>" .
 "dbh->errstr= '%s'<br>",
 $dbh->err,
 $dbh->errstr
);

# Examine $retCode, err, and errstr

print "<BR>after execute retCode is: $retCode <br>";
printf("dbh->execute():<br>" .
"dbh->err= '%s'<br>" .
"dbh->errstr= '%s'<br>",
$dbh->err,
$dbh->errstr
);

scenario 1 ------------------------------------------
Here is the output from successful execution. You can see that the error handler part is not executed. $retCode is -1.


after execute retCode is: -1
dbh->execute():
dbh->err= ''
dbh->errstr= ''

scenario 2 ------------------------------------------
Here I deliberately passed an incorrect data type as a parameter to the stored procedure. As you can see, there was an error, but it was not caught by the error handling code (after the "||"). It seems strange to me that retCode is -1.


after execute retCode is: -1
dbh->execute():
dbh->err= '257'
dbh->errstr= 'Server message number=257 severity=16 state=1 line=0 server=SCATS1P_SQL procedure=sc_deal_update text=Implicit conversion from datatype 'VARCHAR' to 'SMALLINT' is not allowed. Use the CONVERT function to run this query.'


scenario 3 ------------------------------------------
Here I deliberately changed the stored procedure name to an incorrect one. This time the error handling code (after the "||") is executed. Oddly, $retCode is 1. I would think that the error handler would get executed only if $retCode is 0 or empty. What's going on here?


##### Trouble with dbh->execute():
dbh->err= '2812'
dbh->errstr= 'Server message number=2812 severity=16 state=5 line=22 server=SCATS1P_SQL text=Stored procedure 's_deal_update' not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output). '


after execute retCode is: 1
dbh->execute():
dbh->err= '2812'
dbh->errstr= 'Server message number=2812 severity=16 state=5 line=22 server=SCATS1P_SQL text=Stored procedure 's_deal_update' not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output). '


Thanks!





_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail




Reply via email to