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.
This commit is contained in:
Yasuo Ohgaki 2002-10-13 09:37:27 +00:00
parent 96b9c0a523
commit 2c23e56c7f
2 changed files with 14 additions and 6 deletions

View file

@ -381,6 +381,8 @@ PHP_MINIT_FUNCTION(pgsql)
le_result = zend_register_list_destructors_ex(_free_result, NULL, "pgsql result", module_number); 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_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); 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() */ /* For pg_fetch_array() */
REGISTER_LONG_CONSTANT("PGSQL_ASSOC", PGSQL_ASSOC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PGSQL_ASSOC", PGSQL_ASSOC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PGSQL_NUM", PGSQL_NUM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PGSQL_NUM", PGSQL_NUM, CONST_CS | CONST_PERSISTENT);
@ -489,9 +491,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
PGconn *pgsql; PGconn *pgsql;
smart_str str = {0}; smart_str str = {0};
zval **args[5]; 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) { || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
WRONG_PARAM_COUNT; WRONG_PARAM_COUNT;
} }
@ -508,6 +510,9 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (ZEND_NUM_ARGS() == 1) { /* new style, using connection string */ if (ZEND_NUM_ARGS() == 1) { /* new style, using connection string */
connstring = Z_STRVAL_PP(args[0]); 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 { } else {
host = Z_STRVAL_PP(args[0]); host = Z_STRVAL_PP(args[0]);
port = Z_STRVAL_PP(args[1]); port = Z_STRVAL_PP(args[1]);
@ -596,7 +601,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
pgsql = (PGconn *) le->ptr; pgsql = (PGconn *) le->ptr;
} }
ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink); ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink);
} else { } else { // Non persistent connection
list_entry *index_ptr,new_index_ptr; list_entry *index_ptr,new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists, /* first we check the hash for the hashed_details key. if it exists,
@ -604,7 +609,8 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
* if it doesn't, open a new pgsql link, add it to the resource list, * 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. * 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; int type,link;
void *ptr; void *ptr;
@ -678,7 +684,7 @@ static int php_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS)
/* }}} */ /* }}} */
#endif #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 */ Open a PostgreSQL connection */
PHP_FUNCTION(pg_connect) PHP_FUNCTION(pg_connect)
{ {
@ -686,7 +692,7 @@ PHP_FUNCTION(pg_connect)
} }
/* }}} */ /* }}} */
/* {{{ 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 */ Open a persistent PostgreSQL connection */
PHP_FUNCTION(pg_pconnect) PHP_FUNCTION(pg_pconnect)
{ {

View file

@ -140,6 +140,8 @@ PHP_FUNCTION(pg_update);
PHP_FUNCTION(pg_delete); PHP_FUNCTION(pg_delete);
PHP_FUNCTION(pg_select); PHP_FUNCTION(pg_select);
/* connection options - ToDo: Add async connection option */
#define PGSQL_CONNECT_FORCE_NEW (1<<1)
/* php_pgsql_convert options */ /* 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_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 */ #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */