DB2 interface for Ruby Milestone
I’ve completed my first pass at porting the PHP ibm_db2 extension to Ruby. If anyone out there has both Ruby and DB2 installed on a Unix machine, I would appreciate hearing if you can reproduce my results.
If you pick up the latest code and run it, you should now see
118 tests, 124 assertions, 0 failures, 0 errors
As the PHP extension I am porting was accompanied by 118 tests, this is significant.
The first thing to note is that I ran out of test cases before I ran out of code. Functions which were not ported due to a lack of test cases:
columnprivileges/column_privileges cursor_type field_precision field_scale foreignkeys/foreign_keys free_stmt primarykeys/primary_keys procedurecolumns/procedure_columns procedures setoption/set_option specialcolumns/special_columns statistics tableprivileges/table_privileges
So, at this point, all that can be said is that the code does
what the test test for. It might actually do quite a bit more
than that as much of the logic is largely untouched. Areas
where I likely injected bugs would be in language specific areas,
like binding obscure data types as
DB2::PARAM_INOUT.
Speaking of DB2::PARAM_INOUT, I had to work around
one problem with Ruby 1.8, as I could not successfully resolve
rb_dvar_asn at runtime.
void var_assign(char *name, VALUE value) {
#if TODO
// this compiles and links, but fails to resolve at runtime
rb_dvar_asgn(rb_intern(name_id), value);
#else
// so we do it the hard way
ID inspect;
char *expr, *statement;
long expr_len;
inspect = rb_intern("inspect");
value = rb_funcall(value, inspect, 0);
expr = rb_str2cstr(value, &expr_len);
statement = ALLOC_N(char, strlen(name)+1+expr_len+1);
strcpy(statement, name);
strcat(statement, "=");
strcat(statement, expr);
rb_eval_string(statement);
free(statement);
#endif
}
Sam & James,
Talk about synchronicity — we were talking in the lunchroom about a potential partner who might want to use our (Rails-based) application and is currently using a DB2-based product. We support Postgres and Oracle and know we’ll need to support SQLServer, but have no experience at all with DB2. I thought I’d take a look around to see what kind of Ruby support for DB2 there is (at all), but before that I did my weblog rounds (including intertwingly.net which I hadn’t visited in a few days) and found you talking about this very thing. Spooky.
Glad to see you’re the guys working on the driver.
Best,
Rick
Thanks again. The newer code worked.
But I guess I hit the next hurdle.
Loaded suite tests
Started
E
Finished in 5.230052 seconds.
1) Error:
default_test(TestIbmDb2):
NoMethodError: undefined method `prepare' for #<TestIbmDb2:0xb688d010>
tests.rb:32:in `setup'
1 tests, 0 assertions, 0 failures, 1 errors
anbu@GENTOO ~ $ ruby -r yaml -e 'p YAML::Syck::VERSION' "0.60"
Posted by Anbu at
That would indicate that your tests directory (/tmp/rubydb2/tests) is most likely empty. Which would make sense because php2ruby.rb has the same problem.
rmdir tests
In php2ruby.rb, change line 4 to:
pecl_dir = open('config.yml') {|f| YAML::load f}['source']['pecl_dir']
And then near the bottom of the file are two occurrences of pecl_dir.value. Change both to simply pecl_dir.
The final version of php2ruby.rb should look like this.
Finally, rerun rake.
Thank you for your patience in this.
Posted by Sam Ruby atIs there any possibility of a Windows version?
I don’t have access to (or enough knowledge of) C compilers to perform a compile myself.
Posted by John Unwin atCurrently we are evaluating Ruby on Rails with DB2. Its not a very complex application - just CRUD operations and 100+ users. We want to make sure Ruby’s DB2 driver is capable of doing that. I didn’t find enough test cases/results to support this. It would be great if you could post some more results, list of CLI operations supported and NOT supported,etc. A Windows version would be great! to make such decisions quickly.
thanks
Posted by babu atI didn’t find enough test cases/results to support this.
Forgive me for turning this around, but here are 118 tests, all in Ruby, and all pass. Can you be more specific about what you think is missing?
I’m not set up to produce a Windows version, but apparently some of the DB2 development team are following this weblog and perhaps they could help...
Posted by Sam Ruby at
Initial test run worked for me.
Posted by James Snel at