]> granicus.if.org Git - php/commitdiff
expand oracle null handling compatability by offering the ability to convert
authorWez Furlong <wez@php.net>
Tue, 12 Jul 2005 02:40:59 +0000 (02:40 +0000)
committerWez Furlong <wez@php.net>
Tue, 12 Jul 2005 02:40:59 +0000 (02:40 +0000)
NULLs into empty strings as well as the other way around.  It still doesn't
help a great deal in the long run, but at least the option is there.

Make sure hash tables are nulled out to avoid double freeing them.

ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h

index ddb9d871ce5dbf3f41a58e556bc8f1153c4d7547..616612c87bca9bb4cdd575ba6e179a26283e793d 100755 (executable)
@@ -346,7 +346,11 @@ PHP_MINIT_FUNCTION(pdo)
        REGISTER_LONG_CONSTANT("PDO_CASE_NATURAL",      (long)PDO_CASE_NATURAL,         CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_CASE_LOWER",        (long)PDO_CASE_LOWER,           CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_CASE_UPPER",        (long)PDO_CASE_UPPER,           CONST_CS|CONST_PERSISTENT);
-               
+
+       REGISTER_LONG_CONSTANT("PDO_NULL_NATURAL",      (long)PDO_NULL_NATURAL,         CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PDO_NULL_EMPTY_STRING", (long)PDO_NULL_EMPTY_STRING,            CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PDO_NULL_TO_STRING",    (long)PDO_NULL_TO_STRING,               CONST_CS|CONST_PERSISTENT);
+                       
        REGISTER_STRING_CONSTANT("PDO_ERR_NONE",        PDO_ERR_NONE,           CONST_CS|CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("PDO_FETCH_ORI_NEXT", (long)PDO_FETCH_ORI_NEXT, CONST_CS|CONST_PERSISTENT);
index 336d620e704c9d89e50adb3c88af9ba867f21df0..1130bb1b4a564f00a3ddfd0398d2e1257028120b 100755 (executable)
@@ -691,7 +691,7 @@ static PHP_METHOD(PDO, setAttribute)
 
                case PDO_ATTR_ORACLE_NULLS:
                        convert_to_long(value);
-                       dbh->oracle_nulls = Z_LVAL_P(value) ? 1 : 0;
+                       dbh->oracle_nulls = Z_LVAL_P(value);
                        RETURN_TRUE;
 
                case PDO_ATTR_STRINGIFY_FETCHES:
@@ -746,7 +746,7 @@ static PHP_METHOD(PDO, getAttribute)
                        RETURN_LONG(dbh->desired_case);
 
                case PDO_ATTR_ORACLE_NULLS:
-                       RETURN_BOOL(dbh->oracle_nulls);
+                       RETURN_LONG(dbh->oracle_nulls);
 
                case PDO_ATTR_ERRMODE:
                        RETURN_LONG(dbh->error_mode);
index 830e0525424ad5e4a2239fa4f6348a4ed9255143..131c31c8a29b6fc3aeaa8cff106a72eee366e240 100755 (executable)
@@ -476,7 +476,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno TSRMLS_DC
                        break;
                
                case PDO_PARAM_STR:
-                       if (value && !(value_len == 0 && stmt->dbh->oracle_nulls)) {
+                       if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) {
                                ZVAL_STRINGL(dest, value, value_len, !caller_frees);
                                if (caller_frees) {
                                        caller_frees = 0;
@@ -499,6 +499,10 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno TSRMLS_DC
                                break;
                }
        }
+
+       if (Z_TYPE_P(dest) == IS_NULL && stmt->dbh->oracle_nulls == PDO_NULL_TO_STRING) {
+               ZVAL_EMPTY_STRING(dest);
+       }
 }
 /* }}} */
 
@@ -1898,14 +1902,17 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
        if (stmt->bound_params) {
                zend_hash_destroy(stmt->bound_params);
                FREE_HASHTABLE(stmt->bound_params);
+               stmt->bound_params = NULL;
        }
        if (stmt->bound_param_map) {
                zend_hash_destroy(stmt->bound_param_map);
                FREE_HASHTABLE(stmt->bound_param_map);
+               stmt->bound_param_map = NULL;
        }
        if (stmt->bound_columns) {
                zend_hash_destroy(stmt->bound_columns);
                FREE_HASHTABLE(stmt->bound_columns);
+               stmt->bound_columns = NULL;
        }
 
        if (stmt->methods && stmt->methods->dtor) {
index 0f0b115ac1a8c705c2e48a1bc26d401044f9f8b7..3f72f1dd0def25d0ba7df6a2cedb68781ef3167c 100755 (executable)
@@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
 # define FALSE 0
 #endif
 
-#define PDO_DRIVER_API 20050709
+#define PDO_DRIVER_API 20050711
 
 enum pdo_param_type {
        PDO_PARAM_NULL,
@@ -174,6 +174,13 @@ enum pdo_case_conversion {
        PDO_CASE_LOWER
 };
 
+/* oracle interop settings */
+enum pdo_null_handling {
+       PDO_NULL_NATURAL = 0,
+       PDO_NULL_EMPTY_STRING = 1,
+       PDO_NULL_TO_STRING = 2,
+};
+
 /* {{{ utils for reading attributes set as driver_options */
 static inline long pdo_attr_lval(zval *options, enum pdo_fetch_type option_name, long defval TSRMLS_DC)
 {
@@ -437,15 +444,15 @@ struct _pdo_dbh_t {
        /* max length a single character can become after correct quoting */
        unsigned max_escaped_char_length:3;
 
-       /* when set, convert empty strings to NULL */
-       unsigned oracle_nulls:1;
+       /* oracle compat; see enum pdo_null_handling */
+       unsigned oracle_nulls:2;
 
        /* when set, convert int/floats to strings */
        unsigned stringify:1;
 
        /* the sum of the number of bits here and the bit fields preceeding should
         * equal 32 */
-       unsigned _reserved_flags:22;
+       unsigned _reserved_flags:21;
 
        /* data source string used to open this handle */
        const char *data_source;