Hi,
i am new to this list. But i made a little patch for the sybase-module to
return status-returns of stored procedures.
With the new function sybase_get_status() you can retrieve the latest
status that sybase returned. This is important if you want to catch
errors from a stored procedure.
for instance:
sybase_query("sp_help non_existing_table");
echo sybase_get_status();
will show you:
1
(which happens to be the statuscode that sp_help gives if you if
it doesn't find the mentioned table)
This diff is made from php-4.0.3pl1 but i just tried it on php-4.0.4pl1 and it
gives no problems.
--
Jo Giraerts
Development Services Engineer
VA Linux Professional Services Europe
Interleuvenlaan 15A, 3001 LEUVEN, BELGIUM
icq:81939849, email:[EMAIL PROTECTED], ph0ne:+32(0)475/437719
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GIT/GMU dx(--) s: a-- C++++ L+++$ P+ E--- W++ N++(+) !o K? w--- !0 M-
V? PS+++ PE- Y+ PGP++ t+@ 5- X(-) R(*) tv-@ b+++ DI++ D+ G++ e* h(+) r- y+
------END GEEK CODE BLOCK------
diff -Naur php-4.0.3pl1/ext/sybase/Makefile php-4.0.3pl11-tweaked/ext/sybase/Makefile
--- php-4.0.3pl1/ext/sybase/Makefile Thu Jan 1 01:00:00 1970
+++ php-4.0.3pl11-tweaked/ext/sybase/Makefile Fri Jan 19 16:54:14 2001
@@ -0,0 +1,12 @@
+top_srcdir = /usr/local/php-soft/php-4.0.3pl11-tweaked
+top_builddir = /usr/local/php-soft/php-4.0.3pl11-tweaked
+srcdir = /usr/local/php-soft/php-4.0.3pl11-tweaked/ext/sybase
+builddir = /usr/local/php-soft/php-4.0.3pl11-tweaked/ext/sybase
+VPATH = /usr/local/php-soft/php-4.0.3pl11-tweaked/ext/sybase
+
+LTLIBRARY_NAME = libsybase.la
+LTLIBRARY_SOURCES = php_sybase_db.c
+LTLIBRARY_SHARED_NAME = php_sybase_db.la
+LTLIBRARY_SHARED_LIBADD = $(SYBASE_SHARED_LIBADD)
+
+include $(top_srcdir)/build/dynlib.mk
diff -Naur php-4.0.3pl1/ext/sybase/libs.mk php-4.0.3pl11-tweaked/ext/sybase/libs.mk
--- php-4.0.3pl1/ext/sybase/libs.mk Thu Jan 1 01:00:00 1970
+++ php-4.0.3pl11-tweaked/ext/sybase/libs.mk Fri Jan 19 16:53:31 2001
@@ -0,0 +1,6 @@
+LTLIBRARY_OBJECTS = $(LTLIBRARY_SOURCES:.c=.lo) $(LTLIBRARY_OBJECTS_X)
+LTLIBRARY_SHARED_OBJECTS = $(LTLIBRARY_OBJECTS:.lo=.slo)
+$(LTLIBRARY_NAME): $(LTLIBRARY_OBJECTS) $(LTLIBRARY_DEPENDENCIES)
+ $(LINK) $(LTLIBRARY_LDFLAGS) $(LTLIBRARY_OBJECTS) $(LTLIBRARY_LIBADD)
+
+targets = $(LTLIBRARY_NAME)
diff -Naur php-4.0.3pl1/ext/sybase/php_sybase_db.c
php-4.0.3pl11-tweaked/ext/sybase/php_sybase_db.c
--- php-4.0.3pl1/ext/sybase/php_sybase_db.c Sun Sep 3 19:43:09 2000
+++ php-4.0.3pl11-tweaked/ext/sybase/php_sybase_db.c Fri Jan 19 16:01:24 2001
@@ -46,7 +46,7 @@
PHP_FE(sybase_select_db, NULL)
PHP_FE(sybase_query, NULL)
PHP_FE(sybase_free_result, NULL)
- PHP_FE(sybase_get_last_message, NULL)
+ PHP_FE(sybase_get_last_message, NULL)
PHP_FE(sybase_num_rows, NULL)
PHP_FE(sybase_num_fields, NULL)
PHP_FE(sybase_fetch_row, NULL)
@@ -58,6 +58,7 @@
PHP_FE(sybase_result, NULL)
PHP_FE(sybase_min_error_severity, NULL)
PHP_FE(sybase_min_message_severity, NULL)
+ PHP_FE(sybase_get_status, NULL)
PHP_FALIAS(mssql_connect, sybase_connect, NULL)
PHP_FALIAS(mssql_pconnect, sybase_pconnect, NULL)
PHP_FALIAS(mssql_close, sybase_close, NULL)
@@ -236,6 +237,7 @@
php_sybase_module.server_message = empty_string;
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;
+ php_sybase_module.status = -69696969; /* just to test for a moment */
return SUCCESS;
}
@@ -694,7 +696,7 @@
PHP_FUNCTION(sybase_query)
{
pval *query,*sybase_link_index;
- int id,type,retvalue;
+ int id,type,retvalue, error;
sybase_link *sybase_ptr;
sybase_result *result;
int num_fields;
@@ -729,14 +731,24 @@
convert_to_string(query);
if (dbcmd(sybase_ptr->link,query->value.str.val)==FAIL) {
- /*php_error(E_WARNING,"Sybase: Unable to set query");*/
+ php_error(E_WARNING,"Sybase: Unable to set query");
RETURN_FALSE;
}
+
if (dbsqlexec(sybase_ptr->link)==FAIL || dbresults(sybase_ptr->link)==FAIL) {
- /*php_error(E_WARNING,"Sybase: Query failed");*/
+ php_error(E_WARNING,"Sybase: Query failed");
RETURN_FALSE;
}
+ /* Setting the return-status of stored procedures
+ There's still something weird going on:
+ if (status==0) it doesn't get returned properly
+ */
+ if (dbhasretstat(sybase_ptr->link) == TRUE)
+ {
+ php_sybase_module.status = dbretstatus(sybase_ptr->link);
+ }
+
/* The following is more or less the equivalent of mysql_store_result().
* fetch all rows from the server into the row buffer, thus:
* 1) Being able to fire up another query without explicitly reading all rows
@@ -744,7 +756,7 @@
*/
retvalue=dbnextrow(sybase_ptr->link);
-
+
if (retvalue==FAIL) {
RETURN_FALSE;
}
@@ -784,11 +796,12 @@
}
}
retvalue=dbnextrow(sybase_ptr->link);
- dbclrbuf(sybase_ptr->link,DBLASTROW(sybase_ptr->link)-1);
+ dbclrbuf(sybase_ptr->link,DBLASTROW(sybase_ptr->link)-1);
i++;
}
+
+
result->num_rows = DBCOUNT(sybase_ptr->link);
-
result->fields = (sybase_field *) emalloc(sizeof(sybase_field)*num_fields);
j=0;
for (i=0; i<num_fields; i++) {
@@ -827,6 +840,7 @@
break;
}
}
+
efree(column_types);
return_value->value.lval =
zend_list_insert(result,php_sybase_module.le_result);
return_value->type = IS_LONG;
@@ -870,6 +884,17 @@
RETURN_STRING(php_sybase_module.server_message,1);
}
/* }}} */
+
+/* {{{ proto int sybase_get_status(void)
+ Returns the last statuscode (returncode of stored procedure) from server */
+PHP_FUNCTION(sybase_get_status)
+{
+ return_value->value.lval = php_sybase_module.status;
+ return_value->type = IS_LONG;
+}
+/* }}} */
+
+
/* {{{ proto int sybase_num_rows(int result)
Get number of rows in result */
diff -Naur php-4.0.3pl1/ext/sybase/php_sybase_db.h
php-4.0.3pl11-tweaked/ext/sybase/php_sybase_db.h
--- php-4.0.3pl1/ext/sybase/php_sybase_db.h Mon Jul 24 03:39:50 2000
+++ php-4.0.3pl11-tweaked/ext/sybase/php_sybase_db.h Thu Jan 18 15:34:37 2001
@@ -48,6 +48,7 @@
PHP_FUNCTION(sybase_field_seek);
PHP_FUNCTION(sybase_min_error_severity);
PHP_FUNCTION(sybase_min_message_severity);
+PHP_FUNCTION(sybase_get_status);
PHP_FUNCTION(sybase_db_query);
PHP_FUNCTION(sybase_list_fields);
@@ -62,7 +63,6 @@
PHP_FUNCTION(sybase_field_flags);
-
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
@@ -88,6 +88,7 @@
long min_error_severity,min_message_severity;
long cfg_min_error_severity,cfg_min_message_severity;
long compatability_mode;
+ int status; /* returnvalue of a stored procedure */
} sybase_module;
struct sybase_link_struct {
@@ -114,7 +115,6 @@
extern sybase_module php_sybase_module;
-
#else
#define sybase_module_ptr NULL
@@ -122,5 +122,6 @@
#endif
#define phpext_sybase_ptr sybase_module_ptr
+
#endif /* PHP_SYBASE_DB_H */
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]