zeev            Tue Mar 13 13:42:43 2001 EDT

  Modified files:              
    /php4/ext/mysql     php_mysql.c 
  Log:
  Centralize query code
  
  
Index: php4/ext/mysql/php_mysql.c
diff -u php4/ext/mysql/php_mysql.c:1.74 php4/ext/mysql/php_mysql.c:1.75
--- php4/ext/mysql/php_mysql.c:1.74     Tue Mar 13 13:13:19 2001
+++ php4/ext/mysql/php_mysql.c  Tue Mar 13 13:42:43 2001
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
  
-/* $Id: php_mysql.c,v 1.74 2001/03/13 21:13:19 zeev Exp $ */
+/* $Id: php_mysql.c,v 1.75 2001/03/13 21:42:43 zeev Exp $ */
 
 
 /* TODO:
@@ -102,6 +102,7 @@
 
 typedef struct _php_mysql_conn {
        MYSQL conn;
+       MYSQL_RES *active_result;
 } php_mysql_conn;
 
 
@@ -898,17 +899,61 @@
 /* }}} */
 
 
+
+
+static void php_mysql_do_query(zval **query, zval **mysql_link, int link_id, zval 
+**db, int use_store, zval *return_value)
+{
+       php_mysql_conn *mysql;
+       MYSQL_RES *mysql_result;
+       MySLS_FETCH();
+       
+       ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, link_id, 
+"MySQL-Link", le_link, le_plink);
+       
+       if (db) {
+               convert_to_string_ex(db);
+               if (mysql_select_db(&mysql->conn, (*db)->value.str.val)!=0) {
+                       RETURN_FALSE;
+               }
+       }
+       
+       convert_to_string_ex(query);
+       /* mysql_query is binary unsafe, use mysql_real_query */
+#if MYSQL_VERSION_ID > 32199 
+       if (mysql_real_query(&mysql->conn, (*query)->value.str.val, 
+(*query)->value.str.len)!=0) {
+               RETURN_FALSE;
+       }
+#else
+       if (mysql_query(&mysql->conn, (*query)->value.str.val)!=0) {
+               RETURN_FALSE;
+       }
+#endif
+       if(use_store == MYSQL_USE_RESULT) {
+               mysql_result=mysql_use_result(&mysql->conn);
+       } else {
+               mysql_result=mysql_store_result(&mysql->conn);
+       }
+       if (!mysql_result) {
+               if (PHP_MYSQL_VALID_RESULT(&mysql->conn)) { /* query should have 
+returned rows */
+                       php_error(E_WARNING, "MySQL:  Unable to save result set");
+                       RETURN_FALSE;
+               } else {
+                       RETURN_TRUE;
+               }
+       }
+       ZEND_REGISTER_RESOURCE(return_value, mysql_result, le_result);
+}
+
+
+
+
+
 /* {{{ proto int mysql_query(string query [, int link_identifier] [, int result_mode])
    Send an SQL query to MySQL */
 PHP_FUNCTION(mysql_query)
 {
        zval **query, **mysql_link;
-#if 0
        zval **store_result;
-#endif
        int id, use_store=MYSQL_STORE_RESULT;
-       php_mysql_conn *mysql;
-       MYSQL_RES *mysql_result;
        MySLS_FETCH();
        
        switch(ZEND_NUM_ARGS()) {
@@ -925,7 +970,6 @@
                        }
                        id = -1;
                        break;
-#if 0 /* need to work more on the mysql_store_result() approach */
            case 3:
                        if(zend_get_parameters_ex(3, &query, &mysql_link, 
&store_result)==FAILURE) {
                                RETURN_FALSE;
@@ -936,39 +980,11 @@
                        }
                        id = -1;
                        break;
-#endif
                default:
                        WRONG_PARAM_COUNT;
                        break;
-       }
-       
-       ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", 
le_link, le_plink);
-       
-       convert_to_string_ex(query);
-       /* mysql_query binary unsafe, use mysql_real_query */
-#if MYSQL_VERSION_ID > 32199 
-       if (mysql_real_query(&mysql->conn, (*query)->value.str.val, 
(*query)->value.str.len)!=0) {
-               RETURN_FALSE;
        }
-#else
-       if (mysql_query(&mysql->conn, (*query)->value.str.val)!=0) {
-               RETURN_FALSE;
-       }
-#endif
-       if(use_store == MYSQL_USE_RESULT) {
-               mysql_result=mysql_use_result(&mysql->conn);
-       } else {
-               mysql_result=mysql_store_result(&mysql->conn);
-       }
-       if (!mysql_result) {
-               if (PHP_MYSQL_VALID_RESULT(&mysql->conn)) { /* query should have 
returned rows */
-                       php_error(E_WARNING, "MySQL:  Unable to save result set");
-                       RETURN_FALSE;
-               } else {
-                       RETURN_TRUE;
-               }
-       }
-       ZEND_REGISTER_RESOURCE(return_value, mysql_result, le_result);
+       php_mysql_do_query(query, mysql_link, id, NULL, use_store, return_value);
 }
 /* }}} */
 
@@ -978,12 +994,8 @@
 PHP_FUNCTION(mysql_db_query)
 {
        zval **db, **query, **mysql_link;
-#if 0
        zval **store_result;
-#endif
        int id, use_store=MYSQL_STORE_RESULT;
-       php_mysql_conn *mysql;
-       MYSQL_RES *mysql_result;
        MySLS_FETCH();
        
        switch(ZEND_NUM_ARGS()) {
@@ -1000,7 +1012,6 @@
                        }
                        id = -1;
                        break;
-#if 0
            case 4:
                        if(zend_get_parameters_ex(4, &db, &query, &mysql_link, 
&store_result)==FAILURE) {
                                RETURN_FALSE;
@@ -1011,44 +1022,12 @@
                        }
                        id = -1;
                        break;
-#endif
                default:
                        WRONG_PARAM_COUNT;
                        break;
        }
-       
-       ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", 
le_link, le_plink);
        
-       convert_to_string_ex(db);
-       if (mysql_select_db(&mysql->conn, (*db)->value.str.val)!=0) {
-               RETURN_FALSE;
-       }
-       
-       convert_to_string_ex(query);
-       /* mysql_query is binary unsafe, use mysql_real_query */
-#if MYSQL_VERSION_ID > 32199 
-       if (mysql_real_query(&mysql->conn, (*query)->value.str.val, 
(*query)->value.str.len)!=0) {
-               RETURN_FALSE;
-       }
-#else
-       if (mysql_query(&mysql->conn, (*query)->value.str.val)!=0) {
-               RETURN_FALSE;
-       }
-#endif
-       if(use_store == MYSQL_USE_RESULT) {
-               mysql_result=mysql_use_result(&mysql->conn);
-       } else {
-               mysql_result=mysql_store_result(&mysql->conn);
-       }
-       if (!mysql_result) {
-               if (PHP_MYSQL_VALID_RESULT(&mysql->conn)) { /* query should have 
returned rows */
-                       php_error(E_WARNING, "MySQL:  Unable to save result set");
-                       RETURN_FALSE;
-               } else {
-                       RETURN_TRUE;
-               }
-       }
-       ZEND_REGISTER_RESOURCE(return_value, mysql_result, le_result);
+       php_mysql_do_query(query, mysql_link, id, db, use_store, return_value);
 }
 /* }}} */
 



-- 
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