ext/pool.cc in swift-0.6.1 vs ext/pool.cc in swift-0.7.0
- old
+ new
@@ -16,19 +16,14 @@
Data_Get_Struct(self, dbi::ConnectionPool, pool);
if (!pool) rb_raise(eSwiftRuntimeError, "Invalid object, did you forget to call #super ?");
return pool;
}
-// TODO: Remove unnecessary assignments. See Adapter.
VALUE pool_init(VALUE self, VALUE n, VALUE options) {
VALUE db = rb_hash_aref(options, ID2SYM(rb_intern("db")));
- VALUE host = rb_hash_aref(options, ID2SYM(rb_intern("host")));
- VALUE port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
VALUE user = rb_hash_aref(options, ID2SYM(rb_intern("user")));
VALUE driver = rb_hash_aref(options, ID2SYM(rb_intern("driver")));
- VALUE password = rb_hash_aref(options, ID2SYM(rb_intern("password")));
- VALUE zone = rb_hash_aref(options, ID2SYM(rb_intern("timezone")));
if (NIL_P(db)) rb_raise(eSwiftArgumentError, "Pool#new called without :db");
if (NIL_P(driver)) rb_raise(eSwiftArgumentError, "#new called without :driver");
user = NIL_P(user) ? rb_str_new2(getlogin()) : user;
@@ -37,24 +32,32 @@
try {
DATA_PTR(self) = new dbi::ConnectionPool(
NUM2INT(n),
CSTRING(driver),
CSTRING(user),
- CSTRING(password),
+ CSTRING(rb_hash_aref(options, ID2SYM(rb_intern("password")))),
CSTRING(db),
- CSTRING(host),
- CSTRING(port)
+ CSTRING(rb_hash_aref(options, ID2SYM(rb_intern("host")))),
+ CSTRING(rb_hash_aref(options, ID2SYM(rb_intern("port"))))
);
+
+ rb_iv_set(self, "@timezone", rb_hash_aref(options, ID2SYM(rb_intern("timezone"))));
}
CATCH_DBI_EXCEPTIONS();
+
return Qnil;
}
-void pool_callback(dbi::AbstractResultSet *result) {
+void pool_callback(dbi::AbstractResult *result) {
VALUE callback = (VALUE)result->context;
- // NOTE ResultSet will be free'd by the underlying connection pool dispatcher ib dbic++
- if (!NIL_P(callback)) rb_proc_call(callback, rb_ary_new3(1, Data_Wrap_Struct(cSwiftResult, 0, 0, result)));
+
+ // NOTE: C Result object will be deallocated in dbic++
+ if (!NIL_P(callback)) {
+ VALUE obj = result_wrap_handle(cSwiftResult, 0, result, false);
+ rb_iv_set(obj, "@timezone", rb_iv_get(callback, "@timezone"));
+ rb_proc_call(callback, rb_ary_new3(1, obj));
+ }
}
VALUE pool_execute(int argc, VALUE *argv, VALUE self) {
int n;
VALUE sql;
@@ -63,14 +66,18 @@
VALUE request = Qnil;
dbi::ConnectionPool *pool = pool_handle(self);
rb_scan_args(argc, argv, "1*&", &sql, &bind_values, &callback);
- if (NIL_P(callback)) rb_raise(eSwiftArgumentError, "No block given in Pool#execute");
+ // The only way to pass timezone to the C callback routine.
+ if (NIL_P(callback))
+ rb_raise(eSwiftArgumentError, "No block given in Pool#execute");
+ else
+ rb_iv_set(callback, "@timezone", rb_iv_get(self, "@timezone"));
try {
Query query;
- query_bind_values(&query, bind_values);
+ query_bind_values(&query, bind_values, pool->driver());
request = request_alloc(cSwiftRequest);
DATA_PTR(request) = pool->execute(CSTRING(sql), query.bind, pool_callback, (void*)callback);
return request;
}
CATCH_DBI_EXCEPTIONS();