mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/pdo_pgsql: object initialisation, using smart_str api instead. (#14679)
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "php_pdo_pgsql.h"
|
||||
#include "php_pdo_pgsql_int.h"
|
||||
#include "zend_exceptions.h"
|
||||
#include "zend_smart_str.h"
|
||||
#include "pgsql_driver_arginfo.h"
|
||||
|
||||
static bool pgsql_handle_in_transaction(pdo_dbh_t *dbh);
|
||||
@@ -1329,8 +1330,9 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
{
|
||||
pdo_pgsql_db_handle *H;
|
||||
int ret = 0;
|
||||
char *conn_str, *p, *e;
|
||||
char *p, *e;
|
||||
zend_string *tmp_user, *tmp_pass;
|
||||
smart_str conn_str = {0};
|
||||
zend_long connect_timeout = 30;
|
||||
|
||||
H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent);
|
||||
@@ -1361,18 +1363,20 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
tmp_user = !strstr((char *) dbh->data_source, "user=") ? _pdo_pgsql_escape_credentials(dbh->username) : NULL;
|
||||
tmp_pass = !strstr((char *) dbh->data_source, "password=") ? _pdo_pgsql_escape_credentials(dbh->password) : NULL;
|
||||
|
||||
smart_str_appends(&conn_str, dbh->data_source);
|
||||
smart_str_append_printf(&conn_str, " connect_timeout=" ZEND_LONG_FMT, connect_timeout);
|
||||
|
||||
/* support both full connection string & connection string + login and/or password */
|
||||
if (tmp_user && tmp_pass) {
|
||||
spprintf(&conn_str, 0, "%s user='%s' password='%s' connect_timeout=" ZEND_LONG_FMT, (char *) dbh->data_source, ZSTR_VAL(tmp_user), ZSTR_VAL(tmp_pass), connect_timeout);
|
||||
} else if (tmp_user) {
|
||||
spprintf(&conn_str, 0, "%s user='%s' connect_timeout=" ZEND_LONG_FMT, (char *) dbh->data_source, ZSTR_VAL(tmp_user), connect_timeout);
|
||||
} else if (tmp_pass) {
|
||||
spprintf(&conn_str, 0, "%s password='%s' connect_timeout=" ZEND_LONG_FMT, (char *) dbh->data_source, ZSTR_VAL(tmp_pass), connect_timeout);
|
||||
} else {
|
||||
spprintf(&conn_str, 0, "%s connect_timeout=" ZEND_LONG_FMT, (char *) dbh->data_source, connect_timeout);
|
||||
if (tmp_user) {
|
||||
smart_str_append_printf(&conn_str, " user='%s'", ZSTR_VAL(tmp_user));
|
||||
}
|
||||
|
||||
H->server = PQconnectdb(conn_str);
|
||||
if (tmp_pass) {
|
||||
smart_str_append_printf(&conn_str, " password='%s'", ZSTR_VAL(tmp_pass));
|
||||
}
|
||||
smart_str_0(&conn_str);
|
||||
|
||||
H->server = PQconnectdb(ZSTR_VAL(conn_str.s));
|
||||
H->lob_streams = (HashTable *) pemalloc(sizeof(HashTable), dbh->is_persistent);
|
||||
zend_hash_init(H->lob_streams, 0, NULL, NULL, 1);
|
||||
|
||||
@@ -1383,7 +1387,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
|
||||
zend_string_release_ex(tmp_pass, 0);
|
||||
}
|
||||
|
||||
efree(conn_str);
|
||||
smart_str_free(&conn_str);
|
||||
|
||||
if (PQstatus(H->server) != CONNECTION_OK) {
|
||||
pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE);
|
||||
|
||||
Reference in New Issue
Block a user