cvs: php4 /ext/pgsql pgsql.c php_pgsql.h
| From: | Yasuo Ohgaki | Date: | Sun, 13 Oct 2002 09:37:27 +0000 |
| Subject: | cvs: php4 /ext/pgsql pgsql.c php_pgsql.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-14886@lists.php.net to get a copy of this message | ||
yohgaki Sun Oct 13 05:37:27 2002 EDT
Modified files:
/php4/ext/pgsql pgsql.c php_pgsql.h
Log:
Introduce connect_type option to pg_connect().
pg_connect(conn_str, conn_type) is allowed.
@Added PGSQL_CONNECT_FORCE_NEW option to pg_connect() (Yasuo)
# If you have better idea about constant name(s), let me know.
Index: php4/ext/pgsql/pgsql.c
diff -u php4/ext/pgsql/pgsql.c:1.232 php4/ext/pgsql/pgsql.c:1.233
--- php4/ext/pgsql/pgsql.c:1.232 Sat Oct 12 23:00:47 2002
+++ php4/ext/pgsql/pgsql.c Sun Oct 13 05:37:27 2002
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.232 2002/10/13 03:00:47 yohgaki Exp $ */
+/* $Id: pgsql.c,v 1.233 2002/10/13 09:37:27 yohgaki Exp $ */
#include <stdlib.h>
@@ -381,6 +381,8 @@
le_result = zend_register_list_destructors_ex(_free_result, NULL, "pgsql result",
module_number);
le_lofp = zend_register_list_destructors_ex(_free_ptr, NULL, "pgsql large object",
module_number);
le_string = zend_register_list_destructors_ex(_free_ptr, NULL, "pgsql string",
module_number);
+ /* For connection option */
+ REGISTER_LONG_CONSTANT("PGSQL_CONNECT_FORCE_NEW", PGSQL_CONNECT_FORCE_NEW, CONST_CS |
CONST_PERSISTENT);
/* For pg_fetch_array() */
REGISTER_LONG_CONSTANT("PGSQL_ASSOC", PGSQL_ASSOC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PGSQL_NUM", PGSQL_NUM, CONST_CS | CONST_PERSISTENT);
@@ -489,9 +491,9 @@
PGconn *pgsql;
smart_str str = {0};
zval **args[5];
- int i;
+ int i, connect_type = 0;
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() == 2 || ZEND_NUM_ARGS() > 5
+ if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 5
|| zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -508,6 +510,9 @@
if (ZEND_NUM_ARGS() == 1) { /* new style, using connection string */
connstring = Z_STRVAL_PP(args[0]);
+ } else if (ZEND_NUM_ARGS() == 2 ) { /* Safe to add conntype_option, since 2 args was illegal */
+ convert_to_long_ex(args[1]);
+ connect_type = Z_LVAL_PP(args[1]);
} else {
host = Z_STRVAL_PP(args[0]);
port = Z_STRVAL_PP(args[1]);
@@ -596,7 +601,7 @@
pgsql = (PGconn *) le->ptr;
}
ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink);
- } else {
+ } else { // Non persistent connection
list_entry *index_ptr,new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists,
@@ -604,7 +609,8 @@
* if it doesn't, open a new pgsql link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
- if (zend_hash_find(&EG(regular_list),str.c,str.len+1,(void **) &index_ptr)==SUCCESS) {
+ if (!(connect_type & PGSQL_CONNECT_FORCE_NEW)
+ && zend_hash_find(&EG(regular_list),str.c,str.len+1,(void **)
&index_ptr)==SUCCESS) {
int type,link;
void *ptr;
@@ -678,7 +684,7 @@
/* }}} */
#endif
-/* {{{ proto resource pg_connect([string connection_string] | [string host, string port [, string
options [, string tty,]] string database)
+/* {{{ proto resource pg_connect(string connection_string[, int connect_type] | [string host,
string port [, string options [, string tty,]]] string database)
Open a PostgreSQL connection */
PHP_FUNCTION(pg_connect)
{
@@ -686,7 +692,7 @@
}
/* }}} */
-/* {{{ proto resource pg_pconnect([string connection_string] | [string host, string port [, string
options [, string tty,]] string database)
+/* {{{ proto resource pg_pconnect(string connection_string | [string host, string port [, string
options [, string tty,]]] string database)
Open a persistent PostgreSQL connection */
PHP_FUNCTION(pg_pconnect)
{
Index: php4/ext/pgsql/php_pgsql.h
diff -u php4/ext/pgsql/php_pgsql.h:1.53 php4/ext/pgsql/php_pgsql.h:1.54
--- php4/ext/pgsql/php_pgsql.h:1.53 Sat Oct 12 23:00:48 2002
+++ php4/ext/pgsql/php_pgsql.h Sun Oct 13 05:37:27 2002
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pgsql.h,v 1.53 2002/10/13 03:00:48 yohgaki Exp $ */
+/* $Id: php_pgsql.h,v 1.54 2002/10/13 09:37:27 yohgaki Exp $ */
#ifndef PHP_PGSQL_H
#define PHP_PGSQL_H
@@ -140,6 +140,8 @@
PHP_FUNCTION(pg_delete);
PHP_FUNCTION(pg_select);
+/* connection options - ToDo: Add async connection option */
+#define PGSQL_CONNECT_FORCE_NEW (1<<1)
/* php_pgsql_convert options */
#define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEAFULT value by removing field
from returned array */
#define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */