Permalink
Browse files

Check Sequel compatibility before overwriting methods, supported in S…

…equel 4.44.0+
  • Loading branch information...
1 parent 4681104 commit 59c89dfab28d38cfc40472f4b6c4fc65dae136d5 @jeremyevans committed Feb 6, 2017
Showing with 13 additions and 2 deletions.
  1. +2 −0 CHANGELOG
  2. +11 −2 ext/sequel_pg/sequel_pg.c
View
@@ -1,5 +1,7 @@
=== HEAD
+* Check Sequel compatibility before overwriting methods, supported in Sequel 4.44.0+ (jeremyevans)
+
* Remove verbose mode warnings (jeremyevans)
=== 1.6.17 (2016-04-29)
@@ -1020,6 +1020,17 @@ void Init_sequel_pg(void) {
VALUE c, spg_Postgres;
ID cg;
cg = rb_intern("const_get");
+
+ spg_Sequel = rb_funcall(rb_cObject, cg, 1, rb_str_new2("Sequel"));
+ spg_Postgres = rb_funcall(spg_Sequel, cg, 1, rb_str_new2("Postgres"));
+
+ if(rb_obj_respond_to(spg_Postgres, rb_intern("sequel_pg_version_supported?"), 0)) {
+ if(!RTEST(rb_funcall(spg_Postgres, rb_intern("sequel_pg_version_supported?"), 1, INT2FIX(SEQUEL_PG_VERSION_INTEGER)))) {
+ rb_warn("sequel_pg not loaded as it is not compatible with the Sequel version in use; install the latest version of sequel_pg or uninstall sequel_pg");
+ return;
+ }
+ }
+
spg_id_new = rb_intern("new");
spg_id_local = rb_intern("local");
spg_id_year = rb_intern("year");
@@ -1062,12 +1073,10 @@ void Init_sequel_pg(void) {
spg_sym__sequel_pg_type = ID2SYM(rb_intern("_sequel_pg_type"));
spg_sym__sequel_pg_value = ID2SYM(rb_intern("_sequel_pg_value"));
- spg_Sequel = rb_funcall(rb_cObject, cg, 1, rb_str_new2("Sequel"));
spg_Blob = rb_funcall(rb_funcall(spg_Sequel, cg, 1, rb_str_new2("SQL")), cg, 1, rb_str_new2("Blob"));
spg_SQLTime= rb_funcall(spg_Sequel, cg, 1, rb_str_new2("SQLTime"));
spg_BigDecimal = rb_funcall(rb_cObject, cg, 1, rb_str_new2("BigDecimal"));
spg_Date = rb_funcall(rb_cObject, cg, 1, rb_str_new2("Date"));
- spg_Postgres = rb_funcall(spg_Sequel, cg, 1, rb_str_new2("Postgres"));
spg_PGError = rb_funcall(rb_cObject, cg, 1, rb_str_new2("PGError"));
spg_nan = rb_eval_string("0.0/0.0");

0 comments on commit 59c89df

Please sign in to comment.