Oracle, ruby-oci8 and gcc

Just FYI - I remember someone was asking about using Ruby with Oracle 9i
recently (although I’ve been unable to find the post). Well, I have just had
to do this myself :slight_smile:

The driver in RAA is “ruby-oci8” but I had some trouble compiling this with
gcc. It turned out that it was trying to use a load of Solaris cc-specific
flags, but you can work around it like this:

— ruby-oci8-0.1.1.orig/src/oraconf.rb Sat Feb 1 13:57:15 2003
+++ ruby-oci8-0.1.1/src/oraconf.rb Fri Feb 14 15:15:32 2003
@@ -185,7 +185,7 @@
print(“Running make for $ORACLE_HOME/rdbms/demo/demo_rdbms.mk …”)
STDOUT.flush

  •     command = "|make -f #{@oracle_home}/rdbms/demo/demo_rdbms.mk build\
    
  •     command = "|make KPIC_OPTION= NOKPIC_CCFLAGS= -f #{@oracle_home}/rdbms/demo/demo_rdbms.mk build\
    
    CC=‘echo MARKER’ EXE=/dev/null ECHODO=echo ECHO=echo
    GENCLNTSH=‘echo genclntsh’"
    marker = /^\s*MARKER/

It now compiles fine, and passes all tests but one (and that seems to be
just the difference between a 4 second and 5 second timeout)

I also got the ‘experimental’ DBD to work, just need to copy it into the
right place (assuming you have ruby-dbi already installed of course)

mkdir -p /usr/local/lib/ruby/site_ruby/1.6/DBD/OCI8

cp src/lib/DBD/OCI8/OCI8.rb /usr/local/lib/ruby/site_ruby/1.6/DBD/OCI8/

Regards,

Brian.

Hmm, not particularly comprehensive tests it seems…

I have a table with column type NUMBER(14), and when I read it using
ruby-oci8, any trailing zeros are removed: for example the value “100” is
read as “1” !!

I’ll have a look at this myself, because I really want to use Ruby for this
particular project, but it doesn’t inspire a great deal of confidence…

Cheers,

Brian.

···

On Fri, Feb 14, 2003 at 04:11:26PM +0000, Brian Candler wrote:

It now compiles fine, and passes all tests but one (and that seems to be
just the difference between a 4 second and 5 second timeout)

Hello,

Brian Candler B.Candler@pobox.com writes:

It now compiles fine, and passes all tests but one (and that seems to be
just the difference between a 4 second and 5 second timeout)

Hmm, not particularly comprehensive tests it seems…

I have a table with column type NUMBER(14), and when I read it using
ruby-oci8, any trailing zeros are removed: for example the value “100” is
read as “1” !!

Please apply following patch.

------------------------- patch start -------------------------
— src/oranumber.c.old 2002-09-12 23:14:16.000000000 +0900
+++ src/oranumber.c 2003-02-15 13:21:59.000000000 +0900
@@ -180,10 +180,11 @@
}
if (i != 0 || j / 10 != 0)
buf[len++] = j / 10 + ‘0’;

  •  if (i != mentissa_size - 1 || j % 10 != 0)
    
  •  if ((i < exponent + 1) /* integer part */
    
  • || (i != mentissa_size - 1 || j % 10 != 0)  /* decimal fraction */)
    
    buf[len++] = j % 10 + ‘0’;
    }
  • for (;i < exponent;i++) {
  • for (;i <= exponent;i++) {
    buf[len++] = ‘0’;
    buf[len++] = ‘0’;
    }
    — test/test_oranumber.rb.old 2002-09-12 23:15:30.000000000 +0900
    +++ test/test_oranumber.rb 2003-02-15 13:20:39.000000000 +0900
    @@ -33,6 +33,12 @@
    “-0.0000000000000000000000000000000000001”,
    “-0.000000000000000000000000000000000001”,
    “-0.00000000000000000000000000000000001”,
  • “1”,
  • “20”,
  • “300”,
  • “-1”,
  • “-20”,
  • “-300”,
    ]

def setup
------------------------- patch end -------------------------

If the column type is NUMBER(1) to NUMBER(9), ruby-oci8 bind it as
‘int’ and convert it to Fixnum. If precision is higher tnan 9, bind
as ‘Oracle internal number format’ and convert it to Integer via
String. There was a serious bug in the routine converting ‘Oracle
internal number format’ to String.

I’ll have a look at this myself, because I really want to use Ruby for this
particular project, but it doesn’t inspire a great deal of confidence…

Sorry. I don’t use Oracle now. I could not test my module in real
application. And DBD::OCI8 is highly experimental. I didn’t test it
well. I just ran a few simple test scripts only.

Hmm. Please use DBD::Oracle not DBD::OCI8(ruby-oci8).
DBD::Oracle uses OCI7 but it will work on Oracle 9 also.

DBD::Oracle bind all columns as String. If you change your session’s
NLS_NUMERIC_CHARACTERS as ‘,.’, column data 1.1 will be selected as
‘1,1’. If you convert ‘1.1’ to number by String#to_i, it becomes

  1. But in the most cases, decimal point character of
    NLS_NUMERIC_CHARACTERS is ‘.’, there is no problem.

Cheers.

···

On Fri, Feb 14, 2003 at 04:11:26PM +0000, Brian Candler wrote:

KUBO Takehiro

> I have a table with column type NUMBER(14), and when I read it using
> ruby-oci8, any *trailing* zeros are removed: for example the value "100" is
> read as "1" !!

Please apply following patch.

Your quick response, both off and on-list, is greatly appreciated.

And DBD::OCI8 is highly experimental. I didn't test it
well. I just ran a few simple test scripts only.

That's OK. I don't really mind using the native OCI8 high-level interface; I
may end up using Oracle-specific SQL like 'CONNECT PRIOR...' anyway.

DBD::Oracle uses OCI7 but it will work on Oracle 9 also.

I'll try compiling that as well. I'd feel happier using a more modern API on
the Oracle side of things, but at least I'll have two options to choose
between.

Thanks again,

Brian.

···

On Sat, Feb 15, 2003 at 03:33:04PM +0900, KUBO Takehiro wrote:

Just tried it, and it compiles out of the box.

It produces a warning about 'to_i' being redefined in OCIError, but a simple
test works just fine. My DBI code works the same both ways:

  dbh = DBI.connect("dbi:OCI8:", ... )
  dbh = DBI.connect("dbi:oracle:", ... )

Many thanks!

Brian.

···

On Sat, Feb 15, 2003 at 03:33:04PM +0900, KUBO Takehiro wrote:

Hmm. Please use DBD::Oracle not DBD::OCI8(ruby-oci8).
DBD::Oracle uses OCI7 but it will work on Oracle 9 also.