ext/odbc.c in ruby-odbc-0.99997 vs ext/odbc.c in ruby-odbc-0.99998

- old
+ new

@@ -6,11 +6,11 @@ * * 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.77 2015/04/15 06:03:11 chw Exp chw $ + * $Id: odbc.c,v 1.78 2017/02/15 10:04:30 chw Exp chw $ */ #undef ODBCVER #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) @@ -4121,14 +4121,14 @@ static COLTYPE * make_coltypes(SQLHSTMT hstmt, int ncols, char **msgp) { int i; COLTYPE *ret = NULL; - SQLLEN type, size = 0; for (i = 0; i < ncols; i++) { SQLUSMALLINT ic = i + 1; + SQLLEN type = SQL_UNKNOWN_TYPE, size = 0; if (!succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_TYPE, NULL, 0, NULL, &type), @@ -4150,10 +4150,11 @@ } return NULL; } for (i = 0; i < ncols; i++) { SQLUSMALLINT ic = i + 1; + SQLLEN type = SQL_UNKNOWN_TYPE, size = 0; callsql(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_TYPE, NULL, 0, NULL, &type), @@ -4507,11 +4508,11 @@ static VALUE make_column(SQLHSTMT hstmt, int i, int upc, int use_scn) { VALUE obj, v; SQLUSMALLINT ic = i + 1; - SQLLEN iv = 0; + SQLLEN iv; #ifdef UNICODE SQLWCHAR name[SQL_MAX_MESSAGE_LENGTH]; #else char name[SQL_MAX_MESSAGE_LENGTH]; #endif @@ -4579,20 +4580,22 @@ #else v = rb_tainted_str_new2(name); #endif } rb_iv_set(obj, "@table", v); + iv = SQL_UNKNOWN_TYPE; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_TYPE, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_TYPE)")) { v = INT2NUM(iv); } else { v = INT2NUM(SQL_UNKNOWN_TYPE); } rb_iv_set(obj, "@type", v); v = Qnil; + iv = 0; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, #if (ODBCVER >= 0x0300) SQL_DESC_LENGTH, #else @@ -4614,51 +4617,57 @@ NULL, "SQLColAttributes(SQL_COLUMN_DISPLAY_SIZE)")) { v = INT2NUM(iv); } rb_iv_set(obj, "@length", v); v = Qnil; + iv = SQL_NO_NULLS; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_NULLABLE, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_NULLABLE)")) { v = (iv == SQL_NO_NULLS) ? Qfalse : Qtrue; } rb_iv_set(obj, "@nullable", v); v = Qnil; + iv = 0; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_SCALE, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_SCALE)")) { v = INT2NUM(iv); } rb_iv_set(obj, "@scale", v); v = Qnil; + iv = 0; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_PRECISION, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_PRECISION)")) { v = INT2NUM(iv); } rb_iv_set(obj, "@precision", v); v = Qnil; + iv = SQL_UNSEARCHABLE; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_SEARCHABLE, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_SEARCHABLE)")) { - v = (iv == SQL_NO_NULLS) ? Qfalse : Qtrue; + v = (iv == SQL_UNSEARCHABLE) ? Qfalse : Qtrue; } rb_iv_set(obj, "@searchable", v); v = Qnil; + iv = SQL_FALSE; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_UNSIGNED, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_UNSIGNED)")) { - v = (iv == SQL_NO_NULLS) ? Qfalse : Qtrue; + v = (iv == SQL_FALSE) ? Qfalse : Qtrue; } rb_iv_set(obj, "@unsigned", v); v = Qnil; #ifdef SQL_COLUMN_AUTO_INCREMENT + iv = SQL_FALSE; if (succeeded(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, SQLColAttributes(hstmt, ic, SQL_COLUMN_AUTO_INCREMENT, NULL, 0, NULL, &iv), NULL, "SQLColAttributes(SQL_COLUMN_AUTO_INCREMENT)")) { v = (iv == SQL_FALSE) ? Qfalse : Qtrue; @@ -5218,16 +5227,20 @@ static VALUE do_option(int argc, VALUE *argv, VALUE self, int isstmt, int op) { DBC *p = NULL; STMT *q = NULL; - VALUE val, val2, vstr; + VALUE val, val2 = Qnil; SQLINTEGER v; char *msg; int level = isstmt ? OPT_LEVEL_STMT : OPT_LEVEL_DBC; - rb_scan_args(argc, argv, (op == -1) ? "11" : "01", &val, &val2); + if (op == -1) { + rb_scan_args(argc, argv, "11", &val, &val2); + } else { + rb_scan_args(argc, argv, "01", &val); + } if (isstmt) { Data_Get_Struct(self, STMT, q); if (q->dbc == Qnil) { rb_raise(Cerror, "%s", set_err("Stale ODBC::Statement", 0)); } @@ -5239,9 +5252,10 @@ if (p->hdbc == SQL_NULL_HDBC) { rb_raise(Cerror, "%s", set_err("No connection", 0)); } } if (op == -1) { + VALUE vstr; char *string; int i, op_found = 0; switch (TYPE(val)) { default: