From 664ebfa4990171891f84b18ee1a50f734948d80f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 12 Jul 2005 02:40:59 +0000 Subject: [PATCH] expand oracle null handling compatability by offering the ability to convert 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 | 6 +++++- ext/pdo/pdo_dbh.c | 4 ++-- ext/pdo/pdo_stmt.c | 9 ++++++++- ext/pdo/php_pdo_driver.h | 15 +++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index ddb9d871ce..616612c87b 100755 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -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); diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 336d620e70..1130bb1b4a 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -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); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 830e052542..131c31c8a2 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -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) { diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 0f0b115ac1..3f72f1dd0d 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -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; -- 2.50.1