]> granicus.if.org Git - php/commitdiff
Fixed memory corruption (wrong order of operations of stored prep. stmt).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 20 Jul 2005 04:30:14 +0000 (04:30 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 20 Jul 2005 04:30:14 +0000 (04:30 +0000)
Optimize the max length calculation process.

ext/pdo_mysql/mysql_statement.c

index 5680e0998110c2af0f8a22b1c133599783a04338..43587345a958f6cce900a1ac61aa0cea5ec3916d 100755 (executable)
@@ -91,19 +91,12 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
                        return 0;
                }
 
-               /* if buffered, pre-fetch all the data */
-               if (H->buffered) {
-                       if (S->max_length == 1 && !S->result) {
-                               my_bool on = 1;
-                               mysql_stmt_attr_set(S->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &on);
-                       }
-                       mysql_stmt_store_result(S->stmt);
-               }
-
                if (!S->result) {
                        /* figure out the result set format, if any */
                        S->result = mysql_stmt_result_metadata(S->stmt);
                        if (S->result) {
+                               int calc_max_length = H->buffered && S->max_length == 1;
+                       
                                S->fields = mysql_fetch_fields(S->result);
 
                                if (S->bound_result) {
@@ -123,6 +116,11 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
 
                                /* summon memory to hold the row */
                                for (i = 0; i < stmt->column_count; i++) {
+                                       if (calc_max_length && S->fields[i].type == FIELD_TYPE_BLOB) {
+                                               my_bool on = 1;
+                                               mysql_stmt_attr_set(S->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &on);
+                                               calc_max_length = 0;
+                                       }
                                        S->bound_result[i].buffer_length =
                                                S->fields[i].max_length? S->fields[i].max_length:
                                                S->fields[i].length;
@@ -136,6 +134,11 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
                                        pdo_mysql_error_stmt(stmt);
                                        return 0;
                                }
+
+                               /* if buffered, pre-fetch all the data */
+                               if (H->buffered) {
+                                       mysql_stmt_store_result(S->stmt);
+                               }
                        }
                }