Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new query cancel functions of PostgreSQL-17 #614

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/gvl_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ PGresult *PQclosePortal(PGconn *conn, const char *portalName){return NULL;}
int PQsendClosePrepared(PGconn *conn, const char *stmtName){return 0;}
int PQsendClosePortal(PGconn *conn, const char *portalName){return 0;}
int PQsendPipelineSync(PGconn *conn){return 0;}
int PQcancelBlocking(PGcancelConn *cancelConn){return 0;}
int PQcancelStart(PGcancelConn *cancelConn){return 0;}
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn){return PGRES_POLLING_FAILED;}
#endif
#ifndef HAVE_PQENTERPIPELINEMODE
int PQpipelineSync(PGconn *conn){return 0;}
Expand Down
11 changes: 11 additions & 0 deletions ext/gvl_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# include RUBY_EXTCONF_H
#endif

#ifndef HAVE_PQSETCHUNKEDROWSMODE
typedef struct pg_cancel_conn PGcancelConn;
#endif

#define DEFINE_PARAM_LIST1(type, name) \
name,

Expand Down Expand Up @@ -217,6 +221,10 @@

#define FOR_EACH_PARAM_OF_PQisBusy(param)

#define FOR_EACH_PARAM_OF_PQcancelBlocking(param)
#define FOR_EACH_PARAM_OF_PQcancelStart(param)
#define FOR_EACH_PARAM_OF_PQcancelPoll(param)

#define FOR_EACH_PARAM_OF_PQencryptPasswordConn(param) \
param(PGconn *, conn) \
param(const char *, passwd) \
Expand Down Expand Up @@ -260,6 +268,9 @@
function(PQsendPipelineSync, GVL_TYPE_NONVOID, int, PGconn *, conn) \
function(PQsetClientEncoding, GVL_TYPE_NONVOID, int, const char *, encoding) \
function(PQisBusy, GVL_TYPE_NONVOID, int, PGconn *, conn) \
function(PQcancelBlocking, GVL_TYPE_NONVOID, int, PGcancelConn *, conn) \
function(PQcancelStart, GVL_TYPE_NONVOID, int, PGcancelConn *, conn) \
function(PQcancelPoll, GVL_TYPE_NONVOID, PostgresPollingStatusType, PGcancelConn *, conn) \
function(PQencryptPasswordConn, GVL_TYPE_NONVOID, char *, const char *, algorithm) \
function(PQcancel, GVL_TYPE_NONVOID, int, int, errbufsize);

Expand Down
5 changes: 5 additions & 0 deletions ext/pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ Init_pg_ext(void)
/* Checking if server is in standby mode. Available since PostgreSQL-14. */
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_STANDBY", INT2FIX(CONNECTION_CHECK_STANDBY));
#endif
#if PG_MAJORVERSION_NUM >= 17
/* Waiting for connection attempt to be started. Available since PostgreSQL-17. */
rb_define_const(rb_mPGconstants, "CONNECTION_ALLOCATED", INT2FIX(CONNECTION_ALLOCATED));
#endif

/****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/

Expand Down Expand Up @@ -689,4 +693,5 @@ Init_pg_ext(void)
init_pg_copycoder();
init_pg_recordcoder();
init_pg_tuple();
init_pg_cancon();
}
10 changes: 8 additions & 2 deletions ext/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ typedef struct {
/* enable automatic flushing of send data at the end of send_query calls */
unsigned int flush_data : 1;

#if defined(_WIN32)
/* File descriptor to be used for rb_w32_unwrap_io_handle() */
int ruby_sd;
#endif
} t_pg_connection;

typedef struct pg_coder t_pg_coder;
Expand Down Expand Up @@ -305,6 +303,7 @@ void init_pg_text_decoder _(( void ));
void init_pg_binary_encoder _(( void ));
void init_pg_binary_decoder _(( void ));
void init_pg_tuple _(( void ));
void init_pg_cancon _(( void ));
VALUE lookup_error_class _(( const char * ));
VALUE pg_bin_dec_bytea _(( t_pg_coder*, const char *, int, int, int, int ));
VALUE pg_text_dec_string _(( t_pg_coder*, const char *, int, int, int, int ));
Expand Down Expand Up @@ -344,6 +343,13 @@ void pg_typemap_compact _(( void * ));
PGconn *pg_get_pgconn _(( VALUE ));
t_pg_connection *pg_get_connection _(( VALUE ));
VALUE pgconn_block _(( int, VALUE *, VALUE ));
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
NORETURN(void pg_raise_conn_error _(( VALUE klass, VALUE self, const char *format, ...)));
VALUE pg_wrap_socket_io _(( int sd, VALUE self, VALUE *p_socket_io, int *p_ruby_sd ));
void pg_unwrap_socket_io _(( VALUE self, VALUE *p_socket_io, int ruby_sd ));


VALUE pg_new_result _(( PGresult *, VALUE ));
VALUE pg_new_result_autoclear _(( PGresult *, VALUE ));
Expand Down
Loading
Loading