]> granicus.if.org Git - php/commitdiff
improve handling of bound input parameters when no maximal length value is set;
authorWez Furlong <wez@php.net>
Tue, 12 Jul 2005 02:43:39 +0000 (02:43 +0000)
committerWez Furlong <wez@php.net>
Tue, 12 Jul 2005 02:43:39 +0000 (02:43 +0000)
default to 4000 as the maximal length, which is the biggest size possible
without using a LONG type (if you specify anything larger than this, you'll end
up with ORA-1461).

Don't assume that all parameters were output parameters after execution, as
this would clobber the input values when used in a loop.

ext/pdo_oci/oci_statement.c
ext/pdo_oci/php_pdo_oci_int.h

index 6f775313f61684e3fdadd12335844888a5b33f39..10a4d2f32508a27e396c67c1ea932ac1935abb54 100755 (executable)
@@ -97,6 +97,8 @@ static int oci_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
        }
        efree(S);
 
+       stmt->driver_data = NULL;
+
        return 1;
 } /* }}} */
 
@@ -203,6 +205,7 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d
 
        Z_STRLEN_P(param->parameter) = param->max_value_len;
        Z_STRVAL_P(param->parameter) = emalloc(Z_STRLEN_P(param->parameter)+1);
+       P->used_for_output = 1;
 
        P->actual_len = Z_STRLEN_P(param->parameter);   
        *alenpp = &P->actual_len;
@@ -246,9 +249,10 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
                                        case PDO_PARAM_STR:
                                        default:
                                                P->oci_type = SQLT_CHR;
-                                               convert_to_string(param->parameter);
                                                value_sz = param->max_value_len + 1;
-                                               P->actual_len = Z_STRLEN_P(param->parameter);
+                                               if (param->max_value_len == 0) {
+                                                       value_sz = 4000; /* maximum size before value is interpreted as a LONG value */
+                                               }
                                                
                                }
                                
@@ -275,30 +279,33 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
 
                        case PDO_PARAM_EVT_EXEC_PRE:
                                P->indicator = 0;
+                               P->used_for_output = 0;
                                return 1;
 
                        case PDO_PARAM_EVT_EXEC_POST:
                                /* fixup stuff set in motion in oci_bind_output_cb */
-                               if (P->indicator == -1) {
-                                       /* set up a NULL value */
-                                       if (Z_TYPE_P(param->parameter) == IS_STRING
+                               if (P->used_for_output) {
+                                       if (P->indicator == -1) {
+                                               /* set up a NULL value */
+                                               if (Z_TYPE_P(param->parameter) == IS_STRING
 #if ZEND_EXTENSION_API_NO < 220040718
                                                                && Z_STRVAL_P(param->parameter) != empty_string
 #endif
-                                                       ) {
-                                               /* OCI likes to stick non-terminated strings in things */
-                                               *Z_STRVAL_P(param->parameter) = '\0';
-                                       }
-                                       zval_dtor(param->parameter);
-                                       ZVAL_NULL(param->parameter);
-                               } else if (Z_TYPE_P(param->parameter) == IS_STRING
+                                                  ) {
+                                                       /* OCI likes to stick non-terminated strings in things */
+                                                       *Z_STRVAL_P(param->parameter) = '\0';
+                                               }
+                                               zval_dtor(param->parameter);
+                                               ZVAL_NULL(param->parameter);
+                                       } else if (Z_TYPE_P(param->parameter) == IS_STRING
 #if ZEND_EXTENSION_API_NO < 220040718
                                                        && Z_STRVAL_P(param->parameter) != empty_string
 #endif
-                                               ) {
-                                       Z_STRLEN_P(param->parameter) = P->actual_len;
-                                       Z_STRVAL_P(param->parameter) = erealloc(Z_STRVAL_P(param->parameter), P->actual_len+1);
-                                       Z_STRVAL_P(param->parameter)[P->actual_len] = '\0';
+                                                       ) {
+                                               Z_STRLEN_P(param->parameter) = P->actual_len;
+                                               Z_STRVAL_P(param->parameter) = erealloc(Z_STRVAL_P(param->parameter), P->actual_len+1);
+                                               Z_STRVAL_P(param->parameter)[P->actual_len] = '\0';
+                                       }
                                }
 
                                return 1;
index 2ebd4f22261082f4020aeae5e2c18d150ef0e223..a28d466eacdd2726eed5ee1088039a66f78af12b 100755 (executable)
@@ -75,6 +75,8 @@ typedef struct {
        ub4                     actual_len;
 
        dvoid           *thing; /* for LOBS, REFCURSORS etc. */
+
+       unsigned used_for_output;
 } pdo_oci_bound_param;
 
 extern const ub4 PDO_OCI_INIT_MODE;