]> granicus.if.org Git - php/commitdiff
Implement empty-string-to-null conversion option for oracle compat.
authorWez Furlong <wez@php.net>
Mon, 19 Jul 2004 09:35:36 +0000 (09:35 +0000)
committerWez Furlong <wez@php.net>
Mon, 19 Jul 2004 09:35:36 +0000 (09:35 +0000)
This can be enabled using:
$dbh->setAttribute(PDO_ATTR_ORACLE_NULLS, true);

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

index ff5f4873a3d252b8f6ce5ed24b3567a53d32e3bb..295e8f3c823687b886ba5b87fc93397f0023bca3 100755 (executable)
@@ -229,6 +229,7 @@ PHP_MINIT_FUNCTION(pdo)
        REGISTER_LONG_CONSTANT("PDO_ATTR_CASE",                 (long)PDO_ATTR_CASE,            CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR_NAME",  (long)PDO_ATTR_CURSOR_NAME,             CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR",               (long)PDO_ATTR_CURSOR,          CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PDO_ATTR_ORACLE_NULLS", (long)PDO_ATTR_ORACLE_NULLS,    CONST_CS|CONST_PERSISTENT);
        
        REGISTER_LONG_CONSTANT("PDO_ERRMODE_SILENT",    (long)PDO_ERRMODE_SILENT,               CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ERRMODE_WARNING",   (long)PDO_ERRMODE_WARNING,              CONST_CS|CONST_PERSISTENT);
index ec2508290c3eb04f91dfd923cc6128ff6633ad8d..bad75906529a40b0b2968c211efa2ba97038bad4 100755 (executable)
@@ -353,6 +353,11 @@ static PHP_METHOD(PDO, setAttribute)
                                        zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "Case folding mode %d is invalid", Z_LVAL_P(value));
                        }
                        RETURN_FALSE;
+
+               case PDO_ATTR_ORACLE_NULLS:
+                       convert_to_long(value);
+                       dbh->oracle_nulls = Z_LVAL_P(value) ? 1 : 0;
+                       RETURN_TRUE;
                        
                default:
                        ;
index be704f413227a90829da545a3385bd0fea532d35..745c3455b542ab33f161ae69a7d90ff680ff245c 100755 (executable)
@@ -374,7 +374,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno TSRMLS_DC
 
        switch (col->param_type) {
                case PDO_PARAM_STR:
-                       if (value) {
+                       if (value && !(value_len == 0 && stmt->dbh->oracle_nulls)) {
                                ZVAL_STRINGL(dest, value, value_len, 1);
                                break;
                        }
index a661604bb0b6a5a03c57e2d87e6fa7d3e3431241..8288aa9eb3e1d21a561faa49500ce091e770f1d4 100755 (executable)
@@ -68,6 +68,7 @@ enum pdo_attribute_type {
        PDO_ATTR_CASE,                          /* control case folding for portability */
        PDO_ATTR_CURSOR_NAME,           /* name a cursor for use in "WHERE CURRENT OF <name>" */
        PDO_ATTR_CURSOR,                        /* cursor type */
+       PDO_ATTR_ORACLE_NULLS,          /* convert empty strings to NULL */
 
        /* this defines the start of the range for driver specific options.
         * Drivers should define their own attribute constants beginning with this
@@ -283,9 +284,12 @@ 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;
+
        /* 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;