Skip to content

Commit

Permalink
Fix bug #5313 (#5394)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman authored Jul 4, 2024
1 parent 4860011 commit cd3b627
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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 Down

0 comments on commit cd3b627

Please sign in to comment.