diff options
author | Ondřej Surý <ondrej@sury.org> | 2013-06-06 20:32:27 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2013-06-06 20:32:27 +0200 |
commit | d9b0e944a6bfa31fec6b71170346648925e76935 (patch) | |
tree | b6de5f6389aeb27758d34f29ea6f000570f5e9fc /ext/pgsql | |
parent | 4cd628b36adb52a09b58782cd60c5f4ce2ad4764 (diff) | |
download | php-d9b0e944a6bfa31fec6b71170346648925e76935.tar.gz |
New upstream version 5.5.0~rc3
Diffstat (limited to 'ext/pgsql')
-rw-r--r-- | ext/pgsql/pgsql.c | 41 | ||||
-rw-r--r-- | ext/pgsql/tests/10pg_convert_85.phpt | 1 | ||||
-rw-r--r-- | ext/pgsql/tests/12pg_insert_85.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/14pg_update_85.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/18pg_escape_bytea.phpt | 3 | ||||
-rw-r--r-- | ext/pgsql/tests/bug64609.phpt | 30 |
6 files changed, 73 insertions, 6 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 7ee838a9f..dcc2c2869 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4998,7 +4998,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z } smart_str_appends(&querystr, - "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotNULL, a.atthasdef, a.attndims " + "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' " "FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n " "WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '"); tmp_name2 = php_addslashes(tmp_name2, strlen(tmp_name2), &new_len, 0 TSRMLS_CC); @@ -5044,6 +5044,12 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z add_assoc_bool(elem, "has default", 0); } add_assoc_long(elem, "array dims", atoi(PQgetvalue(pg_result,i,6))); + if (!strcmp(PQgetvalue(pg_result,i,7), "t")) { + add_assoc_bool(elem, "is enum", 1); + } + else { + add_assoc_bool(elem, "is enum", 0); + } name = PQgetvalue(pg_result,i,0); add_assoc_zval(meta, name, elem); } @@ -5077,7 +5083,18 @@ PHP_FUNCTION(pg_meta_data) zval_dtor(return_value); /* destroy array */ RETURN_FALSE; } -} + else { + HashPosition pos; + zval **val; + + for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(return_value), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(return_value), (void **)&val, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(return_value), &pos)) { + /* delete newly added entry, in order to keep BC */ + zend_hash_del_key_or_index(Z_ARRVAL_PP(val), "is enum", sizeof("is enum"), 0, HASH_DEL_KEY); + } + } +} /* }}} */ /* {{{ php_pgsql_get_data_type @@ -5259,8 +5276,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con char *field = NULL; uint field_len = -1; ulong num_idx = -1; - zval *meta, **def, **type, **not_null, **has_default, **val, *new_val; + zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val; int new_len, key_type, err = 0, skip_field; + php_pgsql_data_type data_type; assert(pg_link != NULL); assert(Z_TYPE_P(values) == IS_ARRAY); @@ -5311,17 +5329,30 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'has default'"); err = 1; } + if (!err && zend_hash_find(Z_ARRVAL_PP(def), "is enum", sizeof("is enum"), (void **)&is_enum) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'is enum'"); + err = 1; + } if (!err && (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT || Z_TYPE_PP(val) == IS_CONSTANT_ARRAY)) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scaler values as field values"); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scalar values as field values"); err = 1; } if (err) { break; /* break out for() */ } ALLOC_INIT_ZVAL(new_val); - switch(php_pgsql_get_data_type(Z_STRVAL_PP(type), Z_STRLEN_PP(type))) + + if (Z_BVAL_PP(is_enum)) { + /* enums need to be treated like strings */ + data_type = PG_TEXT; + } + else { + data_type = php_pgsql_get_data_type(Z_STRVAL_PP(type), Z_STRLEN_PP(type)); + } + + switch(data_type) { case PG_BOOL: switch (Z_TYPE_PP(val)) { diff --git a/ext/pgsql/tests/10pg_convert_85.phpt b/ext/pgsql/tests/10pg_convert_85.phpt index 4f1c92bf1..8b1cc8f53 100644 --- a/ext/pgsql/tests/10pg_convert_85.phpt +++ b/ext/pgsql/tests/10pg_convert_85.phpt @@ -12,6 +12,7 @@ error_reporting(E_ALL); include 'config.inc'; $db = pg_connect($conn_str); +pg_query($db, "SET standard_conforming_strings = 0"); $fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB'); $converted = pg_convert($db, $table_name, $fields); diff --git a/ext/pgsql/tests/12pg_insert_85.phpt b/ext/pgsql/tests/12pg_insert_85.phpt index a85dea036..5fbbe4b7a 100644 --- a/ext/pgsql/tests/12pg_insert_85.phpt +++ b/ext/pgsql/tests/12pg_insert_85.phpt @@ -12,6 +12,8 @@ error_reporting(E_ALL); include 'config.inc'; $db = pg_connect($conn_str); +pg_query($db, "SET standard_conforming_strings = 0"); + $fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB'); pg_insert($db, $table_name, $fields) or print "Error in test 1\n"; diff --git a/ext/pgsql/tests/14pg_update_85.phpt b/ext/pgsql/tests/14pg_update_85.phpt index f1c77eac1..06ca8c3de 100644 --- a/ext/pgsql/tests/14pg_update_85.phpt +++ b/ext/pgsql/tests/14pg_update_85.phpt @@ -12,6 +12,8 @@ error_reporting(E_ALL); include 'config.inc'; $db = pg_connect($conn_str); +pg_query($db, "SET standard_conforming_strings = 0"); + $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ'); $ids = array('num'=>'1234'); diff --git a/ext/pgsql/tests/18pg_escape_bytea.phpt b/ext/pgsql/tests/18pg_escape_bytea.phpt index 43f98c446..5f52a17d9 100644 --- a/ext/pgsql/tests/18pg_escape_bytea.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea.phpt @@ -8,10 +8,11 @@ PostgreSQL pg_escape_bytea() functions include('config.inc'); +$db = pg_connect($conn_str); + $image = file_get_contents(dirname(__FILE__) . '/php.gif'); $esc_image = pg_escape_bytea($image); -$db = pg_connect($conn_str); pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');'); $result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876'); $rows = pg_fetch_all($result); diff --git a/ext/pgsql/tests/bug64609.phpt b/ext/pgsql/tests/bug64609.phpt new file mode 100644 index 000000000..0df63012d --- /dev/null +++ b/ext/pgsql/tests/bug64609.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #64609 (pg_convert enum type support) +--SKIPIF-- +<?php +include("skipif.inc"); +skip_server_version('8.3', '<'); +?> +--FILE-- +<?php +error_reporting(E_ALL); + +include 'config.inc'; + +$db = pg_connect($conn_str); +pg_query("BEGIN"); +pg_query("CREATE TYPE t_enum AS ENUM ('ok', 'ko')"); +pg_query("CREATE TABLE test_enum (a t_enum)"); + +$fields = array('a' => 'ok'); +$converted = pg_convert($db, 'test_enum', $fields); + +pg_query("ROLLBACK"); + +var_dump($converted); +?> +--EXPECT-- +array(1) { + ["a"]=> + string(4) "'ok'" +} |