Connecting to Oracle using OCI8 and DBI


#1

Hi,
I need to access an Oracla database with Ruby. I’ve loaded OCI8 and DBI.
When I run a simple script to just check on the existence of an image in
the database, I get a DBI interface error, and, this:

Exception: Could not load driver (unitialized constant OCI8::Driver)

Can someone help?
Thanks a lot,
Peter


#2

On Mon, Apr 13, 2009 at 9:35 PM, Peter B. removed_email_address@domain.invalid wrote:

Hi,
I need to access an Oracla database with Ruby. I’ve loaded OCI8 and DBI.
When I run a simple script to just check on the existence of an image in
the database, I get a DBI interface error, and, this:

Exception: Could not load driver (unitialized constant OCI8::Driver)

What version of ruby, ruby-dbi and ruby-oci8 do you use?
How did you install ruby-dbi and ruby-oci8?


#3

Takehiro Kubo wrote:

On Mon, Apr 13, 2009 at 9:35 PM, Peter B. removed_email_address@domain.invalid wrote:

Hi,
I need to access an Oracla database with Ruby. I’ve loaded OCI8 and DBI.
When I run a simple script to just check on the existence of an image in
the database, I get a DBI interface error, and, this:

Exception: Could not load driver (unitialized constant OCI8::Driver)

What version of ruby, ruby-dbi and ruby-oci8 do you use?
How did you install ruby-dbi and ruby-oci8?

Thanks,
I’m using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it’s
the latest. And, I downloaded and installed the latest version of oci8,
for Windows.

A colleague of mine suggested that, for my purposes, I can just use http
to query my database. So, I’ve done that and it works. But, I would like
to understand better how to actually get into the database, because, in
the future, I could foresee needing to actually pull files from it.


#4

Hi,

On Wed, Apr 15, 2009 at 12:09 AM, Peter B. removed_email_address@domain.invalid wrote:

Exception: Could not load driver (unitialized constant OCI8::Driver)

Did you manually edit dbi.rb?
The OCI8 Driver defines DBI::DBD::OCI8::Driver, but not OCI8::Driver.

What version of ruby, ruby-dbi and ruby-oci8 do you use?
How did you install ruby-dbi and ruby-oci8?

Thanks,
I’m using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it’s
the latest. And, I downloaded and installed the latest version of oci8,
for Windows.

ruby-dbi 0.4.1?
ruby-oci8 2.0.1 or 1.0.5?

Could you tell me the result of the following command on the irb
console?

require ‘dbi’
DBI::VERSION
require ‘oci8’
OCI8::VERSION
dbd_dr = DBI::DBD.const_get(:OCI8)
dbd_dr::Driver.new
DBI.connect(‘dbi:OCI8:’, ‘username’, ‘password’)

Copy and paste the output as follows:

c:> irb
irb(main):001:0> require ‘dbi’
=> true
irb(main):002:0> DBI::VERSION
=> “0.4.1”
irb(main):003:0> require ‘oci8’
=> true
irb(main):004:0> OCI8::VERSION
=> “2.0.1”
irb(main):005:0> dbd_dr = DBI::DBD.const_get(:OCI8)
=> DBI::DBD::OCI8
irb(main):006:0> dbd_dr::Driver.new
=> #DBI::DBD::OCI8::Driver:0xf7a1bb3c
irb(main):007:0> DBI.connect(‘dbi:OCI8:’, ‘username’, ‘password’)
=> #<DBI::DatabaseHandle:0xf7a13310 @driver_name=“OCI8”,
@trace_mode=nil, @convert_types=true,
@handle=#<DBI::DBD::OCI8::Database:0xf7a13220 @attr={},
@handle=#OCI8:RUBY>, @trace_output=nil>
irb(main):008:0>


#5

DBI is version 0.1.1.
OCI8 is version 1.0.5


#6

On Wed, Apr 15, 2009 at 10:34 PM, Peter B. removed_email_address@domain.invalid wrote:

DBI is version 0.1.1.
OCI8 is version 1.0.5

Thanks.
What about other information I requested in my previous reply?


#7

Takehiro Kubo wrote:

On Wed, Apr 15, 2009 at 10:34 PM, Peter B. removed_email_address@domain.invalid wrote:

DBI is version 0.1.1.
OCI8 is version 1.0.5

Thanks.
What about other information I requested in my previous reply?

F:\workflows\graphics>irb
irb(main):001:0> require ‘dbi’
=> true
irb(main):002:0> require ‘oci8’
=> true
irb(main):003:0> dbd_dr = DBI::DBD.const_get(:OCI8)
=> OCI8
irb(main):004:0> dbd_dr::Driver.new
NameError: uninitialized constant OCI8::Driver
from (irb):4
irb(main):005:0> DBI.conect(‘dbi::OCI8:’, ‘orcauser’, ‘orca2user’)
NoMethodError: undefined method `conect’ for DBI:Module
from (irb):5
irb(main):006:0>


#8

On Wed, Apr 15, 2009 at 11:26 PM, Peter B. removed_email_address@domain.invalid wrote:

Takehiro Kubo wrote:

On Wed, Apr 15, 2009 at 10:34 PM, Peter B. removed_email_address@domain.invalid wrote:

DBI is version 0.1.1.

The latest dbi is 0.4.1. You would use dbi bundled with One Click Ruby
Installer.

irb(main):003:0> dbd_dr = DBI::DBD.const_get(:OCI8)
=> OCI8

I have thought that DBI::DBD.const_get(:OCI8) would return
DBI::DBD::OCI8 and
it would raise an exception if DBI::DBD::OCI8 is not defined. But it
returns OCI8
if DBI::DBD::OCI8 is not found. I have misunderstood.

irb(main):004:0> dbd_dr::Driver.new
NameError: uninitialized constant OCI8::Driver
from (irb):4
irb(main):005:0> DBI.conect(‘dbi::OCI8:’, ‘orcauser’, ‘orca2user’)
NoMethodError: undefined method `conect’ for DBI:Module
from (irb):5
irb(main):006:0>

You did a typo. Use ‘connect’ instead of ‘conect’.
DBI.connect will be raise the following exception when using dbi 0.1.1
and oci8 1.0.5.
DBI::InterfaceError: Could not load driver (no such file to load
– DBD/OCI8/OCI8)
Did you copy oci8.rb to DBD/OCI8/OCI8.rb?

You have two ways to use dbi and Oracle.

  1. Use the latest dbi instead of 0.1.1.
    Add “require ‘rubygems’” prior to “require ‘dbi’”.
    Otherwise,
  2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

#9

Takehiro Kubo wrote:

You have two ways to use dbi and Oracle.

  1. Use the latest dbi instead of 0.1.1.
    � �Add “require ‘rubygems’” prior to “require ‘dbi’”.
    Otherwise,
  2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

Yet another way:
3. Use One-Click Installer 1.8.6-27 Release Candidate 2
The bundled dbi version is 0.2.2.
You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

Yeh, well, I don’t see any one-click installer for 1.8.6-27, only 1.8.6.
And, that’s what I’ve been using. And, if I go to these web sites and
choose the latest oci8 and dbi, I don’t see why it just doesn’t work.
So, for now, I’m just giving up. Thanks.


#10

You have two ways to use dbi and Oracle.

  1. Use the latest dbi instead of 0.1.1.
    Add “require ‘rubygems’” prior to “require ‘dbi’”.
    Otherwise,
  2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

Yet another way:
3. Use One-Click Installer 1.8.6-27 Release Candidate 2
The bundled dbi version is 0.2.2.
You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.


#11

On Thu, Apr 16, 2009 at 1:44 AM, Peter B. removed_email_address@domain.invalid wrote:

Takehiro Kubo wrote:

You have two ways to use dbi and Oracle.

  1. Use the latest dbi instead of 0.1.1.
    Add “require ‘rubygems’” prior to “require ‘dbi’”.

Gem packages are unavailable unless “require ‘rubygems’”.

Otherwise,
2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

Yet another way:
3. Use One-Click Installer 1.8.6-27 Release Candidate 2
The bundled dbi version is 0.2.2.
You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

Yeh, well, I don’t see any one-click installer for 1.8.6-27, only 1.8.6.

What I said is ruby186-27_rc2.exe in the following link.
http://rubyforge.org/frs/?group_id=167

And, that’s what I’ve been using.

Your dbi version is 0.1.1. It means your are using ruby186-26.exe or
earlier.


#12

Takehiro Kubo wrote:

Hi,

On Wed, Apr 15, 2009 at 12:09 AM, Peter B. removed_email_address@domain.invalid wrote:

Exception: Could not load driver (unitialized constant OCI8::Driver)

Did you manually edit dbi.rb?
The OCI8 Driver defines DBI::DBD::OCI8::Driver, but not OCI8::Driver.

What version of ruby, ruby-dbi and ruby-oci8 do you use?
How did you install ruby-dbi and ruby-oci8?

Thanks,
I’m using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it’s
the latest. And, I downloaded and installed the latest version of oci8,
for Windows.

ruby-dbi 0.4.1?
ruby-oci8 2.0.1 or 1.0.5?

Could you tell me the result of the following command on the irb
console?

require ‘dbi’
DBI::VERSION
require ‘oci8’
OCI8::VERSION
dbd_dr = DBI::DBD.const_get(:OCI8)
dbd_dr::Driver.new
DBI.connect(‘dbi:OCI8:’, ‘username’, ‘password’)

Copy and paste the output as follows:

c:> irb
irb(main):001:0> require ‘dbi’
=> true
irb(main):002:0> DBI::VERSION
=> “0.4.1”
irb(main):003:0> require ‘oci8’
=> true
irb(main):004:0> OCI8::VERSION
=> “2.0.1”
irb(main):005:0> dbd_dr = DBI::DBD.const_get(:OCI8)
=> DBI::DBD::OCI8
irb(main):006:0> dbd_dr::Driver.new
=> #DBI::DBD::OCI8::Driver:0xf7a1bb3c
irb(main):007:0> DBI.connect(‘dbi:OCI8:’, ‘username’, ‘password’)
=> #<DBI::DatabaseHandle:0xf7a13310 @driver_name=“OCI8”,
@trace_mode=nil, @convert_types=true,
@handle=#<DBI::DBD::OCI8::Database:0xf7a13220 @attr={},
@handle=#OCI8:RUBY>, @trace_output=nil>
irb(main):008:0>

I followd your steps . But while connecting .

DBI.connect(‘dbi:OCI8:databasename:ipaddress’, ‘username’, ‘password’)

I got following error

DBI::DatabaseError: ORA-12154: TNS:could not resolve the connect
identifier specified