]> granicus.if.org Git - php/commitdiff
Fixed bug with stmt_close (libmysql bk version 1.1477 required)
authorGeorg Richter <georg@php.net>
Sat, 22 Feb 2003 07:31:01 +0000 (07:31 +0000)
committerGeorg Richter <georg@php.net>
Sat, 22 Feb 2003 07:31:01 +0000 (07:31 +0000)
Fixed bug with mysql_execute and float values

ext/mysqli/mysqli.c
ext/mysqli/mysqli_api.c
ext/mysqli/php_mysqli.h

index 0fbe0f514e0eb13d92f843b7c6cbc3ddc9c3083e..361132784d9fa3aa5cbfb3f6820fbd60c8600caf 100644 (file)
@@ -1,8 +1,8 @@
 /*
   +----------------------------------------------------------------------+
-  | PHP Version 4                                                        |
+  | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2002 The PHP Group                                |
+  | Copyright (c) 1997-2003 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -43,11 +43,9 @@ void php_clear_stmt_bind(STMT *stmt)
 {
        unsigned int i;
 
-       /* 
-        * we don't need to call mysql_stmt_close here.
-        * in case mysqli_stmt_close wasn't called, all
-        * statements will be freed via mysql_close
-        */
+       if (stmt->stmt) {
+               mysql_stmt_close(stmt->stmt);
+       }
 
        if (stmt->var_cnt) {
                for (i = 0; i < stmt->var_cnt; i++) {
@@ -361,10 +359,11 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
 
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result"); 
 
-       array_init(return_value);
-
        fields = mysql_fetch_fields(result);
-       row = mysql_fetch_row(result);
+       if (!(row = mysql_fetch_row(result))) {
+               RETURN_FALSE;
+       }
+       array_init(return_value);
        field_len = mysql_fetch_lengths(result);
 
        for (i = 0; i < mysql_num_fields(result); i++) {
index 2f2088454d665e8cbc23b0a4e026472d3871224c..56c4056828ee628a079883fec9cbcbc9617252aa 100644 (file)
@@ -1,8 +1,8 @@
 /*
   +----------------------------------------------------------------------+
-  | PHP Version 4                                                        |
+  | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2002 The PHP Group                                |
+  | Copyright (c) 1997-2003 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -385,14 +385,6 @@ PHP_FUNCTION(mysqli_close)
 
        MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link"); 
 
-       /*
-        * Don't free initial struct if there exist 
-        * non closed statements
-        */
-       if (mysql->stmts) {
-               mysql->free_me = 0;
-       }
-
        mysql_close(mysql);
        MYSQLI_CLEAR_RESOURCE(&mysql_link);     
        RETURN_TRUE;
@@ -594,7 +586,7 @@ PHP_FUNCTION(mysqli_execute)
                                                stmt->stmt->params[i].buffer = Z_STRVAL_PP(&stmt->vars[i]);
                                                stmt->stmt->params[i].buffer_length = strlen(Z_STRVAL_PP(&stmt->vars[i]));
                                                break;
-                                       case MYSQL_TYPE_FLOAT:
+                                       case MYSQL_TYPE_DOUBLE:
                                                convert_to_double_ex(&stmt->vars[i]);
                                                stmt->stmt->params[i].buffer = (gptr)&Z_LVAL_PP(&stmt->vars[i]);
                                                break;
@@ -663,8 +655,13 @@ PHP_FUNCTION(mysqli_fetch)
                                                                ZVAL_LONG(stmt->vars[i], lval);
                                                        }
                                                } else {
-                                                       stmt->bind[i].type = IS_STRING;
-                                                       ZVAL_STRING(stmt->vars[i], stmt->bind[i].buffer, 1);
+                                                       if (stmt->vars[i]->type == IS_STRING) {
+                                                               efree(stmt->vars[i]->value.str.val);
+                                                       } 
+                                                       ZVAL_STRING(stmt->vars[i], stmt->bind[i].buffer, 1); 
+                                                       /*      
+                                                       stmt->vars[i]->value.str.len = strlen(stmt->bind[i].buffer);
+                                                       stmt->vars[i]->value.str.val = stmt->bind[i].buffer; */
                                                }
                                                break;
                                        default:
@@ -1530,6 +1527,7 @@ PHP_FUNCTION(mysqli_stmt_close)
        }
        MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt"); 
        mysql_stmt_close(stmt->stmt);
+       stmt->stmt = NULL;
        php_clear_stmt_bind(stmt); 
        MYSQLI_CLEAR_RESOURCE(&mysql_stmt);
        RETURN_TRUE;
index fb34f8f5fd3fea9675e008ee1939a65867ead445..be3c67d439798a58eae23c621d1bf0dad1aab982 100644 (file)
@@ -1,8 +1,8 @@
 /*
   +----------------------------------------------------------------------+
-  | PHP Version 4                                                        |
+  | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2002 The PHP Group                                |
+  | Copyright (c) 1997-2003 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -113,7 +113,13 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
                php_error(E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
                RETURN_NULL();\
        }\
-}
+       if (!strcmp((char *)__name, "mysqli_stmt")) {\
+               if (!((STMT *)__ptr)->stmt->mysql) {\
+                       php_error(E_WARNING, "Statement isn't valid anymore");\
+                       RETURN_NULL();\
+               }\
+       }\
+} 
 
 #define MYSQLI_CLEAR_RESOURCE(__id) \
 { \