]> granicus.if.org Git - php/commitdiff
Reset the error (or message) from the server when calling fetch_row functions.
authorFrank M. Kromann <fmk@php.net>
Mon, 29 Oct 2001 23:41:15 +0000 (23:41 +0000)
committerFrank M. Kromann <fmk@php.net>
Mon, 29 Oct 2001 23:41:15 +0000 (23:41 +0000)
If the user conected and changed the database the message from the change was reported
when the user checked the error function after a failed fetch.
This cased problems in PEAR/DB.
If the fetch fails for other resons than a fetch after the last row, the message from the server will still be reported.

ext/mssql/php_mssql.c

index cf4c655f406db7f92e4d3b305f3ff490506fc3d8..e5f85125e5b982bb0fc1bc5b7c290c40720c766f 100644 (file)
@@ -156,7 +156,9 @@ static int php_mssql_message_handler(DBPROCESS *dbproc, DBINT msgno,int msgstate
        if (severity >= MS_SQL_G(min_message_severity)) {
                php_error(E_WARNING,"MS SQL message:  %s (severity %d)", msgtext, severity);
        }
-       STR_FREE(MS_SQL_G(server_message));
+       if (MS_SQL_G(server_message)) {
+               STR_FREE(MS_SQL_G(server_message));
+       }
        MS_SQL_G(server_message) = estrdup(msgtext);
        return 0;
 }
@@ -1110,7 +1112,12 @@ PHP_FUNCTION(mssql_free_result)
    Gets the last message from the MS-SQL server */
 PHP_FUNCTION(mssql_get_last_message)
 {
-       RETURN_STRING(MS_SQL_G(server_message),1);
+       if (MS_SQL_G(server_message)) {
+               RETURN_STRING(MS_SQL_G(server_message),1);
+       }
+       else {
+               RETURN_STRING(empty_string,1);
+       }
 }
 
 /* }}} */
@@ -1182,6 +1189,11 @@ static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
 
        ZEND_FETCH_RESOURCE(result, mssql_result *, mssql_result_index, -1, "MS SQL-result", le_result);        
 
+       if (MS_SQL_G(server_message)) {
+               STR_FREE(MS_SQL_G(server_message));
+               MS_SQL_G(server_message) = NULL;
+       }
+
        if (result->cur_row >= result->num_rows) {
                RETURN_FALSE;
        }
@@ -1624,7 +1636,7 @@ PHP_FUNCTION(mssql_result)
 }
 /* }}} */
 
-/* {{{ proto string mssql_next_result(int result_id)
+/* {{{ proto bool mssql_next_result(int result_id)
    Move the internal result pointer to the next result */
 PHP_FUNCTION(mssql_next_result)
 {