[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

connecting to Oracle using OCI8 and DBI

Peter Bailey

4/13/2009 12:35:00 PM

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
--
Posted via http://www.ruby-....

10 Answers

KUBO Takehiro

4/14/2009 11:00:00 AM

0

On Mon, Apr 13, 2009 at 9:35 PM, Peter Bailey <pbailey@bna.com> 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?

Peter Bailey

4/14/2009 3:10:00 PM

0

Takehiro Kubo wrote:
> On Mon, Apr 13, 2009 at 9:35 PM, Peter Bailey <pbailey@bna.com> 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.
--
Posted via http://www.ruby-....

KUBO Takehiro

4/15/2009 1:00:00 PM

0

Hi,

On Wed, Apr 15, 2009 at 12:09 AM, Peter Bailey <pbailey@bna.com> 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>

Peter Bailey

4/15/2009 1:35:00 PM

0

DBI is version 0.1.1.
OCI8 is version 1.0.5
--
Posted via http://www.ruby-....

KUBO Takehiro

4/15/2009 2:09:00 PM

0

On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <pbailey@bna.com> wrote:
> DBI is version 0.1.1.
> OCI8 is version 1.0.5

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

Peter Bailey

4/15/2009 2:26:00 PM

0

Takehiro Kubo wrote:
> On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <pbailey@bna.com> 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>
--
Posted via http://www.ruby-....

KUBO Takehiro

4/15/2009 2:54:00 PM

0

On Wed, Apr 15, 2009 at 11:26 PM, Peter Bailey <pbailey@bna.com> wrote:
> Takehiro Kubo wrote:
>> On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <pbailey@bna.com> wrote:
>>> DBI is version 0.1.1.

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

>>> 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'
> =3D> true
> irb(main):002:0> require 'oci8'
> =3D> true
> irb(main):003:0> dbd_dr =3D DBI::DBD.const_get(:OCI8)
> =3D> OCI8

I have thought that DBI::DBD.const_get(:OCI8) would return DBI::DBD::OCI8 a=
nd
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
> =A0 =A0 =A0 =A0from (irb):4
> irb(main):005:0> DBI.conect('dbi::OCI8:', 'orcauser', 'orca2user')
> NoMethodError: undefined method `conect' for DBI:Module
> =A0 =A0 =A0 =A0from (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.

KUBO Takehiro

4/15/2009 3:04:00 PM

0

> You have two ways to use dbi and Oracle.
> 1. Use the latest dbi instead of 0.1.1.
> =A0 =A0Add "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.

Peter Bailey

4/15/2009 4:45:00 PM

0

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.

--
Posted via http://www.ruby-....

KUBO Takehiro

4/16/2009 4:16:00 AM

0

On Thu, Apr 16, 2009 at 1:44 AM, Peter Bailey <pbailey@bna.com> 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 =A01.8.6-27 Release Candidate 2
>> =A0 =A0The bundled dbi version is 0.2.2.
>> =A0 =A0You 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/?grou...

> And, that's what I've been using.

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