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
Jim Cain wrote:
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. 
Regards,
Dan
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.
···
In article 3F026D44.7090802@jimcain.us, Jim Cain list@jimcain.us wrote:
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:
–
Ollivier ROBERT -=- Eurocontrol EEC/AMI -=- roberto@eurocontrol.fr
Usenet Canal Historique FreeBSD: The Power to Serve!
Daniel Berger wrote:
Jim Cain wrote:
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
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:
make
make
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
Daniel Berger wrote:
Jim Cain wrote:
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.
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. 
Done. Sorry. I had just quicky uploaded the tarball I used for backing
up the code.
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.
Cool. Can anyone let me know where the oracle9i distrubution is now? I’ve
misplaced the original announcment and didn’t see it in RAA.
Thanks
This might be a general question…
I’m using the windows-installer version of ruby, and I can’t seem to compile
ANY of the oracle libraries. The extconf.rb files all say “no” to gcc, but I
do have gcc installed (cygwin), it’s visible in my PATH, etc.
When extconf.rb says “no” about gcc, is it saying it can’t find a gcc to
use, or is it saying that my ruby wasn’t compiled using gcc? To that end,
is it necessary to keep the same sort of development environment when
compiling extensions for ruby as what was used to compile ruby itself?
Lastly, if I get the latest ruby source, is it a big chore to get it
compiled myself using cygwin, and what are the disadvantages (if any) of
doing so?
Thanks
Daniel Berger wrote:
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
Jim Cain wrote:
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
Michael Campbell wrote:
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.
Cool. Can anyone let me know where the oracle9i distrubution is now? I’ve
misplaced the original announcment and didn’t see it in RAA.
Thanks
For now it’s only at http://jimcain.us/ruby9i/. I will eventually have
it nicely packaged and ready for inclusion at RAA.
Daniel Berger wrote:
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:
make
make
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.
“Michael Campbell” michael_s_campbell@yahoo.com wrote in message
When extconf.rb says “no” about gcc, is it saying it can’t find a gcc to
use, or is it saying that my ruby wasn’t compiled using gcc?
Probably the later …
To that end, is it necessary to keep the same sort of development
environment when compiling extensions for ruby as what was used
to compile ruby itself?
Yes …the two environments do not mix. To run cygwin extensions you
will need cygwin1.dll and to run msvc extensions you will need msvcrt.dll
(which you must find in C:\ruby\bin if you have installed ruby in c:\ruby)
Lastly, if I get the latest ruby source, is it a big chore to get it
compiled myself using cygwin,
Not at all … I was able to compile ruby-cygwin and ruby9i extensions
in a matter of about 30 minutes … most of which were spent in modifying
the Makefile generated by extconf.rb. Let me know if you need help
in this exercise.
and what are the disadvantages (if any) of doing so?
None that I can think of … other than the fact that you can run cygwin
programs only under the cygwin environment.
Thanks
HTH,
– shanko
Jim Cain wrote:
Daniel Berger wrote:
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:
make
make
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
and what are the disadvantages (if any) of doing so?
None that I can think of … other than the fact that you can run cygwin
programs only under the cygwin environment.
Thanks. I’ll give that a shot. It’s been a few years, but I’ve had
experience with [Mm]akefile hacking, so that shouldn’t be a huge issue.
Hi,
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).
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.
···
nobu.nokada@softhome.net wrote:
At Thu, 3 Jul 2003 02:16:33 +0900, > Daniel Berger wrote:
Hi,
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.
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.
···
At Thu, 3 Jul 2003 03:08:09 +0900, Jim Cain wrote:
–
Nobu Nakada