Permalink
Browse files

Handle infinite dates using Database#convert_infinite_timestamps, bum…

…p version to 1.6.5
  • Loading branch information...
1 parent a9afad3 commit 641854d72e7cd280e1adc22ae797aedc02e493a9 @jeremyevans committed Mar 6, 2013
Showing with 20 additions and 16 deletions.
  1. +4 −0 CHANGELOG
  2. +15 −15 ext/sequel_pg/sequel_pg.c
  3. +1 −1 sequel_pg.gemspec
View
@@ -1,3 +1,7 @@
+=== 1.6.5 (2013-03-06)
+
+* Handle infinite dates using Database#convert_infinite_timestamps (jeremyevans)
+
=== 1.6.4 (2013-01-14)
* Remove type conversion of int2vector and money types on PostgreSQL, since previous conversions were wrong (jeremyevans) (#8)
@@ -268,25 +268,25 @@ static VALUE spg_time(const char *s) {
return rb_funcall(spg_SQLTime, spg_id_local, 7, rb_funcall(now, spg_id_year, 0), rb_funcall(now, spg_id_month, 0), rb_funcall(now, spg_id_day, 0), INT2NUM(hour), INT2NUM(minute), INT2NUM(second), INT2NUM(usec));
}
-static VALUE spg_date(const char *s) {
- int year, month, day;
-
- if(3 != sscanf(s, "%d-%2d-%2d", &year, &month, &day)) {
- rb_raise(rb_eArgError, "unexpected date format");
- }
-
- return rb_funcall(spg_Date, spg_id_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
-}
-
-static VALUE spg_timestamp_error(const char *s, VALUE self) {
+static VALUE spg_timestamp_error(const char *s, VALUE self, const char *error_msg) {
VALUE db;
db = rb_funcall(self, spg_id_db, 0);
if(RTEST(rb_funcall(db, spg_id_convert_infinite_timestamps, 0))) {
if((strcmp(s, "infinity") == 0) || (strcmp(s, "-infinity") == 0)) {
return rb_funcall(db, spg_id_infinite_timestamp_value, 1, rb_tainted_str_new2(s));
}
}
- rb_raise(rb_eArgError, "unexpected datetime format");
+ rb_raise(rb_eArgError, error_msg);
+}
+
+static VALUE spg_date(const char *s, VALUE self) {
+ int year, month, day;
+
+ if(3 != sscanf(s, "%d-%2d-%2d", &year, &month, &day)) {
+ return spg_timestamp_error(s, self, "unexpected date format");
+ }
+
+ return rb_funcall(spg_Date, spg_id_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
}
static VALUE spg_timestamp(const char *s, VALUE self) {
@@ -306,7 +306,7 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
&usec_start, &usec, &usec_stop,
&offset_sign, &offset_hour, &offset_minute);
if(tokens < 7) {
- return spg_timestamp_error(s, self);
+ return spg_timestamp_error(s, self, "unexpected datetime format");
}
usec *= (int) pow(10, (6 - (usec_stop - usec_start)));
} else {
@@ -318,7 +318,7 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
min = 0;
sec = 0;
} else if (tokens < 6) {
- return spg_timestamp_error(s, self);
+ return spg_timestamp_error(s, self, "unexpected datetime format");
}
usec = 0;
}
@@ -474,7 +474,7 @@ static VALUE spg__col_value(VALUE self, PGresult *res, long i, long j, VALUE* co
rv = rb_funcall(spg_BigDecimal, spg_id_new, 1, rb_str_new(v, PQgetlength(res, i, j)));
break;
case 1082: /* date */
- rv = spg_date(v);
+ rv = spg_date(v, self);
break;
case 1083: /* time */
case 1266:
View
@@ -1,6 +1,6 @@
SEQUEL_PG_GEMSPEC = Gem::Specification.new do |s|
s.name = 'sequel_pg'
- s.version = '1.6.4'
+ s.version = '1.6.5'
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"]

0 comments on commit 641854d

Please sign in to comment.