JDBC connectivity using ruby not jruby - ruby

Is there any gem available to Connect to JDBC DB2 for the Ruby project. I have come across activerecord-jdbc-adapter but it works only for Jruby.
Also can i use Jruby specific gem in Ruby? I have Ruby 2.2 and Jruby 9.0.0 in my machine

Did it using two other gems which was mentioned in one site.
We need Sequel and ibm_db gems and ran the below code, it worked
require 'rubygems'
require 'sequel'
require 'ibm_db'
Sequel.connect("ibmdb://#{username}:#{password}##{db_url}") do |db|
db.fetch(selectquery) do |row|
puts row
end
end

Related

Problems with ruby 'unroller' gem

I'm having a problem using unroller. I have installed the gem and wrote this simple program to help focus on the problem i'm having:
#!/usr/bin/ruby
require 'rubygems'
require 'unroller'
Unroller::trace
def foo(p1, p2)
puts p1
puts p2
end
foo("param1", "param2")
Running the program yields:
/Library/Ruby/Gems/1.8/gems/facets-2.9.3/lib/core/facets/filetest/separator_pattern.rb:5: warning: already initialized constant SEPARATOR_PATTERN
/Library/Ruby/Gems/1.8/gems/facets-2.9.3/lib/core/facets/string/bracket.rb:3: warning: already initialized constant BRA2KET
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- facets/methodspace (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from /Library/Ruby/Gems/1.8/gems/unroller-1.0.0/lib/unroller.rb:4
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from ./ut:4
My ruby version is ruby 1.8.7 (2011-12-28 patchlevel 357). I also installed ruby on my Windows development box and get the same error and that ruby version is 1.9.3 so it does not appear to be related to the version of Ruby I'm on.
Anyone have any ideas?
Thanks very much in advance!
jon
This is a bug of unroller gem, described here: https://github.com/TylerRick/unroller/issues/1. unroller automatically requires the latest version of facets gem and the version 2.9 breaks it. (BTW gems should never use '>=' when loading dependencies, that's why '~>' is for.)
It's not that difficult to hotfix locally by using bundler and hardcoding facets gem to specific version before requiring unroller (so the specific facets version gets loaded instead of latest 2.9).
create Gemfile:
source 'http://rubygems.org'
gem 'facets', '2.8.4'
gem 'termios' # you're gonna need this gem too, for some reason
gem 'unroller'
run bundle install and then either run the script by bundle exec ruby test.rb or require bundler/setup in it:
require 'rubygems'
require 'bundler/setup'
require 'unroller'
...
UPDATE: or if you don't wanna deal with bundler, try this first, it could work too:
require 'rubygems'
gem 'facets', '2.8.4'
require 'unroller'
...

bundler and ruby 1.9.2

Why am I not able to use these lines in a Gemfile:
gem 'date'
gem 'pp'
Must these be required in file instead like this:
require 'date'
require 'pp'
Or is there a way to mix them into your Gemfile so they are available project wide?
I think that date and pp are part of ruby 1.9.2 core and as a result are different from regular gems but I don't exactly understand why...
Because those are not Gems but part of the Ruby standard library. But the standard library isnt loaded by default, hence the require statements

Problem when requiring 'Qt4' in Ruby 1.8.7

I have successfully installed:
Ruby 1.8.7-p334
Rubygems 1.7.2
rake 0.9.0
qtruby4 2.1.0 mswin32
Now the following block of code
require 'rubygems'
require 'Qt4'
gives me an error:
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:926:in report_activate_error': RubyGem version error: qtruby4(2.1.0 not >= 0) (Gem::LoadError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:244:inactivate_dep'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:236:in activate'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:213:intry_activate'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:56:in `require'
from C:/Users/nick/Documents/NetBeansProjects/RubyApplication2/lib/main.rb:4
Everything good when requiring just 'rubygems'. My OS is Windows 7.
Make sure you require correct gem name
require 'Qt4' seems like little different as almost all the ruby gem names are in simple letters
isnt your gem name 'qtruby4' by any chance, if so try
require 'rubygems'
require 'qtruby4'
HTH
sameera

Can't stop Sinatra using Ctrl+C when `require 'coffee-script'`

I'm running Ruby 1.9.2p180 on Ubuntu 11.04 64-bit.
I have the simplest possible CoffeeScript example using Sinatra which runs fine, but doesn't stop when I press the Ctrl+C shortcut. So every time I have to kill -9 and it's getting quite tedious.
The app.rb:
require 'sinatra'
require 'coffee-script'
get '/' do
'<script src="/app.js" type="text/javascript"></script>'
end
get '/app.js' do
coffee :app
end
The views/app.coffee:
alert 'Foo'
It works on Ruby 1.8.7 with minor modifications:
require 'rubygems'
require 'sinatra'
require 'coffee-script'
require 'json'
get '/' do
'<script src="/app.js" type="text/javascript"></script>'
end
get '/app.js' do
coffee :app
end
It also works on 1.9.2 when I remove the line require 'coffee-script', but gives me a warning:
WARN: tilt autoloading 'coffee_script' in a non thread-safe way; explicit require 'coffee_script' suggested.
Figured out that it works when using therubyracer, but fails on node. The version 0.1.97 from Ubuntu 10.10 repositories is the only exception. When using the 0.2.6 from Natty, it fails and also when installing the latest (0.4.8) using nvm, I wasn't able to install 0.1.97 via nvm.
Unable to replicate. I'm on a Mac (OS 10.6.7) running bash and Ruby 1.9.2p180. I don't get your tilt warning, either.
I also haven't experienced this problem when using The Middleman (Sinatra-based) or Rails 3.1; both use the same coffee-script gem (as does Tilt; I suspect the coffee_script is just a typo).
Have you tried updating all the pertinent gems (sinatra, coffee-script, tilt, execjs) to their latest versions? What JS environment do you have on your system (e.g. do you have node, or are you relying on therubyracer)?
On Ruby 1.9.2, Sinatra 1.3.2, CoffeeScript 2.2.0 and Node 0.6.2 this does not occur anymore.

Manually connect to PostgreSQL with Ruby

Connecting to postgres with rails was no big deal. rails -d postgresql app_name, setup the database.yml and voila. I cannot, however, use postgres with just a little test script
I've tried installing the gems postgres, dbi & dbd-pg, pg, and ruby-pg, but with pg/ruby-pg and postgres it fails at the require for require 'postgres' or require 'pg'. With require 'dbi' I get past the require, but it can't load the driver....so how is rails doing it with the same set of packages? In fact I removed all the afore mentioned and found I only needed the 'pg' gem for everything to work fine with rails. Any advice?
Are you remembering to add a require 'rubygems' to your source, or invoke ruby with a -rubygems argument, or add RUBYOPT=rubygems to your environment? You need to do one of those to actually load the gem machinery that allows require to find your gems.

Resources