112
*** src/modules/Mysql/mysql.c.orig Tue Dec 23 12:41:22 2008
--- src/modules/Mysql/mysql.c Wed Jan 14 17:41:05 2009
***************
*** 11,16 ****
--- 11,22 ----
* Henrik Grubbström 1996-12-21
*/
+ /*
+ * Simple support for Stored procedures hacked in
+ *
+ * Justin Murdock, Genesis Communications 2008-12-22
+ */
+
/* Master Pike headerfile */
#include "global.h"
***************
*** 1701,1707 ****
MYSQL_DISALLOW();
! Pike_error("Mysql.mysql->list_processes(): Cannot list databases: %s\n",
err);
}
{
--- 1707,1713 ----
MYSQL_DISALLOW();
! Pike_error("Mysql.mysql->list_processes(): Cannot list processes: %s\n",
err);
}
{
***************
*** 1845,1850 ****
--- 1851,1975 ----
push_int (res);
}
+ #ifdef CLIENT_MULTI_RESULTS
+
+ static void f_more_results (INT32 args)
+ /* Helper function to detect if a string can be sent in the latin1
+ * encoding. */
+ {
+ MYSQL *socket = PIKE_MYSQL->socket;
+ int res;
+
+ if (args != 0)
+ SIMPLE_WRONG_NUM_ARGS_ERROR ("more_results", 1);
+
+ socket = PIKE_MYSQL->socket;
+
+ MYSQL_ALLOW();
+
+ res = mysql_more_results(socket);
+
+ MYSQL_DISALLOW();
+
+ push_int (res);
+ }
+
+ static int try_next_result (MYSQL **socket, MYSQL_RES **result) {
+ int ret = 0;
+
+ if (*socket) {
+ MYSQL_ALLOW();
+
+ ret = mysql_next_result(*socket);
+
+ switch (ret) {
+ case 0:
+ *result = mysql_store_result(*socket);
+ break;
+
+ #ifdef CR_UNDEFINED_ERROR
+ case CR_UNDEFINED_ERROR:
+ #endif
+ #ifdef CR_SERVER_GONE_ERROR
+ case CR_SERVER_GONE_ERROR:
+ #else
+ default:
+ #endif
+ *socket = NULL;
+ break;
+ }
+ MYSQL_DISALLOW();
+ }
+ return ret;
+ }
+
+
+ static void f_next_result (INT32 args)
+ /* Helper function to detect if a string can be sent in the latin1
+ * encoding. */
+ {
+ MYSQL *socket = PIKE_MYSQL->socket;
+ int ret = 0;
+ MYSQL_RES *result = NULL;
+ struct precompiled_mysql_result *res;
+ struct object *o;
+
+ if (args != 0)
+ SIMPLE_WRONG_NUM_ARGS_ERROR ("next_result", 1);
+
+ pop_n_elems(args); /* don't think this is needed */
+
+ socket = PIKE_MYSQL->socket;
+
+ if (socket) {
+ ret = try_next_result(&socket, &result);
+ }
+ if (!socket) {
+ /* I think this is unlikely to work if the connection failed
+ * but I don't see any harm in trying.
+ */
+ pike_mysql_reconnect (1);
+
+ socket = PIKE_MYSQL->socket;
+
+ ret = try_next_result(&socket, &result);
+ }
+ switch (ret) {
+ case 0:
+ /* Create the object */
+ ref_push_object(Pike_fp->current_object);
+ push_object(o = clone_object(mysql_result_program, 1));
+
+ /* Set the result. */
+ if ((!(res = (struct precompiled_mysql_result *)
+ get_storage(o, mysql_result_program))) || res->result) {
+ mysql_free_result(result);
+ Pike_error("big_query(): Bad mysql result object!\n");
+ }
+ res->result = result;
+
+ break;
+
+ case -1:
+ /* that was the last result set */
+
+ push_int(ret);
+
+ break;
+ #ifdef CR_UNKNOWN_ERROR
+ case CR_UNKNOWN_ERROR:
+ #endif
+ default:
+ /* unknown error */
+
+ pop_stack();
+ push_int(ret);
+ }
+
+ }
+ #endif /*def CLIENT_MULTI_RESULTS*/
+
+
/*! @endclass
*/
***************
*** 1933,1938 ****
--- 2058,2070 ----
ADD_FUNCTION ("_can_send_as_latin1", f__can_send_as_latin1,
tFunc(tStr,tInt01), ID_STATIC);
+ #ifdef CLIENT_MULTI_RESULTS
+ /* function(void:int) */
+ ADD_FUNCTION("more_results", f_more_results,tFunc(tVoid,tInt), ID_PUBLIC);
+ /* function(void:int|object) */
+ ADD_FUNCTION("next_result", f_next_result,tFunc(tVoid,tOr(tInt,tObj)),
ID_PUBLIC);
+ #endif
+
add_integer_constant( "CLIENT_COMPRESS", CLIENT_COMPRESS, 0);
add_integer_constant( "CLIENT_FOUND_ROWS", CLIENT_FOUND_ROWS, 0);
add_integer_constant( "CLIENT_IGNORE_SPACE", CLIENT_IGNORE_SPACE, 0);
***************
*** 1948,1953 ****
--- 2080,2089 ----
#ifdef HAVE_MYSQL_FIELD_CHARSETNR
add_integer_constant ("HAVE_MYSQL_FIELD_CHARSETNR", 1, 0);
+ #endif
+
+ #ifdef CLIENT_MULTI_RESULTS
+ add_integer_constant ("CLIENT_MULTI_RESULTS", CLIENT_MULTI_RESULTS, 0);
#endif
set_init_callback(init_mysql_struct);
|