ext/tiny_tds/result.c in tiny_tds-0.2.1 vs ext/tiny_tds/result.c in tiny_tds-0.2.2
- old
+ new
@@ -1,14 +1,15 @@
#include <tiny_tds_ext.h>
VALUE cTinyTdsResult;
extern VALUE mTinyTds, cTinyTdsClient, cTinyTdsError;
-VALUE cBigDecimal, cDate, cDateTime, cRational;
+VALUE cBigDecimal, cDate, cDateTime;
VALUE opt_decimal_zero, opt_float_zero, opt_one, opt_zero, opt_four, opt_19hdr, opt_tenk, opt_onemil;
+int opt_ruby_186;
static ID intern_new, intern_utc, intern_local, intern_localtime, intern_merge,
- intern_civil, intern_new_offset, intern_plus, intern_divide;
+ intern_civil, intern_new_offset, intern_plus, intern_divide, intern_Rational;
static ID sym_symbolize_keys, sym_as, sym_array, sym_cache_rows, sym_first, sym_timezone, sym_local, sym_utc;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *binaryEncoding;
#define ENCODED_STR_NEW(_data, _len) ({ \
@@ -135,12 +136,12 @@
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(val, binaryEncoding);
#endif
break;
case 36: { // SYBUNIQUE
- char converted_unique[36];
- dbconvert(rwrap->client, coltype, data, data_len, SYBVARCHAR, (BYTE *)converted_unique, sizeof(converted_unique));
+ char converted_unique[37];
+ dbconvert(rwrap->client, coltype, data, 37, SYBVARCHAR, (BYTE *)converted_unique, -1);
val = ENCODED_STR_NEW2(converted_unique);
break;
}
case SYBDATETIME4: {
DBDATETIME new_data;
@@ -162,16 +163,18 @@
VALUE offset = (timezone == intern_local) ? rwrap->local_offset : opt_zero;
/* Use DateTime */
if (year < 1902 || year+month+day > 2058) {
VALUE datetime_sec = INT2NUM(sec);
if (msec != 0) {
- #ifdef HAVE_RUBY_ENCODING_H
- VALUE rational_msec = rb_Rational2(INT2NUM(msec*1000), opt_onemil);
- #else
- VALUE rational_msec = rb_funcall(cRational, intern_new, 2, INT2NUM(msec*1000), opt_onemil);
- #endif
- datetime_sec = rb_funcall(datetime_sec, intern_plus, 1, rational_msec);
+ if ((opt_ruby_186 == 0 && sec < 59) || (opt_ruby_186 != 0 )) {
+ #ifdef HAVE_RUBY_ENCODING_H
+ VALUE rational_msec = rb_Rational2(INT2NUM(msec*1000), opt_onemil);
+ #else
+ VALUE rational_msec = rb_funcall(rb_cObject, intern_Rational, 2, INT2NUM(msec*1000), opt_onemil);
+ #endif
+ datetime_sec = rb_funcall(datetime_sec, intern_plus, 1, rational_msec);
+ }
}
val = rb_funcall(cDateTime, intern_civil, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), datetime_sec, offset);
val = rb_funcall(val, intern_new_offset, 1, offset);
/* Use Time */
} else {
@@ -369,11 +372,10 @@
void init_tinytds_result() {
/* Data Classes */
cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
cDate = rb_const_get(rb_cObject, rb_intern("Date"));
cDateTime = rb_const_get(rb_cObject, rb_intern("DateTime"));
- cRational = rb_const_get(rb_cObject, rb_intern("Rational"));
/* Define TinyTds::Result */
cTinyTdsResult = rb_define_class_under(mTinyTds, "Result", rb_cObject);
/* Define TinyTds::Result Public Methods */
rb_define_method(cTinyTdsResult, "each", rb_tinytds_result_each, -1);
rb_define_method(cTinyTdsResult, "fields", rb_tinytds_result_fields, 0);
@@ -389,10 +391,11 @@
intern_localtime = rb_intern("localtime");
intern_civil = rb_intern("civil");
intern_new_offset = rb_intern("new_offset");
intern_plus = rb_intern("+");
intern_divide = rb_intern("/");
+ intern_Rational = rb_intern("Rational");
/* Symbol Helpers */
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
sym_as = ID2SYM(rb_intern("as"));
sym_array = ID2SYM(rb_intern("array"));
sym_cache_rows = ID2SYM(rb_intern("cache_rows"));
@@ -409,9 +412,11 @@
opt_zero = INT2NUM(0);
opt_four = INT2NUM(4);
opt_19hdr = INT2NUM(1900);
opt_tenk = INT2NUM(10000);
opt_onemil = INT2NUM(1000000);
+ /* Ruby version flags */
+ opt_ruby_186 = strcmp(ruby_version, "1.8.6");
/* Encoding */
#ifdef HAVE_RUBY_ENCODING_H
binaryEncoding = rb_enc_find("binary");
#endif
}