From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.1.2
PHP Bug Type:     Sybase (dblib) related
Bug description:  mssql_query does not update get_last_message

If you make the following calls in PHP 4.1.2 on Linux using freetds 0.53 to
connect to a MS SQL Server 7 database:

mssql_query ("mystoredproc");
$msg = mssql_get_last_message ();
print $msg;

where "mystoredproc" is a stored procedure that returns N rows of data and
calls the SQL function below to send a warning message:

raiserror ('QueryLimit',9,1)

you would expect the value of $msg to be "QueryLimit" after the call to
mssql_query.  In fact, this is how it works on Windows but not on Linux
using freetds.  I have debugged this issue on both the freetds and php
software and found the following.  On Freetds, the message number that
gets returned from SQL is 50000 which when stored as a 16-bit signed
integer is a negative value in the freetds code, so the freetds code
ignores the message.  I modified the freetds code to NOT ignore negative
message numbers but to go ahead and pass those messages on to the
appropriate callback function in PHP.  That helped matters, but there was
still an issue in the php code in the "sybase_query" function in
php_sybase_db.c.  Basically, what is happening is that in the case
described above, you receive 2 sets of database results as a result of the
query, but the sybase_query function is only reading the first set of
results.  To remedy the problem, I modified the sybase_query function to
save the results of the first call to dbresults().  Then, after reading
all the rows of data from the first set of results, I checked the result
of the first call to dbresults.  If it is not set to NO_MORE_RESULTS, I
call dbresults again to read the second set of results, which in this
case, is the warning message.  By doing so, this causes the freetds
software to recognize the message and callback PHP with the message.  I
have tested these fixes on Linux and they seem to work find I can email
the source code for the fix if you are interested....


-- 
Edit bug report at http://bugs.php.net/?id=17291&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=17291&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=17291&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=17291&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=17291&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17291&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=17291&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=17291&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=17291&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=17291&r=globals

Reply via email to