helly Sat May 31 08:59:20 2003 EDT
Removed files: (Branch: PHP_4_3)
/php4/ext/pgsql/tests async_query.inc connection.inc copy.inc
createdb.inc dropdb.inc escape.inc
informational.inc large_object.inc notice.inc
old_api.inc optional.inc pg_convert.inc
pg_delete.inc pg_escape_bytea.inc
pg_get_notify.inc pg_get_pid.inc
pg_insert.inc pg_meta_data.inc pg_ping.inc
pg_result_status.inc pg_select.inc
pg_update.inc result.inc sync_query.inc
Modified files:
/php4/ext/pgsql pgsql.c php_pgsql.h
/php4/ext/pgsql/tests 01createdb.phpt 02connection.phpt
03sync_query.phpt 04async_query.phpt
05large_object.phpt 06copy.phpt
07optional.phpt 08escape.phpt 09notice.phpt
10pg_convert.phpt 11pg_meta_data.phpt
12pg_insert.phpt 13pg_select.phpt
14pg_update.phpt 15pg_delete.phpt
16pg_result_status.phpt 17result.phpt
18pg_escape_bytea.phpt 19pg_ping.phpt
20pg_get_pid.phpt 21pg_get_notify.phpt
98old_api.phpt 9999dropdb.phpt README
Log:
MFH: Synch latest fixes
Index: php4/ext/pgsql/pgsql.c
diff -u php4/ext/pgsql/pgsql.c:1.244.2.17 php4/ext/pgsql/pgsql.c:1.244.2.18
--- php4/ext/pgsql/pgsql.c:1.244.2.17 Fri Apr 25 18:00:17 2003
+++ php4/ext/pgsql/pgsql.c Sat May 31 08:59:19 2003
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.244.2.17 2003/04/25 22:00:17 iliaa Exp $ */
+/* $Id: pgsql.c,v 1.244.2.18 2003/05/31 12:59:19 helly Exp $ */
#include <stdlib.h>
@@ -212,11 +212,7 @@
static int le_link, le_plink, le_result, le_lofp, le_string;
-#ifdef ZTS
-int pgsql_globals_id;
-#else
-php_pgsql_globals pgsql_globals;
-#endif
+ZEND_DECLARE_MODULE_GLOBALS(pgsql);
/* {{{ php_pgsql_set_default_link
*/
@@ -268,15 +264,21 @@
static void _php_pgsql_notice_handler(void *resource_id, const char *message)
{
php_pgsql_notice *notice;
+ int i;
TSRMLS_FETCH();
if (! PGG(ignore_notices)) {
+ notice = (php_pgsql_notice *)emalloc(sizeof(php_pgsql_notice));
+ i = strlen(message)-1;
+ while (i && (message[i] == '\r' || message[i] == '\n')) {
+ i--;
+ }
+ i++;
+ notice->message = estrndup(message, i);
+ notice->len = i;
if (PGG(log_notices)) {
- php_log_err((char *) message TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s",
notice->message);
}
- notice = (php_pgsql_notice *)emalloc(sizeof(php_pgsql_notice));
- notice->len = strlen(message);
- notice->message = estrndup(message, notice->len);
zend_hash_index_update(&PGG(notices), *(int *)resource_id, (void
**)¬ice, sizeof(php_pgsql_notice *), NULL);
}
}
@@ -348,22 +350,22 @@
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
-STD_PHP_INI_BOOLEAN("pgsql.allow_persistent", "1", PHP_INI_SYSTEM,
OnUpdateBool, allow_persistent, php_pgsql_globals,
pgsql_globals)
-STD_PHP_INI_ENTRY_EX("pgsql.max_persistent", "-1", PHP_INI_SYSTEM,
OnUpdateInt, max_persistent, php_pgsql_globals,
pgsql_globals, display_link_numbers)
-STD_PHP_INI_ENTRY_EX("pgsql.max_links", "-1", PHP_INI_SYSTEM,
OnUpdateInt, max_links, php_pgsql_globals,
pgsql_globals, display_link_numbers)
-STD_PHP_INI_BOOLEAN("pgsql.auto_reset_persistent", "0", PHP_INI_SYSTEM,
OnUpdateBool, auto_reset_persistent, php_pgsql_globals,
pgsql_globals)
-STD_PHP_INI_BOOLEAN("pgsql.ignore_notice", "0", PHP_INI_ALL,
OnUpdateBool, ignore_notices, php_pgsql_globals, pgsql_globals)
-STD_PHP_INI_BOOLEAN("pgsql.log_notice", "0", PHP_INI_ALL,
OnUpdateBool, log_notices, php_pgsql_globals, pgsql_globals)
+STD_PHP_INI_BOOLEAN( "pgsql.allow_persistent", "1", PHP_INI_SYSTEM,
OnUpdateBool, allow_persistent, zend_pgsql_globals, pgsql_globals)
+STD_PHP_INI_ENTRY_EX("pgsql.max_persistent", "-1", PHP_INI_SYSTEM,
OnUpdateInt, max_persistent, zend_pgsql_globals, pgsql_globals,
display_link_numbers)
+STD_PHP_INI_ENTRY_EX("pgsql.max_links", "-1", PHP_INI_SYSTEM,
OnUpdateInt, max_links, zend_pgsql_globals, pgsql_globals,
display_link_numbers)
+STD_PHP_INI_BOOLEAN( "pgsql.auto_reset_persistent", "0", PHP_INI_SYSTEM,
OnUpdateBool, auto_reset_persistent, zend_pgsql_globals, pgsql_globals)
+STD_PHP_INI_BOOLEAN( "pgsql.ignore_notice", "0", PHP_INI_ALL,
OnUpdateBool, ignore_notices, zend_pgsql_globals, pgsql_globals)
+STD_PHP_INI_BOOLEAN( "pgsql.log_notice", "0", PHP_INI_ALL,
OnUpdateBool, log_notices, zend_pgsql_globals, pgsql_globals)
PHP_INI_END()
/* }}} */
/* {{{ php_pgsql_init_globals
*/
-static void php_pgsql_init_globals(php_pgsql_globals *pgsql_globals_p TSRMLS_DC)
+static void php_pgsql_init_globals(zend_pgsql_globals *pgsql_globals)
{
- PGG(num_persistent) = 0;
+ memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
/* Initilize notice message hash at MINIT only */
- zend_hash_init_ex(&PGG(notices), 0, NULL, PHP_PGSQL_NOTICE_PTR_DTOR, 1, 0);
+ zend_hash_init_ex(&pgsql_globals->notices, 0, NULL, PHP_PGSQL_NOTICE_PTR_DTOR,
1, 0);
}
/* }}} */
@@ -371,11 +373,7 @@
*/
PHP_MINIT_FUNCTION(pgsql)
{
-#ifdef ZTS
- ts_allocate_id(&pgsql_globals_id, sizeof(php_pgsql_globals),
(ts_allocate_ctor) php_pgsql_init_globals, NULL);
-#else
- php_pgsql_init_globals(&pgsql_globals TSRMLS_CC);
-#endif
+ ZEND_INIT_MODULE_GLOBALS(pgsql, php_pgsql_init_globals, NULL);
REGISTER_INI_ENTRIES();
@@ -728,6 +726,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -775,6 +776,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -914,6 +918,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -1595,7 +1602,7 @@
Enable tracing a PostgreSQL connection */
PHP_FUNCTION(pg_trace)
{
- zval **z_filename, **z_mode, **z_pgsql_link = NULL;
+ zval **z_filename, **z_mode, **pgsql_link = NULL;
int id = -1;
PGconn *pgsql;
char *mode = "w";
@@ -1619,7 +1626,7 @@
mode = Z_STRVAL_PP(z_mode);
break;
case 3:
- if (zend_get_parameters_ex(3, &z_filename, &z_mode,
&z_pgsql_link)==FAILURE) {
+ if (zend_get_parameters_ex(3, &z_filename, &z_mode,
&pgsql_link)==FAILURE) {
RETURN_FALSE;
}
convert_to_string_ex(z_mode);
@@ -1629,8 +1636,11 @@
ZEND_WRONG_PARAM_COUNT();
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
- ZEND_FETCH_RESOURCE2(pgsql, PGconn *, z_pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
convert_to_string_ex(z_filename);
stream = php_stream_open_wrapper(Z_STRVAL_PP(z_filename), mode,
ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
@@ -1671,6 +1681,9 @@
ZEND_WRONG_PARAM_COUNT();
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
PQuntrace(pgsql);
@@ -1701,6 +1714,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -1776,8 +1792,7 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 1 or 2
arguments.");
RETURN_FALSE;
}
-
- if (pgsql_link == NULL) {
+ if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
@@ -1849,8 +1864,7 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 1 or 2
arguments.");
RETURN_FALSE;
}
-
- if (pgsql_link == NULL) {
+ if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
@@ -2082,15 +2096,15 @@
WRONG_PARAM_COUNT;
}
- if (pgsql_link == NULL) {
+ if (PG(safe_mode) &&(!php_checkuid(file_in, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
RETURN_FALSE;
}
- if (PG(safe_mode) &&(!php_checkuid(file_in, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
+ if (php_check_open_basedir(file_in TSRMLS_CC)) {
RETURN_FALSE;
}
- if (php_check_open_basedir(file_in TSRMLS_CC)) {
+ if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
@@ -2180,15 +2194,15 @@
RETURN_FALSE;
}
- if (pgsql_link == NULL) {
+ if (PG(safe_mode) &&(!php_checkuid(file_out, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
RETURN_FALSE;
}
- if (PG(safe_mode) &&(!php_checkuid(file_out, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
+ if (php_check_open_basedir(file_out TSRMLS_CC)) {
RETURN_FALSE;
}
- if (php_check_open_basedir(file_out TSRMLS_CC)) {
+ if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
@@ -2274,6 +2288,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -2306,6 +2323,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -2350,6 +2370,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
@@ -2390,6 +2413,9 @@
WRONG_PARAM_COUNT;
break;
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
Index: php4/ext/pgsql/php_pgsql.h
diff -u php4/ext/pgsql/php_pgsql.h:1.56.2.2 php4/ext/pgsql/php_pgsql.h:1.56.2.3
--- php4/ext/pgsql/php_pgsql.h:1.56.2.2 Tue Apr 1 19:00:09 2003
+++ php4/ext/pgsql/php_pgsql.h Sat May 31 08:59:19 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pgsql.h,v 1.56.2.2 2003/04/02 00:00:09 jay Exp $ */
+/* $Id: php_pgsql.h,v 1.56.2.3 2003/05/31 12:59:19 helly Exp $ */
#ifndef PHP_PGSQL_H
#define PHP_PGSQL_H
@@ -236,24 +236,23 @@
size_t len;
} php_pgsql_notice;
-typedef struct {
+ZEND_BEGIN_MODULE_GLOBALS(pgsql)
long default_link; /* default link when connection is omitted */
long num_links,num_persistent;
long max_links,max_persistent;
long allow_persistent;
long auto_reset_persistent;
int le_lofp,le_string;
- int ignore_notices,log_notices;
+ long ignore_notices,log_notices;
HashTable notices; /* notice message for each connection */
-} php_pgsql_globals;
+ZEND_END_MODULE_GLOBALS(pgsql)
+ZEND_EXTERN_MODULE_GLOBALS(pgsql)
#ifdef ZTS
-# define PGG(v) TSRMG(pgsql_globals_id, php_pgsql_globals *, v)
-extern int pgsql_globals_id;
+# define PGG(v) TSRMG(pgsql_globals_id, zend_pgsql_globals *, v)
#else
# define PGG(v) (pgsql_globals.v)
-extern php_pgsql_globals pgsql_globals;
#endif
#endif
Index: php4/ext/pgsql/tests/01createdb.phpt
diff -u php4/ext/pgsql/tests/01createdb.phpt:1.1
php4/ext/pgsql/tests/01createdb.phpt:1.1.8.1
--- php4/ext/pgsql/tests/01createdb.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/01createdb.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,25 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("createdb.inc");
+// create test table
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+if ([EMAIL PROTECTED](@pg_query($db, "SELECT * FROM ".$table_name)))
+{
+ @pg_query($db,$table_def); // Create table here
+ for ($i=0; $i < $num_test_record; $i++) {
+ pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
+ }
+}
+else {
+ echo pg_last_error()."\n";
+}
+
+pg_close($db);
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/02connection.phpt
diff -u php4/ext/pgsql/tests/02connection.phpt:1.1
php4/ext/pgsql/tests/02connection.phpt:1.1.8.1
--- php4/ext/pgsql/tests/02connection.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/02connection.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,47 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("connection.inc");
+// connection function tests
+
+include('config.inc');
+
+$db = pg_pconnect($conn_str);
+if (pg_connection_status($db) != PGSQL_CONNECTION_OK)
+{
+ echo "pg_connection_status() error\n";
+}
+if (!pg_connection_reset($db))
+{
+ echo "pg_connection_reset() error\n";
+}
+if (pg_connection_busy($db))
+{
+ echo "pg_connection_busy() error\n";
+}
+if (!pg_host($db))
+{
+ echo "pg_host() error\n";
+}
+if (!pg_dbname($db))
+{
+ echo "pg_dbname() error\n";
+}
+if (!pg_port($db))
+{
+ echo "pg_port() error\n";
+}
+if (pg_tty($db))
+{
+ echo "pg_tty() error\n";
+}
+if (pg_options($db))
+{
+ echo "pg_options() error\n";
+}
+
+pg_close($db);
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/03sync_query.phpt
diff -u php4/ext/pgsql/tests/03sync_query.phpt:1.1
php4/ext/pgsql/tests/03sync_query.phpt:1.1.8.1
--- php4/ext/pgsql/tests/03sync_query.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/03sync_query.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,50 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("sync_query.inc");
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+
+$result = pg_query($db, "SELECT * FROM ".$table_name.";");
+if (!($rows = pg_num_rows($result)))
+{
+ echo "pg_num_row() error\n";
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_array($result, $i, PGSQL_NUM);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_object($result, $i, PGSQL_ASSOC);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_row($result, $i);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_result($result, $i, 0);
+}
+
+pg_result_error($result);
+pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
+pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
+pg_field_name($result, 0);
+pg_field_num($result, $field_name);
+pg_field_size($result, 0);
+pg_field_type($result, 0);
+pg_field_prtlen($result, 0);
+pg_field_is_null($result, 0);
+
+$result = pg_query($db, "INSERT INTO ".$table_name." VALUES (9999, 'ABC');");
+pg_last_oid($result);
+
+pg_free_result($result);
+pg_close($db);
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/04async_query.phpt
diff -u php4/ext/pgsql/tests/04async_query.phpt:1.1
php4/ext/pgsql/tests/04async_query.phpt:1.1.8.1
--- php4/ext/pgsql/tests/04async_query.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/04async_query.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,62 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("async_query.inc");
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+
+if (!pg_send_query($db, "SELECT * FROM ".$table_name.";")) {
+ echo "pg_send_query() error\n";
+}
+while(pg_connection_busy($db)); // busy wait: intended
+if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+ echo "pg_connection_status() error\n";
+}
+if (!($result = pg_get_result($db)))
+{
+ echo "pg_get_result() error\n";
+}
+
+if (!($rows = pg_num_rows($result))) {
+ echo "pg_num_rows() error\n";
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_array($result, $i, PGSQL_NUM);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_object($result, $i, PGSQL_ASSOC);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_row($result, $i);
+}
+for ($i=0; $i < $rows; $i++)
+{
+ pg_fetch_result($result, $i, 0);
+}
+
+pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
+pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
+pg_field_name($result, 0);
+pg_field_num($result, $field_name);
+pg_field_size($result, 0);
+pg_field_type($result, 0);
+pg_field_prtlen($result, 0);
+pg_field_is_null($result, 0);
+
+if (!pg_send_query($db, "INSERT INTO ".$table_name." VALUES (8888, 'GGG');"))
+{
+ echo "pg_send_query() error\n";
+}
+
+pg_last_oid($result);
+pg_free_result($result);
+
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/05large_object.phpt
diff -u php4/ext/pgsql/tests/05large_object.phpt:1.1
php4/ext/pgsql/tests/05large_object.phpt:1.1.8.1
--- php4/ext/pgsql/tests/05large_object.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/05large_object.phpt Sat May 31 08:59:19 2003
@@ -4,8 +4,78 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("large_object.inc");
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+
+echo "create/write/close LO\n";
+pg_exec ($db, "begin");
+$oid = pg_lo_create ($db);
+if (!$oid) echo ("pg_lo_create() error\n");
+$handle = pg_lo_open ($db, $oid, "w");
+if (!$handle) echo ("pg_lo_open() error\n");
+pg_lo_write ($handle, "large object data\n");
+pg_lo_close ($handle);
+pg_exec ($db, "commit");
+
+echo "open/read/tell/seek/close LO\n";
+pg_exec ($db, "begin");
+$handle = pg_lo_open ($db, $oid, "w");
+pg_lo_read($handle, 100);
+pg_lo_tell($handle);
+pg_lo_seek($handle, 2);
+pg_lo_close($handle);
+pg_exec ($db, "commit");
+
+echo "open/read_all/close LO\n";
+pg_exec ($db, "begin");
+$handle = pg_lo_open ($db, $oid, "w");
+pg_lo_read_all($handle);
+if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error();
+pg_lo_close($handle);
+pg_exec ($db, "commit");
+
+echo "unlink LO\n";
+pg_exec ($db, "begin");
+pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error 1\n");
+pg_exec ($db, "commit");
+
+// more pg_lo_unlink() tests
+echo "Test without connection\n";
+pg_exec ($db, "begin");
+$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
+pg_lo_unlink($oid) or print("pg_lo_unlink() error 2\n");
+pg_exec ($db, "commit");
+
+echo "Test with string oid value\n";
+pg_exec ($db, "begin");
+$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
+pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error 3\n");
+pg_exec ($db, "commit");
+
+echo "import/export LO\n";
+pg_query($db, 'begin');
+$oid = pg_lo_import($db, 'php.gif');
+pg_query($db, 'commit');
+pg_query($db, 'begin');
[EMAIL PROTECTED]('php.gif.exported');
+pg_lo_export($oid, 'php.gif.exported', $db);
+if (!file_exists('php.gif.exported')) {
+ echo "Export failed\n";
+}
[EMAIL PROTECTED]('php.gif.exported');
+pg_query($db, 'commit');
+
+echo "OK";
?>
--EXPECT--
+create/write/close LO
+open/read/tell/seek/close LO
+open/read_all/close LO
large object data
+unlink LO
+Test without connection
+Test with string oid value
+import/export LO
OK
Index: php4/ext/pgsql/tests/06copy.phpt
diff -u php4/ext/pgsql/tests/06copy.phpt:1.1 php4/ext/pgsql/tests/06copy.phpt:1.1.8.1
--- php4/ext/pgsql/tests/06copy.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/06copy.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,12 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("copy.inc");
+
+include('config.inc');
+
+
+echo "OK";
+
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/07optional.phpt
diff -u php4/ext/pgsql/tests/07optional.phpt:1.1
php4/ext/pgsql/tests/07optional.phpt:1.1.8.1
--- php4/ext/pgsql/tests/07optional.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/07optional.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,16 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("optional.inc");
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+$enc = pg_client_encoding($db);
+
+pg_set_client_encoding($db, $enc);
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/08escape.phpt
diff -u php4/ext/pgsql/tests/08escape.phpt:1.4
php4/ext/pgsql/tests/08escape.phpt:1.4.4.1
--- php4/ext/pgsql/tests/08escape.phpt:1.4 Fri Apr 19 08:24:58 2002
+++ php4/ext/pgsql/tests/08escape.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,63 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("escape.inc");
+
+include 'config.inc';
+define('FILE_NAME', './php.gif');
+
+// pg_escape_string() test
+$before = "ABC\\ABC\'";
+$expect = "ABC\\\\ABC\\'";
+$after = pg_escape_string($before);
+if ($expect === $after) {
+ echo "pg_escape_string() is Ok\n";
+}
+else {
+ echo "pg_escape_string() is NOT Ok\n";
+ var_dump($before);
+ var_dump($after);
+ var_dump($expect);
+}
+
+// pg_escape_bytea() test
+$before = "ABC\\ABC";
+$expect = "ABC\\\\\\\\ABC";
+$after = pg_escape_bytea($before);
+if ($expect === $after) {
+ echo "pg_escape_bytea() is Ok\n";
+}
+else {
+ echo "pg_escape_byte() is NOT Ok\n";
+ var_dump($before);
+ var_dump($after);
+ var_dump($expect);
+}
+
+// Test using database
+$fp = fopen(FILE_NAME,'r');
+$data = fread($fp, filesize(FILE_NAME));
+$db = pg_connect($conn_str);
+
+// Insert binary to DB
+$escaped_data = pg_escape_bytea($data);
+pg_query("DELETE FROM ".$table_name." WHERE num = -9999;");
+$sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST
('".$escaped_data."' AS BYTEA));";
+pg_query($db, $sql);
+
+// Retrieve binary from DB
+$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
+$result = pg_query($db, $sql);
+$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
+
+// Compare
+// Need to wait PostgreSQL 7.3.x for PQunescapeBytea()
+// if ($data === pg_unescape_bytea($row['bin'])) {
+// echo "pg_escape_bytea() actually works with databse\n";
+// }
+// else {
+// echo "pg_escape_bytea() is broken\n";
+// }
+
?>
--EXPECT--
pg_escape_string() is NOT Ok
Index: php4/ext/pgsql/tests/09notice.phpt
diff -u php4/ext/pgsql/tests/09notice.phpt:1.2
php4/ext/pgsql/tests/09notice.phpt:1.2.4.1
--- php4/ext/pgsql/tests/09notice.phpt:1.2 Fri Apr 5 02:57:33 2002
+++ php4/ext/pgsql/tests/09notice.phpt Sat May 31 08:59:19 2003
@@ -2,12 +2,27 @@
PostgreSQL notice function
--SKIPIF--
<?php include("skipif.inc"); ?>
+--INI--
+pgsql.log_notice=1
+pgsql.ignore_notices=0
--FILE--
<?php
-include("notice.inc");
-?>
---EXPECT--
-NOTICE: BEGIN: already a transaction in progress
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+pg_query($db, "BEGIN;");
+pg_query($db, "BEGIN;");
+$msg = pg_last_notice($db);
+if ($msg === FALSE) {
+ echo "Cannot find notice message in hash\n";
+ var_dump($msg);
+}
+echo $msg."\n";
+echo "pg_last_notice() is Ok\n";
+
+?>
+--EXPECTF--
+Notice: pg_query(): NOTICE: BEGIN: already a transaction in progress in %s on line %d
NOTICE: BEGIN: already a transaction in progress
pg_last_notice() is Ok
Index: php4/ext/pgsql/tests/10pg_convert.phpt
diff -u php4/ext/pgsql/tests/10pg_convert.phpt:1.2
php4/ext/pgsql/tests/10pg_convert.phpt:1.2.4.1
--- php4/ext/pgsql/tests/10pg_convert.phpt:1.2 Fri Apr 19 08:24:58 2002
+++ php4/ext/pgsql/tests/10pg_convert.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,16 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_convert.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
+$converted = pg_convert($db, $table_name, $fields);
+
+var_dump($converted);
?>
--EXPECT--
array(3) {
Index: php4/ext/pgsql/tests/11pg_meta_data.phpt
diff -u php4/ext/pgsql/tests/11pg_meta_data.phpt:1.1
php4/ext/pgsql/tests/11pg_meta_data.phpt:1.1.2.1
--- php4/ext/pgsql/tests/11pg_meta_data.phpt:1.1 Tue Oct 1 22:11:27 2002
+++ php4/ext/pgsql/tests/11pg_meta_data.phpt Sat May 31 08:59:19 2003
@@ -4,7 +4,15 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_meta_data.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$meta = pg_meta_data($db, $table_name);
+
+var_dump($meta);
?>
--EXPECT--
array(3) {
Index: php4/ext/pgsql/tests/12pg_insert.phpt
diff -u php4/ext/pgsql/tests/12pg_insert.phpt:1.2
php4/ext/pgsql/tests/12pg_insert.phpt:1.2.4.1
--- php4/ext/pgsql/tests/12pg_insert.phpt:1.2 Mon Apr 22 23:42:26 2002
+++ php4/ext/pgsql/tests/12pg_insert.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,17 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_insert.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
+
+pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
+echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
+
+echo "Ok\n";
?>
--EXPECT--
INSERT INTO php_pgsql_test (num,str,bin) VALUES (1234,'AAA','BBB');
Index: php4/ext/pgsql/tests/13pg_select.phpt
diff -u php4/ext/pgsql/tests/13pg_select.phpt:1.2
php4/ext/pgsql/tests/13pg_select.phpt:1.2.4.1
--- php4/ext/pgsql/tests/13pg_select.phpt:1.2 Mon Apr 22 23:42:26 2002
+++ php4/ext/pgsql/tests/13pg_select.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,19 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_select.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
+$ids = array('num'=>'1234');
+
+$res = pg_select($db, $table_name, $ids) or print "Error\n";
+var_dump($res);
+echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
+echo "Ok\n";
+
?>
--EXPECT--
array(1) {
Index: php4/ext/pgsql/tests/14pg_update.phpt
diff -u php4/ext/pgsql/tests/14pg_update.phpt:1.2
php4/ext/pgsql/tests/14pg_update.phpt:1.2.4.1
--- php4/ext/pgsql/tests/14pg_update.phpt:1.2 Mon Apr 22 23:42:26 2002
+++ php4/ext/pgsql/tests/14pg_update.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,18 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_update.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
+$ids = array('num'=>'1234');
+
+pg_update($db, $table_name, $fields, $ids) or print "Error in test 1\n";
+echo pg_update($db, $table_name, $fields, $ids, PGSQL_DML_STRING)."\n";
+
+echo "Ok\n";
?>
--EXPECT--
UPDATE php_pgsql_test SET num=1234,str='ABC',bin='XYZ' WHERE num=1234;
Index: php4/ext/pgsql/tests/15pg_delete.phpt
diff -u php4/ext/pgsql/tests/15pg_delete.phpt:1.1
php4/ext/pgsql/tests/15pg_delete.phpt:1.1.4.1
--- php4/ext/pgsql/tests/15pg_delete.phpt:1.1 Sun Apr 7 21:37:38 2002
+++ php4/ext/pgsql/tests/15pg_delete.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,20 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_delete.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$fields = array('num'=>'1234', 'str'=>'XXX', 'bin'=>'YYY');
+$ids = array('num'=>'1234');
+if (!pg_delete($db, $table_name, $ids)) {
+ echo "Error\n";
+}
+else {
+ echo "Ok\n";
+}
?>
--EXPECT--
Ok
Index: php4/ext/pgsql/tests/16pg_result_status.phpt
diff -u php4/ext/pgsql/tests/16pg_result_status.phpt:1.1
php4/ext/pgsql/tests/16pg_result_status.phpt:1.1.4.1
--- php4/ext/pgsql/tests/16pg_result_status.phpt:1.1 Sun Apr 7 21:37:38 2002
+++ php4/ext/pgsql/tests/16pg_result_status.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,15 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_result_status.inc");
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$sql = "SELECT * FROM ".$table_name." WHERE num = -2";
+$result = pg_query($db, "BEGIN;END");
+
+echo pg_result_status($result)."\n";
+echo pg_result_status($result, PGSQL_STATUS_STRING)."\n";
?>
--EXPECT--
1
Index: php4/ext/pgsql/tests/17result.phpt
diff -u php4/ext/pgsql/tests/17result.phpt:1.2
php4/ext/pgsql/tests/17result.phpt:1.2.2.1
--- php4/ext/pgsql/tests/17result.phpt:1.2 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/17result.phpt Sat May 31 08:59:20 2003
@@ -4,10 +4,26 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("result.inc");
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$sql = "SELECT * FROM $table_name";
+$result = pg_query($db, $sql) or die('Cannot qeury db');
+$rows = pg_num_rows($result);
+
+var_dump(pg_fetch_object($result, 1));
+var_dump(pg_fetch_array($result, 1));
+var_dump(pg_fetch_row($result, 1));
+var_dump(pg_fetch_assoc($result, 1));
+var_dump(pg_result_seek($result, 0));
+
+echo "Ok\n";
?>
--EXPECT--
-object(stdClass)(3) {
+object(stdClass)#1 (3) {
["num"]=>
string(1) "1"
["str"]=>
@@ -39,7 +55,7 @@
}
array(3) {
["num"]=>
- string(1) "2"
+ string(1) "1"
["str"]=>
string(3) "ABC"
["bin"]=>
Index: php4/ext/pgsql/tests/18pg_escape_bytea.phpt
diff -u php4/ext/pgsql/tests/18pg_escape_bytea.phpt:1.1
php4/ext/pgsql/tests/18pg_escape_bytea.phpt:1.1.2.1
--- php4/ext/pgsql/tests/18pg_escape_bytea.phpt:1.1 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/18pg_escape_bytea.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,26 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_escape_bytea.inc");
+// optional functions
+
+include('config.inc');
+
+$fp = fopen('php.gif', 'r');
+$image = fread($fp, filesize('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);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+ echo "NG";
+}
+else {
+ echo "OK";
+}
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/19pg_ping.phpt
diff -u php4/ext/pgsql/tests/19pg_ping.phpt:1.1
php4/ext/pgsql/tests/19pg_ping.phpt:1.1.2.1
--- php4/ext/pgsql/tests/19pg_ping.phpt:1.1 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/19pg_ping.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,12 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_ping.inc");
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+var_dump(pg_ping($db));
?>
--EXPECT--
bool(true)
Index: php4/ext/pgsql/tests/20pg_get_pid.phpt
diff -u php4/ext/pgsql/tests/20pg_get_pid.phpt:1.1
php4/ext/pgsql/tests/20pg_get_pid.phpt:1.1.2.1
--- php4/ext/pgsql/tests/20pg_get_pid.phpt:1.1 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/20pg_get_pid.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,14 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_get_pid.inc");
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+$pid = pg_get_pid($db);
+
+is_integer($pid) ? print 'OK' : print 'NG';
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/21pg_get_notify.phpt
diff -u php4/ext/pgsql/tests/21pg_get_notify.phpt:1.1
php4/ext/pgsql/tests/21pg_get_notify.phpt:1.1.2.1
--- php4/ext/pgsql/tests/21pg_get_notify.phpt:1.1 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/21pg_get_notify.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,17 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("pg_get_notify.inc");
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+pg_query($db, 'LISTEN test_msg');
+pg_query($db, 'NOTIFY test_msg');
+
+$msg = pg_get_notify($db);
+
+isset($msg['message'],$msg['pid']) ? print 'OK' : print 'NG';
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/98old_api.phpt
diff -u php4/ext/pgsql/tests/98old_api.phpt:1.1
php4/ext/pgsql/tests/98old_api.phpt:1.1.8.1
--- php4/ext/pgsql/tests/98old_api.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/98old_api.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,30 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("old_api.inc");
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+$result = pg_exec("SELECT * FROM ".$table_name);
+pg_numrows($result);
+pg_numfields($result);
+pg_fieldname($result, 0);
+pg_fieldsize($result, $field_name);
+pg_fieldtype($result, 0);
+pg_fieldprtlen($result, 0);
+pg_fieldisnull($result, 0);
+
+pg_result($result,0,0);
+$result = pg_exec("INSERT INTO ".$table_name." VALUES (7777, 'KKK')");
+$oid = pg_getlastoid($result);
+pg_freeresult($result);
+pg_errormessage();
+$result = pg_exec("UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
+pg_cmdtuples($result);
+
+
+
+echo "OK";
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/9999dropdb.phpt
diff -u php4/ext/pgsql/tests/9999dropdb.phpt:1.1
php4/ext/pgsql/tests/9999dropdb.phpt:1.1.8.1
--- php4/ext/pgsql/tests/9999dropdb.phpt:1.1 Sun Dec 16 19:16:48 2001
+++ php4/ext/pgsql/tests/9999dropdb.phpt Sat May 31 08:59:20 2003
@@ -4,7 +4,15 @@
<?php include("skipif.inc"); ?>
--FILE--
<?php
-include("dropdb.inc");
+// drop test table
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+pg_query($db, "DROP TABLE ".$table_name);
+
+echo "OK";
+
?>
--EXPECT--
OK
Index: php4/ext/pgsql/tests/README
diff -u php4/ext/pgsql/tests/README:1.1 php4/ext/pgsql/tests/README:1.1.2.1
--- php4/ext/pgsql/tests/README:1.1 Fri Oct 18 03:52:09 2002
+++ php4/ext/pgsql/tests/README Sat May 31 08:59:20 2003
@@ -1,14 +1,16 @@
-Test scripts assume:
+Test scripts assumes:
- PostgreSQL server is installed locally
- - there is a PostgreSQL account for the users running test script
+ - there is a PostgreSQL account for the users running the test scripts
- there is database named "test"
-For instance, if you login name is 'testuser', you should
-have PostgreSQL user account named 'testuser' and have 'test'
-database.
+For instance, if your login name is 'testuser', you should have PostgreSQL
+user account named 'testuser' and grant that user access to the database
+'test'.
-If you have account and database, type "createdb test" from
-command prompt to create database to execute test scripts.
+If you have account and database, type "createdb test" from command prompt
+to create the database to execute the test scripts. By executing the above
+command as the same user running the tests you ensure that the user is
+granted access to the database.
If you find problems in PostgreSQL module, please mail to
[EMAIL PROTECTED] or [EMAIL PROTECTED]
[EMAIL PROTECTED], [EMAIL PROTECTED] or [EMAIL PROTECTED]
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php