ext/swift.cc in swift-0.4.1 vs ext/swift.cc in swift-0.4.2

- old
+ new

@@ -11,10 +11,11 @@ static VALUE cStatement; static VALUE cResultSet; static VALUE cPool; static VALUE cRequest; static VALUE cBigDecimal; +static VALUE cStringIO; static VALUE eRuntimeError; static VALUE eArgumentError; static VALUE eStandardError; static VALUE eConnectionError; @@ -116,11 +117,11 @@ void static inline rb_extract_bind_params(int argc, VALUE* argv, std::vector<dbi::Param> &bind) { for (int i = 0; i < argc; i++) { VALUE arg = argv[i]; if (arg == Qnil) bind.push_back(dbi::PARAM(dbi::null())); - else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue) { + else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue || rb_obj_is_kind_of(arg, cStringIO) == Qtrue) { arg = rb_funcall(arg, fRead, 0); bind.push_back(dbi::PARAM_BINARY((unsigned char*)RSTRING_PTR(arg), RSTRING_LEN(arg))); } else { arg = OBJ2STRING(arg); @@ -427,11 +428,11 @@ case DBI_TYPE_BOOLEAN: return strcmp(data, "t") == 0 || strcmp(data, "1") == 0 ? Qtrue : Qfalse; case DBI_TYPE_INT: return rb_cstr2inum(data, 10); case DBI_TYPE_BLOB: - return rb_str_new(data, len); + return rb_funcall(cStringIO, fNew, 1, rb_str_new(data, len)); // forcing UTF8 convention here - do we really care about people using non utf8 // client encodings and databases ? case DBI_TYPE_TEXT: return rb_enc_str_new(data, len, rb_utf8_encoding()); case DBI_TYPE_TIME: @@ -642,11 +643,11 @@ dbi::ResultRow bind; for (n = 0; n < RARRAY_LEN(args); n++) { VALUE arg = rb_ary_entry(args, n); if (arg == Qnil) bind.push_back(dbi::PARAM(dbi::null())); - else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue) { + else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue || rb_obj_is_kind_of(arg, cStringIO) == Qtrue) { arg = rb_funcall(arg, fRead, 0); bind.push_back(dbi::PARAM_BINARY((unsigned char*)RSTRING_PTR(arg), RSTRING_LEN(arg))); } else { arg = OBJ2STRING(arg); @@ -684,10 +685,11 @@ } extern "C" { void Init_swift(void) { rb_require("bigdecimal"); + rb_require("stringio"); fNew = rb_intern("new"); fStringify = rb_intern("to_s"); fLoad = rb_intern("load"); fRead = rb_intern("read"); @@ -695,9 +697,10 @@ eRuntimeError = CONST_GET(rb_mKernel, "RuntimeError"); eArgumentError = CONST_GET(rb_mKernel, "ArgumentError"); eStandardError = CONST_GET(rb_mKernel, "StandardError"); cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal"); + cStringIO = CONST_GET(rb_mKernel, "StringIO"); eConnectionError = rb_define_class("ConnectionError", eRuntimeError); mSwift = rb_define_module("Swift"); cAdapter = rb_define_class_under(mSwift, "Adapter", rb_cObject); cStatement = rb_define_class_under(mSwift, "Statement", rb_cObject);