Ruby9i now available

J

Jim Cain

All,

I've made available on my Web site what I have so far. I've called it
Ruby9i, which is the name of the C extension library. It is available at:

http://jimcain.us/ruby9i/

Currently it has support for the basics and some of the newer Oracle
types, including timestamps and intervals. There is some support for
non-blocking OCI calls, too.

If you're interested, you'll have to peruse the source code, since I
haven't written any documentation for it yet. That will be along soon,
maybe within the next week or so.

It doesn't yet support fancier stuff like LOBs, collections or
user-defined types, but since I use those in Oracle, that's what I'll be
working on in the following week or so.

Date functions and arithmetic have spotty support. This will be fleshed
out soon, too.

My main purpose in posting this now is to get feedback from the more
knowledgable Ruby folks, at least those who don't have anything better
to do. :) As I state on the project's main page, I only read Ruby's docs
for the first time less than two weeks ago, and the following day I
started this project.

If anyone has any features that they would like supported, please let me
know. For now, I've got plenty of time to spend on this project since I
was just laid off. My loss is the Ruby community's gain, I hope.

Cheers,
Jim
 
D

Daniel Berger

Jim said:
All,


If anyone has any features that they would like supported, please let me
know. For now, I've got plenty of time to spend on this project since I
was just laid off. My loss is the Ruby community's gain, I hope.

Cheers,
Jim

Hi Jim,

Thank you very much!

As for features, I personally hate manual installation. Here's a little
extconf.rb script I whipped up for folks to use.

# extconf.rb for ruby9i
require "mkmf"

if ENV["ORACLE_HOME"] || ENV["ORA_HOME"]
ORACLE_HOME = ENV["ORACLE_HOME"] || ENV["ORA_HOME"]
$CFLAGS="-I#{ORACLE_HOME}/rdbms/demo -I#{ORACLE_HOME}/rdbms/public"
$LDFLAGS="-L#{ORACLE_HOME}/lib"
else
msg = "Your $ORACLE_HOME environment variable is not set. You can "
msg += "either set it and start over or hand-modify the Makefile "
msg += "to point to the appropriate directories"
STDERR.puts msg
end

dir_config("oracle9i")
have_header("oci.h")
have_library("clntsh")
create_makefile("oracle9i")
# end extconf.rb

Then it's just a matter of doing:

ruby extconf.rb
make
make site-install

I ran this sample test:

# test.rb
require 'ruby9i'

db = "some_db"
user = "some_user"
passwd = "bogus"

dbh = Ruby9i::Database.new(db,user,passwd)
sth = dbh.prepare("SELECT sysdate from dual")
sth.execute

puts sth.fetch

sth.close # oops!
dbh.disconnect
# end test.rb

Only thing that surprised me was that statement handles didn't have a
close method. But otherwise, it worked! Oracle 9.0.1, Solaris 9, btw.

Oh, one more thing. Please create tarballs so that they unpack into
their own directory, not the current directory. You seem a decent
fellow - I'd hate to kill you. :p

Regards,

Dan
 
D

Daniel Berger

Quick followup - it built fine with 1.6.8 but wasn't as happy with 1.8
(2003-06-14). Here's the result of the make command:
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c baseinterval.c
baseinterval.c: In function `biv_initialize':
baseinterval.c:31: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
baseinterval.c:63: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c basetimestamp.c
basetimestamp.c: In function `bts_initialize':
basetimestamp.c:68: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
basetimestamp.c:69: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
basetimestamp.c: In function `bts_to_s':
basetimestamp.c:229: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c database.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c datatype.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c date.c
date.c: In function `date_initialize':
date.c:39: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
date.c: In function `date_next_day':
date.c:95: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c error.c
error.c: In function `error_to_s':
error.c:101: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
error.c:102: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
error.c:104: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
error.c:113: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
error.c:115: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c handle.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c intervalds.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c intervalym.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c number.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c rowid.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c ruby9i.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c statement.c
statement.c: In function `stmt_bind_param':
statement.c:106: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c timestamp.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c timestampltz.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c timestamptz.c
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c varchar.c
varchar.c: In function `varchar_initialize':
varchar.c:33: warning: passing arg 2 of `rb_str2cstr' from incompatible
pointer type
gcc -Wl,-G -L/opt/oracle/lib -L"/opt/lib" -o ruby9i.so baseinterval.o
basetimestamp.o database.o datatype.o date.o error.o handle.o
intervalds.o intervalym.o number.o rowid.o ruby9i.o statement.o
timestamp.o timestampltz.o timestamptz.o varchar.o -lclntsh -ldl
-lcrypt -lm -lc

Despite the warnings, a small test script worked ok. Just thought I'd
point it out in case it leads to bigger problems down the road.

Regards,

Dan
 
J

Jim Cain

Daniel said:
Hi Jim,

Thank you very much!

As for features, I personally hate manual installation. Here's a little
extconf.rb script I whipped up for folks to use.

Yes, I agree with you. I just haven't taken the time to study the "Ruby
way" in that regard yet. I'll have that included in the next release.
Only thing that surprised me was that statement handles didn't have a
close method. But otherwise, it worked! Oracle 9.0.1, Solaris 9, btw.

They do have #finish though. Actually it was originally called close,
but I changed it to agree with the DBI so that it would be a little more
intuitive for the people who were used to the DBI but who still wanted
to use the low-level API in the C extension.
Oh, one more thing. Please create tarballs so that they unpack into
their own directory, not the current directory. You seem a decent
fellow - I'd hate to kill you. :p

Done. Sorry. I had just quicky uploaded the tarball I used for backing
up the code.
 
D

Daniel Berger

Jim said:
They do have #finish though. Actually it was originally called close,
but I changed it to agree with the DBI so that it would be a little more
intuitive for the people who were used to the DBI but who still wanted
to use the low-level API in the C extension.

Oops - my bad. It *is* supposed to be finish(). Dunno where I got that
one - maybe Perl.

Regards,

Dan
 
J

Jim Cain

Daniel said:
Quick followup - it built fine with 1.6.8 but wasn't as happy with 1.8
(2003-06-14). Here's the result of the make command:
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c baseinterval.c
baseinterval.c: In function `biv_initialize':
baseinterval.c:31: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
[more of the same warnings...]
Despite the warnings, a small test script worked ok. Just thought I'd
point it out in case it leads to bigger problems down the road.

This is because in 1.8 rb_str2cstr(VALUE, int*) has changed to
rb_str2cstr(VALUE, long*), and I've used ints for all my lengths.
 
D

Daniel Berger

Jim said:
Daniel said:
Quick followup - it built fine with 1.6.8 but wasn't as happy with 1.8
(2003-06-14). Here's the result of the make command:
gcc -fPIC -I/opt/oracle/rdbms/demo -I/opt/oracle/rdbms/public -I.
-I/opt/lib/ruby/1.8/sparc-solaris2.9
-I/opt/lib/ruby/1.8/sparc-solaris2.9 -I. -DHAVE_OCI_H -c baseinterval.c
baseinterval.c: In function `biv_initialize':
baseinterval.c:31: warning: passing arg 2 of `rb_str2cstr' from
incompatible pointer type
[more of the same warnings...]
Despite the warnings, a small test script worked ok. Just thought I'd
point it out in case it leads to bigger problems down the road.


This is because in 1.8 rb_str2cstr(VALUE, int*) has changed to
rb_str2cstr(VALUE, long*), and I've used ints for all my lengths.

Ah, ok. Ruby has some #define's (in version.h) you could use to see
which version you're building against (if you're feeling up to it).

Regards,

Dan
 
N

nobu.nokada

Hi,

At Thu, 3 Jul 2003 02:16:33 +0900,
Daniel said:
Ah, ok. Ruby has some #define's (in version.h) you could use to see
which version you're building against (if you're feeling up to it).

It's not good idea to determin by release date or similar.
Also, basically, rb_str2cstr() is obsolete. You should use
StringValuePtr() and RSTRING()->ptr/len, instead.

And the source looks like C++ or C99, doesn't it?
 
J

Jim Cain

Hi,

At Thu, 3 Jul 2003 02:16:33 +0900,



It's not good idea to determin by release date or similar.
Also, basically, rb_str2cstr() is obsolete. You should use
StringValuePtr() and RSTRING()->ptr/len, instead.

Excellent. That's just the kind of info I was looking for. I'll make the
changes as I work on the code.
And the source looks like C++ or C99, doesn't it?

Funny you mention that. It's been years since I've coded in C. I used
C++ extensively in 00-01, and neither of them since then, although I
still play with C++ now and then. Between C and C++ I've only used C++
since 99, so I don't even remember all the picky little C++ things you
can't do in standard C. Well, until the compiler complains about them.
So I'm sure there's a lot of C++ influence in my C coding.
 
N

nobu.nokada

Hi,

At Thu, 3 Jul 2003 03:08:09 +0900,
Jim said:
Funny you mention that. It's been years since I've coded in C. I used
C++ extensively in 00-01, and neither of them since then, although I
still play with C++ now and then. Between C and C++ I've only used C++
since 99, so I don't even remember all the picky little C++ things you
can't do in standard C. Well, until the compiler complains about them.
So I'm sure there's a lot of C++ influence in my C coding.

For example, from ruby9i/baseinterval.c:

VALUE biv_initialize(int argc, VALUE *argv, VALUE self)
{
rb_call_super(argc, argv);

oci9_define_buf *bp;

This bp looks like a variable definition, but C90 shouldn't
allow it after excution statements.
 
O

Ollivier Robert

I've made available on my Web site what I have so far. I've called it
Ruby9i, which is the name of the C extension library. It is available at:

Can you also make a DBD for it, as DBI is pretty much a de facto standard
among Ruby & Perl?

I've been using ruby-oci8 with Oracle 9i (9.2.0) with great success, it
includes a DBD::OCI8 driver.
 
J

Jim Cain

Ollivier said:
Can you also make a DBD for it, as DBI is pretty much a de facto standard
among Ruby & Perl?

I've been using ruby-oci8 with Oracle 9i (9.2.0) with great success, it
includes a DBD::OCI8 driver.

The package includes a DBD API.
 
D

Daniel Berger

Daniel said:
# extconf.rb for ruby9i
require "mkmf"

if ENV["ORACLE_HOME"] || ENV["ORA_HOME"]
ORACLE_HOME = ENV["ORACLE_HOME"] || ENV["ORA_HOME"]
$CFLAGS="-I#{ORACLE_HOME}/rdbms/demo -I#{ORACLE_HOME}/rdbms/public"
$LDFLAGS="-L#{ORACLE_HOME}/lib"
else
msg = "Your $ORACLE_HOME environment variable is not set. You can "
msg += "either set it and start over or hand-modify the Makefile "
msg += "to point to the appropriate directories"
STDERR.puts msg
end

dir_config("oracle9i")
have_header("oci.h")
have_library("clntsh")
create_makefile("oracle9i")
# end extconf.rb

For anyone using this script, please change "oracle9i" to "ruby9i".
Sorry about that.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top