Skip to content

Commit

Permalink
Work with pg 1.2.1+, bump version to 1.12.4
Browse files Browse the repository at this point in the history
Use the new pg_get_result_enc_idx to get the encoding index for
the PG::Result instance if using ruby-pg > 1.2.

Explicitly exclude the use of pg 1.2.0 in the gemspec, since there
is no support for it.
  • Loading branch information
jeremyevans committed Jan 2, 2020
1 parent 19fe1cf commit 3fb8afb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
=== 1.12.4 (2020-01-02)

* Work with pg 1.2.1+ (jeremyevans)

=== 1.12.3 (2020-01-02)

* Warn and do not load sequel_pg if pg >1.2 is used (jeremyevans)
Expand Down
11 changes: 6 additions & 5 deletions ext/sequel_pg/sequel_pg.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define SEQUEL_PG_VERSION_INTEGER 11203
#define SEQUEL_PG_VERSION_INTEGER 11204

#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -72,8 +72,10 @@
/* External functions defined by ruby-pg */
PGconn* pg_get_pgconn(VALUE);
PGresult* pgresult_get(VALUE);
int pg_get_result_enc_idx(VALUE);

static int spg_use_ipaddr_alloc;
static int spg_use_pg_get_result_enc_idx;

static VALUE spg_Sequel;
static VALUE spg_PGArray;
Expand Down Expand Up @@ -1387,7 +1389,7 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
}
res = pgresult_get(rres);

enc_index = enc_get_index(rres);
enc_index = spg_use_pg_get_result_enc_idx ? pg_get_result_enc_idx(rres) : enc_get_index(rres);

ntuples = PQntuples(res);
nfields = PQnfields(res);
Expand Down Expand Up @@ -1655,7 +1657,7 @@ static VALUE spg__yield_each_row(VALUE self) {
rb_funcall(rres, spg_id_check, 0);
res = pgresult_get(rres);

enc_index = enc_get_index(rres);
enc_index = spg_use_pg_get_result_enc_idx ? pg_get_result_enc_idx(rres) : enc_get_index(rres);

/* Only handle regular and model types. All other types require compiling all
* of the results at once, which is not a use case for streaming. The streaming
Expand Down Expand Up @@ -1760,8 +1762,7 @@ void Init_sequel_pg(void) {
}

if (RTEST(rb_eval_string("defined?(PG::VERSION) && PG::VERSION.to_f >= 1.2"))) {
rb_warn("sequel_pg not loaded as it is not compatible with the ruby-pg version in use; uninstall sequel_pg or downgrade pg to 1.1.4");
return;
spg_use_pg_get_result_enc_idx = 1;
}

rb_const_set(spg_Postgres, rb_intern("SEQUEL_PG_VERSION_INTEGER"), INT2FIX(SEQUEL_PG_VERSION_INTEGER));
Expand Down
2 changes: 1 addition & 1 deletion sequel_pg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SEQUEL_PG_GEMSPEC = Gem::Specification.new do |s|
s.files = %w(MIT-LICENSE CHANGELOG README.rdoc Rakefile ext/sequel_pg/extconf.rb ext/sequel_pg/sequel_pg.c lib/sequel_pg/sequel_pg.rb lib/sequel/extensions/pg_streaming.rb)
s.license = 'MIT'
s.extensions << 'ext/sequel_pg/extconf.rb'
s.add_dependency("pg", [">= 0.18.0"])
s.add_dependency("pg", [">= 0.18.0", "!= 1.2.0"])
s.add_dependency("sequel", [">= 4.38.0"])
s.metadata = {
'bug_tracker_uri' => 'https://github.com/jeremyevans/sequel_pg/issues',
Expand Down

0 comments on commit 3fb8afb

Please sign in to comment.