Attached is a patch for error handling with Sybase/MSSQL databases.
Basically it picks up the message and the error number from the
dberrhandler() call. This means that MSSQL/Sybase RAISERROR calls can be
caught properly in the PHP script.
Any chance of someone committing it in?
Dave.
Index: ext/sybase/php_sybase_db.c
===================================================================
RCS file: /repository/php4/ext/sybase/php_sybase_db.c,v
retrieving revision 1.37
diff -u -r1.37 php_sybase_db.c
--- ext/sybase/php_sybase_db.c 12 Mar 2002 20:18:00 -0000 1.37
+++ ext/sybase/php_sybase_db.c 22 May 2002 13:37:43 -0000
@@ -88,6 +88,8 @@
PHP_FE(sybase_query, NULL)
PHP_FE(sybase_free_result, NULL)
PHP_FE(sybase_get_last_message, NULL)
+ PHP_FE(sybase_get_last_error, NULL)
+ PHP_FE(sybase_get_last_error_no, NULL)
PHP_FE(sybase_num_rows, NULL)
PHP_FE(sybase_num_fields, NULL)
PHP_FE(sybase_fetch_row, NULL)
@@ -107,6 +109,8 @@
PHP_FALIAS(mssql_query, sybase_query, NULL)
PHP_FALIAS(mssql_free_result, sybase_free_result, NULL)
PHP_FALIAS(mssql_get_last_message, sybase_get_last_message, NULL)
+ PHP_FALIAS(mssql_get_last_error, sybase_get_last_error, NULL)
+ PHP_FALIAS(mssql_get_last_error_no, sybase_get_last_error_no, NULL)
PHP_FALIAS(mssql_num_rows, sybase_num_rows, NULL)
PHP_FALIAS(mssql_num_fields, sybase_num_fields, NULL)
PHP_FALIAS(mssql_fetch_row, sybase_fetch_row, NULL)
@@ -146,6 +150,9 @@
if (severity >= php_sybase_module.min_error_severity) {
php_error(E_WARNING,"Sybase error: %s (severity
%d)",dberrstr,severity);
}
+ STR_FREE(php_sybase_module.error_message);
+ php_sybase_module.error_message = estrdup(dberrstr);
+ php_sybase_module.error_no = dberr;
return INT_CANCEL;
}
@@ -279,8 +286,10 @@
{
php_sybase_module.default_link=-1;
php_sybase_module.num_links = php_sybase_module.num_persistent;
- php_sybase_module.appname = estrndup("PHP 4.0",7);
+ php_sybase_module.appname = estrndup("PHP 4.2",7);
php_sybase_module.server_message = empty_string;
+ php_sybase_module.error_message = empty_string;
+ php_sybase_module.error_no = 0;
php_sybase_module.min_error_severity =
php_sybase_module.cfg_min_error_severity;
php_sybase_module.min_message_severity =
php_sybase_module.cfg_min_message_severity;
return SUCCESS;
@@ -296,6 +305,7 @@
{
efree(php_sybase_module.appname);
STR_FREE(php_sybase_module.server_message);
+ STR_FREE(php_sybase_module.error_message);
return SUCCESS;
}
@@ -940,6 +950,26 @@
RETURN_STRING(php_sybase_module.server_message,1);
}
/* }}} */
+
+
+/* {{{ proto string sybase_get_last_error(void)
+ Returns the last error message from server */
+PHP_FUNCTION(sybase_get_last_error)
+{
+ RETURN_STRING(php_sybase_module.error_message,1);
+}
+/* }}} */
+
+
+/* {{{ proto string sybase_get_last_error_no(void)
+ Returns the last error number from server */
+PHP_FUNCTION(sybase_get_last_error_no)
+{
+ Z_LVAL_P(return_value) = php_sybase_module.error_no;
+ Z_TYPE_P(return_value) = IS_LONG;
+}
+/* }}} */
+
/* {{{ proto int sybase_num_rows(int result)
Get number of rows in result */
Index: ext/sybase/php_sybase_db.h
===================================================================
RCS file: /repository/php4/ext/sybase/php_sybase_db.h,v
retrieving revision 1.8
diff -u -r1.8 php_sybase_db.h
--- ext/sybase/php_sybase_db.h 28 Feb 2002 08:26:50 -0000 1.8
+++ ext/sybase/php_sybase_db.h 22 May 2002 13:37:45 -0000
@@ -38,6 +38,8 @@
PHP_FUNCTION(sybase_query);
PHP_FUNCTION(sybase_free_result);
PHP_FUNCTION(sybase_get_last_message);
+PHP_FUNCTION(sybase_get_last_error);
+PHP_FUNCTION(sybase_get_last_error_no);
PHP_FUNCTION(sybase_num_rows);
PHP_FUNCTION(sybase_num_fields);
PHP_FUNCTION(sybase_fetch_row);
@@ -70,6 +72,8 @@
long allow_persistent;
char *appname;
char *server_message;
+ char *error_message;
+ int error_no;
int le_link,le_plink,le_result;
long min_error_severity,min_message_severity;
long cfg_min_error_severity,cfg_min_message_severity;
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php