swift 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/swift.cc +6 -3
- data/swift.gemspec +1 -1
- data/test/test_io.rb +8 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/ext/swift.cc
CHANGED
@@ -13,6 +13,7 @@ static VALUE cResultSet;
|
|
13
13
|
static VALUE cPool;
|
14
14
|
static VALUE cRequest;
|
15
15
|
static VALUE cBigDecimal;
|
16
|
+
static VALUE cStringIO;
|
16
17
|
|
17
18
|
static VALUE eRuntimeError;
|
18
19
|
static VALUE eArgumentError;
|
@@ -118,7 +119,7 @@ void static inline rb_extract_bind_params(int argc, VALUE* argv, std::vector<dbi
|
|
118
119
|
VALUE arg = argv[i];
|
119
120
|
if (arg == Qnil)
|
120
121
|
bind.push_back(dbi::PARAM(dbi::null()));
|
121
|
-
else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue) {
|
122
|
+
else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue || rb_obj_is_kind_of(arg, cStringIO) == Qtrue) {
|
122
123
|
arg = rb_funcall(arg, fRead, 0);
|
123
124
|
bind.push_back(dbi::PARAM_BINARY((unsigned char*)RSTRING_PTR(arg), RSTRING_LEN(arg)));
|
124
125
|
}
|
@@ -429,7 +430,7 @@ VALUE rb_field_typecast(VALUE adapter, int type, const char *data, ulong len) {
|
|
429
430
|
case DBI_TYPE_INT:
|
430
431
|
return rb_cstr2inum(data, 10);
|
431
432
|
case DBI_TYPE_BLOB:
|
432
|
-
return rb_str_new(data, len);
|
433
|
+
return rb_funcall(cStringIO, fNew, 1, rb_str_new(data, len));
|
433
434
|
// forcing UTF8 convention here - do we really care about people using non utf8
|
434
435
|
// client encodings and databases ?
|
435
436
|
case DBI_TYPE_TEXT:
|
@@ -644,7 +645,7 @@ VALUE rb_cpool_execute(int argc, VALUE *argv, VALUE self) {
|
|
644
645
|
VALUE arg = rb_ary_entry(args, n);
|
645
646
|
if (arg == Qnil)
|
646
647
|
bind.push_back(dbi::PARAM(dbi::null()));
|
647
|
-
else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue) {
|
648
|
+
else if (rb_obj_is_kind_of(arg, rb_cIO) == Qtrue || rb_obj_is_kind_of(arg, cStringIO) == Qtrue) {
|
648
649
|
arg = rb_funcall(arg, fRead, 0);
|
649
650
|
bind.push_back(dbi::PARAM_BINARY((unsigned char*)RSTRING_PTR(arg), RSTRING_LEN(arg)));
|
650
651
|
}
|
@@ -686,6 +687,7 @@ VALUE rb_request_process(VALUE self) {
|
|
686
687
|
extern "C" {
|
687
688
|
void Init_swift(void) {
|
688
689
|
rb_require("bigdecimal");
|
690
|
+
rb_require("stringio");
|
689
691
|
|
690
692
|
fNew = rb_intern("new");
|
691
693
|
fStringify = rb_intern("to_s");
|
@@ -697,6 +699,7 @@ extern "C" {
|
|
697
699
|
eArgumentError = CONST_GET(rb_mKernel, "ArgumentError");
|
698
700
|
eStandardError = CONST_GET(rb_mKernel, "StandardError");
|
699
701
|
cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal");
|
702
|
+
cStringIO = CONST_GET(rb_mKernel, "StringIO");
|
700
703
|
eConnectionError = rb_define_class("ConnectionError", eRuntimeError);
|
701
704
|
|
702
705
|
mSwift = rb_define_module("Swift");
|
data/swift.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{swift}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shane Hanna", "Bharanee 'Barney' Rathna"]
|
data/test/test_io.rb
CHANGED
@@ -14,12 +14,16 @@ describe 'Adapter' do
|
|
14
14
|
it 'stores and retrieves an image' do
|
15
15
|
Swift.db do |db|
|
16
16
|
io = File.open(File.dirname(__FILE__) + '/house-explode.jpg')
|
17
|
-
db.prepare(
|
18
|
-
|
17
|
+
db.prepare('insert into users (name, image) values(?, ?)').execute('test', io)
|
18
|
+
|
19
|
+
blob = db.prepare('select image from users limit 1').execute.first[:image]
|
19
20
|
|
20
21
|
io.rewind
|
21
|
-
|
22
|
-
|
22
|
+
assert_kind_of StringIO, blob
|
23
|
+
|
24
|
+
data = blob.read
|
25
|
+
assert_equal Encoding::ASCII_8BIT, data.encoding
|
26
|
+
assert_equal io.read.force_encoding('ASCII-8BIT'), data
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|