mboeren         Wed Apr 11 01:14:57 2001 EDT

  Modified files:              
    /php4/ext/dbx       dbx.c dbx_mysql.c dbx_mysql.h dbx_odbc.c dbx_odbc.h 
                        dbx_pgsql.c dbx_pgsql.h php_dbx.h 
  Log:
  Added a database member to the dbx_link object. Since e.g. mysql reuses
  connections, two or more dbx_link objects may share the connection 
  identifier. The database name is used in the dbx_query, where it calls
  mysql_db_query instead of mysql_query.
  This means the database name has to be passed around to all dbx_xxx_query
  functions, hence the update on all the files. (Mc)
  # Thanks to Christian Rabe for all the input on this issue!
  
  
Index: php4/ext/dbx/dbx.c
diff -u php4/ext/dbx/dbx.c:1.8 php4/ext/dbx/dbx.c:1.9
--- php4/ext/dbx/dbx.c:1.8      Mon Apr  9 04:53:39 2001
+++ php4/ext/dbx/dbx.c  Wed Apr 11 01:14:57 2001
@@ -51,9 +51,11 @@
     return DBX_UNKNOWN;
     }
 
-int split_dbx_handle_object(zval ** dbx_object, zval *** pdbx_handle, zval *** 
pdbx_module) {
+int split_dbx_handle_object(zval ** dbx_object, zval *** pdbx_handle, zval *** 
+pdbx_module, zval *** pdbx_database) {
     convert_to_object_ex(dbx_object);
-    if (zend_hash_find((*dbx_object)->value.obj.properties, "handle", 7, (void **) 
pdbx_handle)==FAILURE || zend_hash_find((*dbx_object)->value.obj.properties, "module", 
7, (void **) pdbx_module)==FAILURE) {
+    if (zend_hash_find((*dbx_object)->value.obj.properties, "handle", 7, (void **) 
+pdbx_handle)==FAILURE
+    || zend_hash_find((*dbx_object)->value.obj.properties, "module", 7, (void **) 
+pdbx_module)==FAILURE
+    || zend_hash_find((*dbx_object)->value.obj.properties, "database", 9, (void **) 
+pdbx_database)==FAILURE) {
         return 0;
         }
     return 1;
@@ -85,7 +87,7 @@
     /*/ returns persistent connection handle as resource on success or 0 as long on 
failure /*/
 int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, 
zval ** dbx_module);
     /*/ returns 1 as long on success or 0 as long on failure /*/
-int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module);
+int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module);
     /*/ returns 1 as long or result identifier as resource on success or 0 as long on 
failure /*/
 int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, 
INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module);
     /*/ returns column-count as long on success or 0 as long on failure /*/
@@ -97,26 +99,7 @@
     /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure 
/*/
 int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, 
zval ** dbx_module);
     /*/ returns string /*/
-/*
-#ifdef ZTS
-int dbx_globals_id;
-#else
-ZEND_DBX_API zend_dbx_globals dbx_globals;
-#endif
-*/
-/* If you declare any globals in php_dbx.h uncomment this: */
-/* ZEND_DECLARE_MODULE_GLOBALS(dbx) */
-/* True global resources - no need for thread safety here */
-/*
-static int le_dbx;
-*/
-/*
-static void zend_dbx_init_globals(PGLS_D)
-{
-       DBXG(row_count) = 0;
-       DBXG(num_rows) = 0;
-}
-*/
+
 /* Every user visible function must have an entry in dbx_functions[].
 */
 function_entry dbx_functions[] = {
@@ -129,8 +112,6 @@
     ZEND_FE(dbx_cmp_asc,    NULL)
     ZEND_FE(dbx_cmp_desc,    NULL)
 
-    ZEND_FE(dbx_test,      NULL)
-
        {NULL, NULL, NULL}      /* Must be the last line in dbx_functions[] */
     };
 
@@ -149,19 +130,8 @@
 ZEND_GET_MODULE(dbx)
 #endif
 
-/*/ZEND_INI_BEGIN()
-/ /    ZEND_INI_ENTRY("dbx.defaulttype", "mysql", ZEND_INI_SYSTEM, NULL)
-/ /ZEND_INI_END()
-/*/
 ZEND_MINIT_FUNCTION(dbx)
 {
-/*
-#ifdef ZTS
-       dbx_globals_id = ts_allocate_id(sizeof(zend_dbx_globals), (ts_allocate_ctor) 
zend_dbx_init_globals, NULL);
-#else
-       zend_dbx_init_globals(DBXLS_C);
-#endif
-*/
 /*/    REGISTER_INI_ENTRIES(); /*/
 
     REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | 
CONST_PERSISTENT);
@@ -218,6 +188,7 @@
     int result;
     long module_identifier;
     zval * dbx_module;
+    zval * db_name;
     zval * rv_dbx_handle;
     int persistent=0;
 
@@ -248,6 +219,8 @@
     convert_to_string_ex(arguments[2]);
     convert_to_string_ex(arguments[3]);
     convert_to_string_ex(arguments[4]);
+    MAKE_STD_ZVAL(db_name); 
+    ZVAL_STRING(db_name, (*arguments[2])->value.str.val, 1);
     if (persistent) {
         result = switch_dbx_pconnect(&rv_dbx_handle, arguments[1], arguments[2], 
arguments[3], arguments[4], INTERNAL_FUNCTION_PARAM_PASSTHRU, &dbx_module);
         }
@@ -256,6 +229,7 @@
         }
     if (!result) {
         FREE_ZVAL(dbx_module);
+        FREE_ZVAL(db_name);
         FREE_ZVAL(rv_dbx_handle);
         RETURN_LONG(0);
         }
@@ -263,12 +237,14 @@
     if (object_init(return_value) != SUCCESS) {
         zend_error(E_ERROR, "dbx: unable to create resulting object...");
         FREE_ZVAL(dbx_module);
+        FREE_ZVAL(db_name);
         FREE_ZVAL(rv_dbx_handle);
         RETURN_LONG(0);
         }
 
     zend_hash_update(return_value->value.obj.properties, "handle", 7, (void 
*)&(rv_dbx_handle), sizeof(zval *), NULL);
     zend_hash_update(return_value->value.obj.properties, "module", 7, (void 
*)&(dbx_module), sizeof(zval *), NULL);
+    zend_hash_update(return_value->value.obj.properties, "database", 9, (void 
+*)&(db_name), sizeof(zval *), NULL);
 }
 /* }}} */
 
@@ -282,12 +258,13 @@
     int result;
     zval ** dbx_handle;
     zval ** dbx_module;
+    zval ** dbx_database;
     zval * rv_success;
 
     if (ZEND_NUM_ARGS() !=number_of_arguments || 
zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
                WRONG_PARAM_COUNT;
            }
-    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module)) {
+    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, 
+&dbx_database)) {
         zend_error(E_WARNING, "dbx_close: not a valid dbx_handle-object...");
         RETURN_LONG(0);
         }
@@ -319,27 +296,24 @@
     int result;
     zval ** dbx_handle;
     zval ** dbx_module;
+    zval ** dbx_database;
     zval * rv_result_handle;
     zval * rv_column_count;
     long col_index;
     long row_count;
     zval * info;
     long info_flags;
-/*/    long result_row_offset; /*/
-/*/    long result_row_count; /*/
     zval * data;
 
     if (ZEND_NUM_ARGS()<min_number_of_arguments || 
ZEND_NUM_ARGS()>number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), 
arguments) == FAILURE) {
                WRONG_PARAM_COUNT;
            }
-    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module)) {
+    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, 
+&dbx_database)) {
         zend_error(E_WARNING, "dbx_query: not a valid dbx_handle-object...");
         RETURN_LONG(0);
         }
     /*/ default values /*/
     info_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
-/*/    result_row_offset = 0; /*/
-/*/    result_row_count = -1; /*/
     /*/ parameter overrides /*/
     if (ZEND_NUM_ARGS()>2) {
         convert_to_long_ex(arguments[2]);
@@ -349,20 +323,10 @@
             info_flags |= DBX_RESULT_INFO;
             }
         }
- /*/
-/ /    if (ZEND_NUM_ARGS()>3) {
-/ /        convert_to_long_ex(arguments[3]);
-/ /        result_row_offset = (*arguments[3])->value.lval;
-/ /        }
-/ /    if (ZEND_NUM_ARGS()>4) {
-/ /        convert_to_long_ex(arguments[4]);
-/ /        result_row_count = (*arguments[4])->value.lval;
-/ /        }
- /*/
     MAKE_STD_ZVAL(rv_result_handle); 
     ZVAL_LONG(rv_result_handle, 0);
     convert_to_string_ex(arguments[1]);
-    result = switch_dbx_query(&rv_result_handle, dbx_handle, arguments[1], 
INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
+    result = switch_dbx_query(&rv_result_handle, dbx_handle, dbx_database, 
+arguments[1], INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
     /*/ boolean return value means either failure for any query or success for 
queries that don't return anything  /*/
     if (!result || (rv_result_handle && rv_result_handle->type==IS_BOOL)) {
         result = (result && rv_result_handle->value.lval)?1:0;
@@ -463,7 +427,6 @@
         ZVAL_LONG(rv_row, 0);
         result = switch_dbx_getrow(&rv_row, &rv_result_handle, row_count, 
INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
         if (result) {
-/*/            if (row_count>=result_row_offset && (result_row_count==-1 || 
row_count<result_row_offset+result_row_count)) { /*/
                 zval ** row_ptr;
                 zend_hash_index_update(data->value.ht, row_count, (void *)&(rv_row), 
sizeof(zval *), (void **) &row_ptr);
                 /*/ associate results with fieldnames /*/
@@ -480,12 +443,6 @@
                         zend_assign_to_variable_reference(NULL, reference_ptr, 
actual_ptr, NULL ELS_CC);
                         }
                     }
- /*/
-/ /                }
-/ /            else {
-/ /                FREE_ZVAL(rv_row);
-/ /                }
- /*/
             ++row_count;
             }
         else {
@@ -508,12 +465,13 @@
     int result;
     zval ** dbx_handle;
     zval ** dbx_module;
+    zval ** dbx_database;
     zval * rv_errormsg;
 
     if (ZEND_NUM_ARGS() !=number_of_arguments || 
zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
                WRONG_PARAM_COUNT;
            }
-    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module)) {
+    if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, 
+&dbx_database)) {
         zend_error(E_WARNING, "dbx_error: not a valid dbx_handle-object...");
         RETURN_LONG(0);
         }
@@ -528,6 +486,7 @@
     MOVE_RETURNED_TO_RV(&return_value, rv_errormsg);
 }
 /* }}} */
+
 /*/
 / /       dbx functions that are database independent... like sorting result_objects!
 /*/
@@ -685,18 +644,6 @@
 
 /***********************************/
 
-/* {{{ proto long dbx_test(???)
-   */
-ZEND_FUNCTION(dbx_test)
-{
-}
-/* }}} */
-
-
-
-
-
-
 /*/
 / / switch_dbx functions
 /*/
@@ -733,12 +680,12 @@
     return 0;
     }
 
-int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) {
+int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) {
     /*/ returns 1 as long or result identifier as resource on success or 0 as long on 
failure /*/
     switch ((*dbx_module)->value.lval) {
-        case DBX_MYSQL: return dbx_mysql_query(rv, dbx_handle, sql_statement, 
INTERNAL_FUNCTION_PARAM_PASSTHRU);        
-        case DBX_ODBC: return dbx_odbc_query(rv, dbx_handle, sql_statement, 
INTERNAL_FUNCTION_PARAM_PASSTHRU);        
-        case DBX_PGSQL: return dbx_pgsql_query(rv, dbx_handle, sql_statement, 
INTERNAL_FUNCTION_PARAM_PASSTHRU);        
+        case DBX_MYSQL: return dbx_mysql_query(rv, dbx_handle, db_name, 
+sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);        
+        case DBX_ODBC: return dbx_odbc_query(rv, dbx_handle, db_name, sql_statement, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);        
+        case DBX_PGSQL: return dbx_pgsql_query(rv, dbx_handle, db_name, 
+sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);        
         }
     zend_error(E_WARNING, "dbx_query: not supported in this module");
     return 0;
Index: php4/ext/dbx/dbx_mysql.c
diff -u php4/ext/dbx/dbx_mysql.c:1.4 php4/ext/dbx/dbx_mysql.c:1.5
--- php4/ext/dbx/dbx_mysql.c:1.4        Fri Mar 23 06:50:17 2001
+++ php4/ext/dbx/dbx_mysql.c    Wed Apr 11 01:14:57 2001
@@ -94,15 +94,16 @@
     return 1;
     }
 
-int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS) {
+int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS) {
     /*/ returns 1 as long or a result identifier as resource on success  or 0 as long 
on failure /*/
-    int number_of_arguments=2;
-    zval ** arguments[2];
+    int number_of_arguments=3;
+    zval ** arguments[3];
     zval * returned_zval=NULL;
 
-    arguments[0]=sql_statement;
-    arguments[1]=dbx_handle;
-    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_query", 
&returned_zval, number_of_arguments, arguments);
+    arguments[0]=db_name;
+    arguments[1]=sql_statement;
+    arguments[2]=dbx_handle;
+    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_db_query", 
+&returned_zval, number_of_arguments, arguments);
     /*/ mysql_query returns a bool for success or failure, or a result_identifier for 
select statements /*/
     if (!returned_zval || (returned_zval->type!=IS_BOOL && 
returned_zval->type!=IS_RESOURCE)) {
         if (returned_zval) zval_ptr_dtor(&returned_zval);
Index: php4/ext/dbx/dbx_mysql.h
diff -u php4/ext/dbx/dbx_mysql.h:1.4 php4/ext/dbx/dbx_mysql.h:1.5
--- php4/ext/dbx/dbx_mysql.h:1.4        Fri Mar 23 06:50:17 2001
+++ php4/ext/dbx/dbx_mysql.h    Wed Apr 11 01:14:57 2001
@@ -35,7 +35,7 @@
     /*/ returns persistent connection handle as resource on success or 0 as long on 
failure /*/
 int dbx_mysql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long on success or 0 as long on failure /*/
-int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS);
+int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long or a result identifier as resource on success  or 0 as long 
on failure /*/
 int dbx_mysql_getcolumncount(zval ** rv, zval ** result_handle, 
INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns column-count as long on success or 0 as long on failure /*/
Index: php4/ext/dbx/dbx_odbc.c
diff -u php4/ext/dbx/dbx_odbc.c:1.5 php4/ext/dbx/dbx_odbc.c:1.6
--- php4/ext/dbx/dbx_odbc.c:1.5 Mon Apr  2 01:51:35 2001
+++ php4/ext/dbx/dbx_odbc.c     Wed Apr 11 01:14:57 2001
@@ -78,13 +78,14 @@
     return 1;
     }
 
-int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS) {
+int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS) {
     /*/ returns 1 as long or a result identifier as resource on success  or 0 as long 
on failure /*/
     int number_of_arguments=2;
     zval ** arguments[2];
     zval * queryresult_zval=NULL;
     zval * num_fields_zval=NULL;
 
+    // db_name is not used in this function
     arguments[0]=dbx_handle;
     arguments[1]=sql_statement;
     dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_exec", 
&queryresult_zval, number_of_arguments, arguments);
Index: php4/ext/dbx/dbx_odbc.h
diff -u php4/ext/dbx/dbx_odbc.h:1.4 php4/ext/dbx/dbx_odbc.h:1.5
--- php4/ext/dbx/dbx_odbc.h:1.4 Fri Mar 23 06:50:17 2001
+++ php4/ext/dbx/dbx_odbc.h     Wed Apr 11 01:14:57 2001
@@ -35,7 +35,7 @@
     /*/ returns persisten connection handle as resource on success or 0 as long on 
failure /*/
 int dbx_odbc_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long on success or 0 as long on failure /*/
-int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS);
+int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long or a result identifier as resource on success  or 0 as long 
on failure /*/
 int dbx_odbc_getcolumncount(zval ** rv, zval ** result_handle, 
INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns column-count as long on success or 0 as long on failure /*/
Index: php4/ext/dbx/dbx_pgsql.c
diff -u php4/ext/dbx/dbx_pgsql.c:1.4 php4/ext/dbx/dbx_pgsql.c:1.5
--- php4/ext/dbx/dbx_pgsql.c:1.4        Mon Apr  2 01:51:35 2001
+++ php4/ext/dbx/dbx_pgsql.c    Wed Apr 11 01:14:57 2001
@@ -138,13 +138,14 @@
     return 1;
 }
 
-int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS) {
+int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS) {
     /* returns 1 as long or a result identifier as resource on success  
           or 0 as long on failure */
     int nargs=2;
     zval **args[2];
     zval *returned_zval=NULL, *num_rows_zval=NULL;
 
+    // db_name is not used in this function
     args[0]=dbx_handle;
     args[1]=sql_statement;
     dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_exec", 
&returned_zval, nargs, args);
Index: php4/ext/dbx/dbx_pgsql.h
diff -u php4/ext/dbx/dbx_pgsql.h:1.3 php4/ext/dbx/dbx_pgsql.h:1.4
--- php4/ext/dbx/dbx_pgsql.h:1.3        Fri Mar 23 06:50:17 2001
+++ php4/ext/dbx/dbx_pgsql.h    Wed Apr 11 01:14:57 2001
@@ -31,7 +31,7 @@
     /*/ returns persistent connection handle as resource on success or 0 as long on 
failure /*/
 int dbx_pgsql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long on success or 0 as long on failure /*/
-int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** sql_statement, 
INTERNAL_FUNCTION_PARAMETERS);
+int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** 
+sql_statement, INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns 1 as long or a result identifier as resource on success  or 0 as long 
on failure /*/
 int dbx_pgsql_getcolumncount(zval ** rv, zval ** result_handle, 
INTERNAL_FUNCTION_PARAMETERS);
     /*/ returns column-count as long on success or 0 as long on failure /*/
Index: php4/ext/dbx/php_dbx.h
diff -u php4/ext/dbx/php_dbx.h:1.5 php4/ext/dbx/php_dbx.h:1.6
--- php4/ext/dbx/php_dbx.h:1.5  Fri Mar 23 06:50:17 2001
+++ php4/ext/dbx/php_dbx.h      Wed Apr 11 01:14:57 2001
@@ -52,18 +52,16 @@
 ZEND_FUNCTION(dbx_cmp_asc);
 ZEND_FUNCTION(dbx_cmp_desc);
 
-ZEND_FUNCTION(dbx_test);
-
 /* 
        Declare any global variables you may need between the BEGIN
        and END macros here:     
 */
+
 /*
 ZEND_BEGIN_MODULE_GLOBALS(dbx)
-        int row_count;
-        int num_rows;
 ZEND_END_MODULE_GLOBALS(dbx)
 */
+
 /* In every function that needs to use variables in php_dbx_globals,
    do call dbxLS_FETCH(); after declaring other variables used by
    that function, and always refer to them as dbxG(variable).

-- 
PHP CVS 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]

Reply via email to