diff options
| author | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
|---|---|---|
| committer | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
| commit | cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch) | |
| tree | 1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /ext/pgsql | |
| parent | 9ea47aab740772adf0c69d8c94b208a464e599ea (diff) | |
| download | php-upstream/5.2.9.dfsg.1.tar.gz | |
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'ext/pgsql')
| -rw-r--r-- | ext/pgsql/pgsql.c | 160 | ||||
| -rw-r--r-- | ext/pgsql/php_pgsql.h | 4 | ||||
| -rw-r--r-- | ext/pgsql/tests/bug37100.phpt | 43 | ||||
| -rw-r--r-- | ext/pgsql/tests/pg_delete_001.phpt | 86 | ||||
| -rw-r--r-- | ext/pgsql/tests/pg_insert_001.phpt | 40 | ||||
| -rw-r--r-- | ext/pgsql/tests/pg_meta_data_001.phpt | 92 | ||||
| -rw-r--r-- | ext/pgsql/tests/pg_select_001.phpt | 63 | ||||
| -rw-r--r-- | ext/pgsql/tests/pg_update_001.phpt | 51 |
8 files changed, 469 insertions, 70 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 15371e01c..05493d87d 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.331.2.13.2.27 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: pgsql.c,v 1.331.2.13.2.36 2009/01/27 14:44:07 felipe Exp $ */ #include <stdlib.h> @@ -1199,6 +1199,12 @@ PHP_FUNCTION(pg_query) static void _php_pgsql_free_params(char **params, int num_params) { if (num_params > 0) { + int i; + for (i = 0; i < num_params; i++) { + if (params[i]) { + efree(params[i]); + } + } efree(params); } } @@ -1216,7 +1222,6 @@ PHP_FUNCTION(pg_query_params) int leftover = 0; int num_params = 0; char **params = NULL; - unsigned char otype; PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; @@ -1276,19 +1281,20 @@ PHP_FUNCTION(pg_query_params) RETURN_FALSE; } - otype = (*tmp)->type; - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr)); @@ -1439,7 +1445,6 @@ PHP_FUNCTION(pg_execute) int leftover = 0; int num_params = 0; char **params = NULL; - unsigned char otype; PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; @@ -1500,19 +1505,20 @@ PHP_FUNCTION(pg_execute) RETURN_FALSE; } - otype = (*tmp)->type; - SEPARATE_ZVAL(tmp); - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; } else { - params[i] = Z_STRVAL_PP(tmp); + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr)); @@ -1729,7 +1735,7 @@ PHP_FUNCTION(pg_field_table) char *table_name; zend_rsrc_list_entry *field_table; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|b!", &result, &fnum, &return_oid) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|b", &result, &fnum, &return_oid) == FAILURE) { return; } @@ -1979,10 +1985,9 @@ PHP_FUNCTION(pg_fetch_result) if (PQgetisnull(pgsql_result, pgsql_row, field_offset)) { Z_TYPE_P(return_value) = IS_NULL; } else { - Z_STRVAL_P(return_value) = PQgetvalue(pgsql_result, pgsql_row, field_offset); - Z_STRLEN_P(return_value) = (Z_STRVAL_P(return_value) ? strlen(Z_STRVAL_P(return_value)) : 0); - Z_STRVAL_P(return_value) = safe_estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); - Z_TYPE_P(return_value) = IS_STRING; + char *value = PQgetvalue(pgsql_result, pgsql_row, field_offset); + int value_len = PQgetlength(pgsql_result, pgsql_row, field_offset); + ZVAL_STRINGL(return_value, value, value_len, 1); } } /* }}} */ @@ -3449,7 +3454,7 @@ PHP_FUNCTION(pg_copy_from) ExecStatusType status; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rs/a|ss", + if (zend_parse_parameters(argc TSRMLS_CC, "rsa|ss", &pgsql_link, &table_name, &table_name_len, &pg_rows, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; @@ -4048,7 +4053,6 @@ PHP_FUNCTION(pg_send_query_params) zval **pv_param_arr, **tmp; int num_params = 0; char **params = NULL; - unsigned char otype; zval **query; int id = -1; PGconn *pgsql; @@ -4097,20 +4101,20 @@ PHP_FUNCTION(pg_send_query_params) RETURN_FALSE; } - otype = (*tmp)->type; - SEPARATE_ZVAL(tmp); - convert_to_string_ex(tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr)); @@ -4194,7 +4198,6 @@ PHP_FUNCTION(pg_send_execute) zval **pv_param_arr, **tmp; int num_params = 0; char **params = NULL; - unsigned char otype; zval **stmtname; int id = -1; PGconn *pgsql; @@ -4241,19 +4244,20 @@ PHP_FUNCTION(pg_send_execute) RETURN_FALSE; } - otype = (*tmp)->type; - convert_to_string(*tmp); - if (Z_TYPE_PP(tmp) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); - _php_pgsql_free_params(params, num_params); - RETURN_FALSE; - } - - if (otype == IS_NULL) { + if (Z_TYPE_PP(tmp) == IS_NULL) { params[i] = NULL; - } - else { - params[i] = Z_STRVAL_PP(tmp); + } else { + zval tmp_val = **tmp; + zval_copy_ctor(&tmp_val); + convert_to_string(&tmp_val); + if (Z_TYPE(tmp_val) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter"); + zval_dtor(&tmp_val); + _php_pgsql_free_params(params, num_params); + RETURN_FALSE; + } + params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val)); + zval_dtor(&tmp_val); } zend_hash_move_forward(Z_ARRVAL_PP(pv_param_arr)); @@ -4407,27 +4411,47 @@ PHP_FUNCTION(pg_get_pid) PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC) { PGresult *pg_result; - char *tmp_name; + char *src, *tmp_name, *tmp_name2 = NULL; smart_str querystr = {0}; int new_len; int i, num_rows; zval *elem; + if (!*table_name) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified"); + return FAILURE; + } + + src = estrdup(table_name); + tmp_name = php_strtok_r(src, ".", &tmp_name2); + + if (!tmp_name2 || !*tmp_name2) { + /* Default schema */ + tmp_name2 = tmp_name; + tmp_name = "public"; + } + smart_str_appends(&querystr, "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotNULL, a.atthasdef, a.attndims " - "FROM pg_class as c, pg_attribute a, pg_type t " + "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); + smart_str_appendl(&querystr, tmp_name2, new_len); - tmp_name = php_addslashes((char *)table_name, strlen(table_name), &new_len, 0 TSRMLS_CC); + smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '"); + tmp_name = php_addslashes(tmp_name, strlen(tmp_name), &new_len, 0 TSRMLS_CC); smart_str_appendl(&querystr, tmp_name, new_len); - efree(tmp_name); smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;"); smart_str_0(&querystr); + efree(tmp_name2); + efree(tmp_name); + efree(src); + pg_result = PQexec(pg_link, querystr.c); if (PQresultStatus(pg_result) != PGRES_TUPLES_OK || (num_rows = PQntuples(pg_result)) == 0) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to query meta_data for '%s' table %s", table_name, querystr.c); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Table '%s' doesn't exists", table_name); smart_str_free(&querystr); PQclear(pg_result); return FAILURE; @@ -5003,7 +5027,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1); } else { /* FIXME: better regex must be used */ - if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,2}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { + if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { err = 1; } else { ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); @@ -5342,7 +5366,7 @@ static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, ulong opt T PQclear(pg_result); return 0; } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to execute '%s'", querystr->c); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", PQresultErrorMessage(pg_result)); PQclear(pg_result); } } @@ -5693,7 +5717,7 @@ cleanup: FREE_ZVAL(ids_converted); } if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { - *sql = estrdup(querystr.c); + *sql = querystr.c; } else { smart_str_free(&querystr); diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 08b2a394d..f6033e5a4 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pgsql.h,v 1.73.2.1.2.3 2007/12/31 07:20:10 sebastian Exp $ */ +/* $Id: php_pgsql.h,v 1.73.2.1.2.4 2008/12/31 11:17:42 sebastian Exp $ */ #ifndef PHP_PGSQL_H #define PHP_PGSQL_H diff --git a/ext/pgsql/tests/bug37100.phpt b/ext/pgsql/tests/bug37100.phpt new file mode 100644 index 000000000..b66149e4a --- /dev/null +++ b/ext/pgsql/tests/bug37100.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #37100 (data is returned truncated with BINARY CURSOR) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include 'config.inc'; + +$db = pg_connect($conn_str); + +@pg_query('DROP TABLE test_bug'); + +pg_query('CREATE TABLE test_bug (binfield byteA) ;'); +pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))"); + + +$data = pg_query("SELECT binfield FROM test_bug"); +$res = pg_fetch_result($data,0); +var_dump($res); +var_dump(bin2hex(pg_unescape_bytea($res))); + +$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;"; + +$data = pg_query($sql); +$res = pg_fetch_result($data,0); + +var_dump(strlen($res)); +var_dump(bin2hex($res)); + +pg_close($db); + +$db = pg_connect($conn_str); +pg_query('DROP TABLE test_bug'); +pg_close($db); + + +?> +--EXPECT-- +string(24) "\001\003\252\000\010\022" +string(12) "0103aa000812" +int(6) +string(12) "0103aa000812" diff --git a/ext/pgsql/tests/pg_delete_001.phpt b/ext/pgsql/tests/pg_delete_001.phpt new file mode 100644 index 000000000..abb65be14 --- /dev/null +++ b/ext/pgsql/tests/pg_delete_001.phpt @@ -0,0 +1,86 @@ +--TEST-- +PostgreSQL pg_delete() - basic test using schema +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include('config.inc'); + +$conn = pg_connect($conn_str); + +pg_query('CREATE SCHEMA phptests'); + +pg_query('CREATE TABLE foo (id INT, id2 INT)'); +pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); + +pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); +pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2)); +pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2)); +pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3)); + +pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1)); +pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); +pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); +pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); + +pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0)); +pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2)); +var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); + +pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1)); +pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); +var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING)); + +var_dump(pg_fetch_all(pg_query('SELECT * FROM foo'))); +var_dump(pg_fetch_all(pg_query('SELECT * FROM phptests.foo'))); + +/* Inexistent */ +pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2)); +var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); + +pg_query('DROP TABLE foo'); +pg_query('DROP TABLE phptests.foo'); +pg_query('DROP SCHEMA phptests'); + +?> +--EXPECTF-- +string(37) "DELETE FROM foo WHERE id=1 AND id2=2;" +string(46) "DELETE FROM phptests.foo WHERE id=2 AND id2=3;" +array(2) { + [0]=> + array(2) { + ["id"]=> + string(1) "1" + ["id2"]=> + string(1) "1" + } + [1]=> + array(2) { + ["id"]=> + string(1) "3" + ["id2"]=> + string(1) "3" + } +} +array(2) { + [0]=> + array(2) { + ["id"]=> + string(1) "1" + ["id2"]=> + string(1) "1" + } + [1]=> + array(2) { + ["id"]=> + string(1) "1" + ["id2"]=> + string(1) "2" + } +} + +Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d + +Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d +bool(false) diff --git a/ext/pgsql/tests/pg_insert_001.phpt b/ext/pgsql/tests/pg_insert_001.phpt new file mode 100644 index 000000000..7d2721918 --- /dev/null +++ b/ext/pgsql/tests/pg_insert_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +PostgreSQL pg_select() - basic test using schema +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include('config.inc'); + +$conn = pg_connect($conn_str); + +pg_query('CREATE SCHEMA phptests'); +pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); + + +pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); + +pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); + +var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); + +var_dump(pg_select($conn, 'phptests.foo', array('id' => 1))); + +pg_query('DROP TABLE phptests.foo'); +pg_query('DROP SCHEMA phptests'); + +?> +--EXPECTF-- + +Warning: pg_insert(): Table 'foo' doesn't exists in %s on line %d +string(47) "INSERT INTO phptests.foo (id,id2) VALUES (1,2);" +array(1) { + [0]=> + array(2) { + ["id"]=> + string(1) "1" + ["id2"]=> + string(1) "2" + } +} diff --git a/ext/pgsql/tests/pg_meta_data_001.phpt b/ext/pgsql/tests/pg_meta_data_001.phpt new file mode 100644 index 000000000..2841de83d --- /dev/null +++ b/ext/pgsql/tests/pg_meta_data_001.phpt @@ -0,0 +1,92 @@ +--TEST-- +PostgreSQL pg_meta_data() - basic test using schema +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include('config.inc'); + +$conn = pg_connect($conn_str); + +pg_query('CREATE SCHEMA phptests'); + +pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); + +pg_query('CREATE TABLE foo (id INT, id3 INT)'); + + +var_dump(pg_meta_data($conn, 'foo')); +var_dump(pg_meta_data($conn, 'phptests.foo')); + + +pg_query('DROP TABLE foo'); +pg_query('DROP TABLE phptests.foo'); +pg_query('DROP SCHEMA phptests'); + +?> +--EXPECT-- +array(2) { + ["id"]=> + array(6) { + ["num"]=> + int(1) + ["type"]=> + string(4) "int4" + ["len"]=> + int(4) + ["not null"]=> + bool(false) + ["has default"]=> + bool(false) + ["array dims"]=> + int(0) + } + ["id3"]=> + array(6) { + ["num"]=> + int(2) + ["type"]=> + string(4) "int4" + ["len"]=> + int(4) + ["not null"]=> + bool(false) + ["has default"]=> + bool(false) + ["array dims"]=> + int(0) + } +} +array(2) { + ["id"]=> + array(6) { + ["num"]=> + int(1) + ["type"]=> + string(4) "int4" + ["len"]=> + int(4) + ["not null"]=> + bool(false) + ["has default"]=> + bool(false) + ["array dims"]=> + int(0) + } + ["id2"]=> + array(6) { + ["num"]=> + int(2) + ["type"]=> + string(4) "int4" + ["len"]=> + int(4) + ["not null"]=> + bool(false) + ["has default"]=> + bool(false) + ["array dims"]=> + int(0) + } +} diff --git a/ext/pgsql/tests/pg_select_001.phpt b/ext/pgsql/tests/pg_select_001.phpt new file mode 100644 index 000000000..9bcf130dd --- /dev/null +++ b/ext/pgsql/tests/pg_select_001.phpt @@ -0,0 +1,63 @@ +--TEST-- +PostgreSQL pg_select() - basic test using schema +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include('config.inc'); + +$conn = pg_connect($conn_str); + +pg_query('CREATE SCHEMA phptests'); + +pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query('INSERT INTO phptests.foo VALUES (1,2)'); +pg_query('INSERT INTO phptests.foo VALUES (2,3)'); + +pg_query('CREATE TABLE phptests.bar (id4 INT, id3 INT)'); +pg_query('INSERT INTO phptests.bar VALUES (4,5)'); +pg_query('INSERT INTO phptests.bar VALUES (6,7)'); + +/* Inexistent table */ +var_dump(pg_select($conn, 'foo', array('id' => 1))); + +/* Existent column */ +var_dump(pg_select($conn, 'phptests.foo', array('id' => 1))); + +/* Testing with inexistent column */ +var_dump(pg_select($conn, 'phptests.bar', array('id' => 1))); + +/* Existent column */ +var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4))); + + +pg_query('DROP TABLE phptests.foo'); +pg_query('DROP TABLE phptests.bar'); +pg_query('DROP SCHEMA phptests'); + +?> +--EXPECTF-- +Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d +bool(false) +array(1) { + [0]=> + array(2) { + ["id"]=> + string(1) "1" + ["id2"]=> + string(1) "2" + } +} + +Notice: pg_select(): Invalid field name (id) in values in %s on line %d +bool(false) +array(1) { + [0]=> + array(2) { + ["id4"]=> + string(1) "4" + ["id3"]=> + string(1) "5" + } +} diff --git a/ext/pgsql/tests/pg_update_001.phpt b/ext/pgsql/tests/pg_update_001.phpt new file mode 100644 index 000000000..95fa69256 --- /dev/null +++ b/ext/pgsql/tests/pg_update_001.phpt @@ -0,0 +1,51 @@ +--TEST-- +PostgreSQL pg_update() - basic test using schema +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include('config.inc'); + +$conn = pg_connect($conn_str); + +pg_query('CREATE SCHEMA phptests'); + +pg_query('CREATE TABLE foo (id INT, id2 INT)'); +pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); + + +pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); +pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); + +pg_update($conn, 'foo', array('id' => 10), array('id' => 1)); +var_dump(pg_update($conn, 'foo', array('id' => 10), array('id' => 1), PGSQL_DML_STRING)); + +pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2)); +var_dump(pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2), PGSQL_DML_STRING)); + +$rs = pg_query('SELECT * FROM foo UNION SELECT * FROM phptests.foo'); +while ($row = pg_fetch_assoc($rs)) { + var_dump($row); +} + +pg_query('DROP TABLE foo'); +pg_query('DROP TABLE phptests.foo'); +pg_query('DROP SCHEMA phptests'); + +?> +--EXPECT-- +string(32) "UPDATE foo SET id=10 WHERE id=1;" +string(43) "UPDATE phptests.foo SET id=100 WHERE id2=2;" +array(2) { + ["id"]=> + string(2) "10" + ["id2"]=> + string(1) "1" +} +array(2) { + ["id"]=> + string(3) "100" + ["id2"]=> + string(1) "2" +} |
