Skip to content

Commit

Permalink
Fix bug #5313
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Jul 3, 2024
1 parent 25561e5 commit f6b47a0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ static PGresult *swoole_pgsql_get_result(PGconn *conn) {
}

PGconn *swoole_pgsql_connectdb(const char *conninfo) {
if (swoole_pgsql_blocking) {
return PQconnectdb(conninfo);
}

PGconn *conn = PQconnectStart(conninfo);
if (conn == nullptr) {
return nullptr;
Expand Down Expand Up @@ -116,6 +120,10 @@ PGconn *swoole_pgsql_connectdb(const char *conninfo) {

PGresult *swoole_pgsql_prepare(
PGconn *conn, const char *stmt_name, const char *query, int n_params, const Oid *param_types) {
if (swoole_pgsql_blocking) {
return PQprepare(conn, stmt_name, query, n_params, param_types);
}

swoole_trace_log(SW_TRACE_CO_PGSQL, "PQsendPrepare(conn=%p, stmt_name='%s')", conn, stmt_name);
int ret = PQsendPrepare(conn, stmt_name, query, n_params, param_types);
if (ret == 0) {
Expand All @@ -136,6 +144,9 @@ PGresult *swoole_pgsql_exec_prepared(PGconn *conn,
const int *param_lengths,
const int *param_formats,
int result_format) {
if (swoole_pgsql_blocking) {
return PQexecPrepared(conn, stmt_name, n_params, param_values, param_lengths, param_formats, result_format);
}
swoole_trace_log(SW_TRACE_CO_PGSQL, "PQsendQueryPrepared(conn=%p, stmt_name='%s')", conn, stmt_name);
int ret = PQsendQueryPrepared(conn, stmt_name, n_params, param_values, param_lengths, param_formats, result_format);
if (ret == 0) {
Expand All @@ -150,6 +161,10 @@ PGresult *swoole_pgsql_exec_prepared(PGconn *conn,
}

PGresult *swoole_pgsql_exec(PGconn *conn, const char *query) {
if (swoole_pgsql_blocking) {
return PQexec(conn, query);
}

swoole_trace_log(SW_TRACE_CO_PGSQL, "PQsendQuery(conn=%p, query='%s')", conn, query);
int ret = PQsendQuery(conn, query);
if (ret == 0) {
Expand All @@ -171,6 +186,10 @@ PGresult *swoole_pgsql_exec_params(PGconn *conn,
const int *param_lengths,
const int *param_formats,
int result_format) {
if (swoole_pgsql_blocking) {
return PQexecParams(conn, command, n_params, param_types, param_values, param_lengths, param_formats, result_format);
}

swoole_trace_log(SW_TRACE_CO_PGSQL, "PQsendQueryParams(conn=%p, command='%s')", conn, command);
int ret = PQsendQueryParams(
conn, command, n_params, param_types, param_values, param_lengths, param_formats, result_format);
Expand All @@ -190,7 +209,8 @@ void swoole_pgsql_set_blocking(bool blocking) {
}

void php_swoole_pgsql_minit(int module_id) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("PGSQL_ATTR_DISABLE_PREPARES")) == nullptr) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("PGSQL_ATTR_DISABLE_PREPARES")) ==
nullptr) {
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_ATTR_DISABLE_PREPARES", PDO_PGSQL_ATTR_DISABLE_PREPARES);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_IDLE", (zend_long) PGSQL_TRANSACTION_IDLE);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_ACTIVE", (zend_long) PGSQL_TRANSACTION_ACTIVE);
Expand Down

0 comments on commit f6b47a0

Please sign in to comment.