ext/odbc.c in ruby-odbc-0.99999 vs ext/odbc.c in ruby-odbc-0.999991

- old
+ new

@@ -1,16 +1,16 @@ /* * ODBC-Ruby binding - * Copyright (c) 2001-2015 Christian Werner <chw@ch-werner.de> + * Copyright (c) 2001-2020 Christian Werner <chw@ch-werner.de> * Portions copyright (c) 2004 Ryszard Niewisiewicz <micz@fibernet.pl> * Portions copyright (c) 2006 Carl Blakeley <cblakeley@openlinksw.co.uk> * * See the file "COPYING" for information on usage * and redistribution of this file and for a * DISCLAIMER OF ALL WARRANTIES. * - * $Id: odbc.c,v 1.79 2018/02/28 15:15:24 chw Exp chw $ + * $Id: odbc.c,v 1.80 2020/12/25 21:45:42 chw Exp chw $ */ #undef ODBCVER #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) @@ -20,10 +20,13 @@ #include <ctype.h> #include "ruby.h" #ifdef HAVE_VERSION_H #include "version.h" #endif +#ifdef HAVE_RUBY_VERSION_H +#include "ruby/version.h" +#endif #ifdef HAVE_SQL_H #include <sql.h> #else #error Missing include: sql.h #endif @@ -63,10 +66,16 @@ #if (RUBY_VERSION_MAJOR <= 1) && (RUBY_VERSION_MINOR < 9) #define TIME_USE_USEC 1 #endif +#if (RUBY_API_VERSION_CODE >= 20500) +#define FUNCALL_NOARGS(o, m) rb_funcall((o), (m), 0) +#else +#define FUNCALL_NOARGS(o, m) rb_funcall((o), (m), 0, NULL) +#endif + #ifdef HAVE_RUBY_THREAD_H #include "ruby/thread.h" #endif /* @@ -1822,11 +1831,11 @@ } static void start_gc() { - rb_funcall(rb_mGC, IDstart, 0, NULL); + FUNCALL_NOARGS(rb_mGC, IDstart); } static void mark_dbc(DBC *p) { @@ -1897,10 +1906,11 @@ "SQLError"); state[6] = '\0'; msg[SQL_MAX_MESSAGE_LENGTH - 1] = '\0'; switch (err) { case SQL_SUCCESS: + case SQL_SUCCESS_WITH_INFO: #ifdef UNICODE v = uc_str_new2(state); #else v = rb_str_new2((char *) state); #endif @@ -2511,11 +2521,11 @@ } astr = rb_str_new2(""); if (rb_obj_is_kind_of(attr, rb_cHash) == Qtrue) { VALUE a, x; - a = rb_funcall(attr, IDkeys, 0, NULL); + a = FUNCALL_NOARGS(attr, IDkeys); while ((x = rb_ary_shift(a)) != Qnil) { VALUE v = rb_hash_aref(attr, x); astr = rb_str_concat(astr, x); astr = rb_str_cat2(astr, "="); @@ -3016,11 +3026,11 @@ if (rb_obj_is_kind_of(drv, Cdrv) == Qtrue) { VALUE d, a, x; d = rb_str_new2(""); - a = rb_funcall(rb_iv_get(drv, "@attrs"), IDkeys, 0, NULL); + a = FUNCALL_NOARGS(rb_iv_get(drv, "@attrs"), IDkeys); while ((x = rb_ary_shift(a)) != Qnil) { VALUE v = rb_hash_aref(rb_iv_get(drv, "@attrs"), x); d = rb_str_concat(d, x); d = rb_str_cat2(d, "="); @@ -4236,10 +4246,26 @@ type = SQL_C_UBIGINT; size = sizeof (SQLBIGINT); } break; #endif + case SQL_DECIMAL: + case SQL_NUMERIC: + if ((size == 0) || (size > SEGSIZE)) { + size = SQL_NO_TOTAL; + } + if (size != SQL_NO_TOTAL) { + size += 2; /* sign and decimal point */ + size += 1; /* NUL terminator */ + } +#ifdef UNICODE + type = SQL_C_WCHAR; + size *= sizeof (SQLWCHAR); +#else + type = SQL_C_CHAR; +#endif + break; default: if ((size == 0) || (size > SEGSIZE)) { size = SQL_NO_TOTAL; } #ifdef UNICODE @@ -5093,11 +5119,11 @@ dbc_commit(self); return ret; } ret = rb_ary_entry(a, 1); rb_exc_raise(rb_exc_new3(rb_obj_class(ret), - rb_funcall(ret, IDto_s, 0, 0))); + FUNCALL_NOARGS(ret, IDto_s))); return Qnil; } /* *---------------------------------------------------------------------- @@ -5658,20 +5684,20 @@ } if (rb_obj_is_kind_of(y, rb_cTime) == Qtrue) { if (argc > 1) { rb_raise(rb_eArgError, "wrong # arguments"); } - d = rb_funcall(y, IDday, 0, NULL); - m = rb_funcall(y, IDmonth, 0, NULL); - y = rb_funcall(y, IDyear, 0, NULL); + d = FUNCALL_NOARGS(y, IDday); + m = FUNCALL_NOARGS(y, IDmonth); + y = FUNCALL_NOARGS(y, IDyear); } else if (rb_obj_is_kind_of(y, rb_cDate) == Qtrue) { if (argc > 1) { rb_raise(rb_eArgError, "wrong # arguments"); } - d = rb_funcall(y, IDmday, 0, NULL); - m = rb_funcall(y, IDmonth, 0, NULL); - y = rb_funcall(y, IDyear, 0, NULL); + d = FUNCALL_NOARGS(y, IDmday); + m = FUNCALL_NOARGS(y, IDmonth); + y = FUNCALL_NOARGS(y, IDyear); } else if ((argc == 1) && (rb_obj_is_kind_of(y, rb_cString) == Qtrue)) { if (date_load1(self, y, 0) != Qnil) { return self; } } @@ -5893,13 +5919,13 @@ } if (rb_obj_is_kind_of(h, rb_cTime) == Qtrue) { if (argc > 1) { rb_raise(rb_eArgError, "wrong # arguments"); } - s = rb_funcall(h, IDsec, 0, NULL); - m = rb_funcall(h, IDmin, 0, NULL); - h = rb_funcall(h, IDhour, 0, NULL); + s = FUNCALL_NOARGS(h, IDsec); + m = FUNCALL_NOARGS(h, IDmin); + h = FUNCALL_NOARGS(h, IDhour); } else if ((argc == 1) && (rb_obj_is_kind_of(h, rb_cString) == Qtrue)) { if (time_load1(self, h, 0) != Qnil) { return self; } } @@ -6133,29 +6159,29 @@ } if (rb_obj_is_kind_of(y, rb_cTime) == Qtrue) { if (argc > 1) { rb_raise(rb_eArgError, "wrong # arguments"); } - f = rb_funcall(y, IDusec, 0, NULL); - ss = rb_funcall(y, IDsec, 0, NULL); - mm = rb_funcall(y, IDmin, 0, NULL); - hh = rb_funcall(y, IDhour, 0, NULL); - d = rb_funcall(y, IDday, 0, NULL); - m = rb_funcall(y, IDmonth, 0, NULL); - y = rb_funcall(y, IDyear, 0, NULL); + f = FUNCALL_NOARGS(y, IDusec); + ss = FUNCALL_NOARGS(y, IDsec); + mm = FUNCALL_NOARGS(y, IDmin); + hh = FUNCALL_NOARGS(y, IDhour); + d = FUNCALL_NOARGS(y, IDday); + m = FUNCALL_NOARGS(y, IDmonth); + y = FUNCALL_NOARGS(y, IDyear); f = INT2NUM(NUM2INT(f) * 1000); } else if (rb_obj_is_kind_of(y, rb_cDate) == Qtrue) { if (argc > 1) { rb_raise(rb_eArgError, "wrong # arguments"); } f = INT2FIX(0); ss = INT2FIX(0); mm = INT2FIX(0); hh = INT2FIX(0); - d = rb_funcall(y, IDmday, 0, NULL); - m = rb_funcall(y, IDmonth, 0, NULL); - y = rb_funcall(y, IDyear, 0, NULL); + d = FUNCALL_NOARGS(y, IDmday); + m = FUNCALL_NOARGS(y, IDmonth); + y = FUNCALL_NOARGS(y, IDyear); } else if ((argc == 1) && (rb_obj_is_kind_of(y, rb_cString) == Qtrue)) { if (timestamp_load1(self, y, 0) != Qnil) { return self; } } @@ -6626,17 +6652,17 @@ if (q->dbcp != NULL && q->dbcp->rbtime == Qtrue) { VALUE now, frac; time = (TIME_STRUCT *) q->paraminfo[vnum].outbuf; frac = rb_float_new(0.0); - now = rb_funcall(rb_cTime, IDnow, 0, NULL); + now = FUNCALL_NOARGS(rb_cTime, IDnow); v = rb_funcall(rb_cTime, (q->dbcp->gmtime == Qtrue) ? IDutc : IDlocal, 7, - rb_funcall(now, IDyear, 0, NULL), - rb_funcall(now, IDmonth, 0, NULL), - rb_funcall(now, IDday, 0, NULL), + FUNCALL_NOARGS(now, IDyear), + FUNCALL_NOARGS(now, IDmonth), + FUNCALL_NOARGS(now, IDday), INT2NUM(time->hour), INT2NUM(time->minute), INT2NUM(time->second), frac); } else { @@ -7283,18 +7309,18 @@ if (q->dbcp != NULL && q->dbcp->rbtime == Qtrue) { VALUE now, frac; time = (TIME_STRUCT *) valp; frac = rb_float_new(0.0); - now = rb_funcall(rb_cTime, IDnow, 0, NULL); + now = FUNCALL_NOARGS(rb_cTime, IDnow); v = rb_funcall(rb_cTime, (q->dbcp->gmtime == Qtrue) ? IDutc : IDlocal, 7, - rb_funcall(now, IDyear, 0, NULL), - rb_funcall(now, IDmonth, 0, NULL), - rb_funcall(now, IDday, 0, NULL), + FUNCALL_NOARGS(now, IDyear), + FUNCALL_NOARGS(now, IDmonth), + FUNCALL_NOARGS(now, IDday), INT2NUM(time->hour), INT2NUM(time->minute), INT2NUM(time->second), frac); } else { @@ -8146,42 +8172,42 @@ TIME_STRUCT *time; ctype = SQL_C_TIME; time = (TIME_STRUCT *) valp; memset(time, 0, sizeof (TIME_STRUCT)); - time->hour = rb_funcall(arg, IDhour, 0, NULL); - time->minute = rb_funcall(arg, IDmin, 0, NULL); - time->second = rb_funcall(arg, IDsec, 0, NULL); + time->hour = FUNCALL_NOARGS(arg, IDhour); + time->minute = FUNCALL_NOARGS(arg, IDmin); + time->second = FUNCALL_NOARGS(arg, IDsec); rlen = 1; vlen = sizeof (TIME_STRUCT); } else if (q->paraminfo[pnum].type == SQL_DATE) { DATE_STRUCT *date; ctype = SQL_C_DATE; date = (DATE_STRUCT *) valp; memset(date, 0, sizeof (DATE_STRUCT)); - date->year = rb_funcall(arg, IDyear, 0, NULL); - date->month = rb_funcall(arg, IDmonth, 0, NULL); - date->day = rb_funcall(arg, IDday, 0, NULL); + date->year = FUNCALL_NOARGS(arg, IDyear); + date->month = FUNCALL_NOARGS(arg, IDmonth); + date->day = FUNCALL_NOARGS(arg, IDday); rlen = 1; vlen = sizeof (TIMESTAMP_STRUCT); } else { TIMESTAMP_STRUCT *ts; ctype = SQL_C_TIMESTAMP; ts = (TIMESTAMP_STRUCT *) valp; memset(ts, 0, sizeof (TIMESTAMP_STRUCT)); - ts->year = rb_funcall(arg, IDyear, 0, NULL); - ts->month = rb_funcall(arg, IDmonth, 0, NULL); - ts->day = rb_funcall(arg, IDday, 0, NULL); - ts->hour = rb_funcall(arg, IDhour, 0, NULL); - ts->minute = rb_funcall(arg, IDmin, 0, NULL); - ts->second = rb_funcall(arg, IDsec, 0, NULL); + ts->year = FUNCALL_NOARGS(arg, IDyear); + ts->month = FUNCALL_NOARGS(arg, IDmonth); + ts->day = FUNCALL_NOARGS(arg, IDday); + ts->hour = FUNCALL_NOARGS(arg, IDhour); + ts->minute = FUNCALL_NOARGS(arg, IDmin); + ts->second = FUNCALL_NOARGS(arg, IDsec); #ifdef TIME_USE_USEC - ts->fraction = rb_funcall(arg, IDusec, 0, NULL) * 1000; + ts->fraction = FUNCALL_NOARGS(arg, IDusec) * 1000; #else - ts->fraction = rb_funcall(arg, IDnsec, 0, NULL); + ts->fraction = FUNCALL_NOARGS(arg, IDnsec); #endif rlen = 1; vlen = sizeof (TIMESTAMP_STRUCT); } break; @@ -8190,13 +8216,13 @@ DATE_STRUCT *date; ctype = SQL_C_DATE; date = (DATE_STRUCT *) valp; memset(date, 0, sizeof (DATE_STRUCT)); - date->year = rb_funcall(arg, IDyear, 0, NULL); - date->month = rb_funcall(arg, IDmonth, 0, NULL); - date->day = rb_funcall(arg, IDmday, 0, NULL); + date->year = FUNCALL_NOARGS(arg, IDyear); + date->month = FUNCALL_NOARGS(arg, IDmonth); + date->day = FUNCALL_NOARGS(arg, IDmday); rlen = 1; vlen = sizeof (DATE_STRUCT); break; } ctype = SQL_C_CHAR; @@ -8706,11 +8732,11 @@ d = INT2NUM(date->day); } else { rb_raise(rb_eTypeError, "expecting ODBC::Date"); } } else { - VALUE now = rb_funcall(rb_cTime, IDnow, 0, NULL); + VALUE now = FUNCALL_NOARGS(rb_cTime, IDnow); y = rb_funcall(rb_cTime, IDyear, 1, now); m = rb_funcall(rb_cTime, IDmonth, 1, now); d = rb_funcall(rb_cTime, IDday, 1, now); } @@ -9296,10 +9322,10 @@ rb_define_method(Cstmt, "fetch_first!", stmt_fetch_first_bang, 0); rb_define_method(Cstmt, "fetch_scroll", stmt_fetch_scroll, -1); rb_define_method(Cstmt, "fetch_scroll!", stmt_fetch_scroll_bang, -1); rb_define_method(Cstmt, "fetch_hash", stmt_fetch_hash, -1); rb_define_method(Cstmt, "fetch_hash!", stmt_fetch_hash_bang, -1); - rb_define_method(Cstmt, "fetch_first_hash", stmt_fetch_first_hash, 0); + rb_define_method(Cstmt, "fetch_first_hash", stmt_fetch_first_hash, -1); rb_define_method(Cstmt, "fetch_many", stmt_fetch_many, 1); rb_define_method(Cstmt, "fetch_all", stmt_fetch_all, 0); rb_define_method(Cstmt, "each", stmt_each, 0); rb_define_method(Cstmt, "each_hash", stmt_each_hash, -1); rb_define_method(Cstmt, "execute", stmt_exec, -1);