ruby-oci8 check fails (macOS)

11 views
Skip to first unread message

Serguei Cambour

unread,
Jun 22, 2018, 4:15:47 AM6/22/18
to Oracle enhanced adapter for ActiveRecord
I can't connect to a DB Oracle, so I checked if  ruby-oci8 works as described in README and executed the below code in my terminal:

ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"


and it failed:


ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"
Traceback (most recent call last):
  1: from /Users/Serguei/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/Serguei/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ubygems (LoadError)


I don't know why the error indicates ubygems? Any idea ?

Here is my environment:

- macOS
- ruby 2.5.0
- activerecord-oracle_enhanced-adapter (5.2.2)
- activerecord (5.2.0, 5.1.6, 5.1.5)
- ruby-oci8 (2.2.5.1)

Thank you

Yasuo Honda

unread,
Jun 22, 2018, 4:27:01 AM6/22/18
to oracle-...@googlegroups.com
Hi,

`-rubygems` option has been removed
https://github.com/rubygems/rubygems/pull/2027/files

Then how about removing `-rubygems` option or use `-rrubygems` option as below.

* Remove `-rubygems` option
$ ruby -e "require 'oci8';
OCI8.new('oracle_enhanced','oracle_enhanced','ORCLPDB1').exec('select
* from dual') do |r| puts r.join(','); end"
X

* Use `-rrubygems`
$ ruby -rrubygems -e "require 'oci8';
OCI8.new('oracle_enhanced','oracle_enhanced','ORCLPDB1').exec('select
* from dual') do |r| puts r.join(','); end"

Replace username, password, and database with your own configurations.

Thanks,
--
Yasuo Honda


--
Yasuo Honda
> --
> You received this message because you are subscribed to the Google Groups "Oracle enhanced adapter for ActiveRecord" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to oracle-enhanc...@googlegroups.com.
> To post to this group, send email to oracle-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/oracle-enhanced.
> For more options, visit https://groups.google.com/d/optout.

Serguei Cambour

unread,
Jun 22, 2018, 4:33:06 AM6/22/18
to Oracle enhanced adapter for ActiveRecord


On Friday, 22 June 2018 10:27:01 UTC+2, Yasuo Honda wrote:
Hi,

`-rubygems` option has been removed
https://github.com/rubygems/rubygems/pull/2027/files

Then how about removing `-rubygems` option or use `-rrubygems` option as below.

* Remove `-rubygems` option
$ ruby -e "require 'oci8';
OCI8.new('oracle_enhanced','oracle_enhanced','ORCLPDB1').exec('select
* from dual') do |r| puts r.join(','); end"
X

* Use `-rrubygems`
$ ruby -rrubygems -e "require 'oci8';
OCI8.new('oracle_enhanced','oracle_enhanced','ORCLPDB1').exec('select
* from dual') do |r| puts r.join(','); end"

Replace username, password, and database with your own configurations.
Thank you for the response. Did you mean to replace "username", "password" and "database" with my own values in the below code?:



Where does "dual' table name come from in this case ? It seems like README suffers fro being updated :). 

Yasuo Honda

unread,
Jun 22, 2018, 4:36:57 AM6/22/18
to oracle-...@googlegroups.com
Hi,

> Thank you for the response. Did you mean to replace "username", "password" and "database" with my own values in the below code?:

Yes. Please use your database configurations.


> Where does "dual' table name come from in this case ? It seems like README suffers fro being updated :).

You can refer this document to see what is `DUAL`.

https://docs.oracle.com/database/121/SQLRF/queries009.htm#SQLRF20036


--
Yasuo Honda

Serguei Cambour

unread,
Jun 22, 2018, 4:37:49 AM6/22/18
to Oracle enhanced adapter for ActiveRecord
I also tried 2 different ways to connect to the DB and without success:

ActiveRecord::Base.establish_connection(
  adapter: 'oracle_enhanced',
  host: 'XXX.XXXX..org',
  port: '1531',
  database: 'some_name',
  username: 'some_pwd',
  password: 'some_user'
)

or like this:

ActiveRecord::Base.establish_connection(
  adapter: 'oracle_enhanced',
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=XXX.XXX.org)(PORT=1531)))
    (CONNECT_DATA=(SID=same_value_database_above))
  )",
  username: 'some_user',
  password: 'some_pwd'
)



On Friday, 22 June 2018 10:27:01 UTC+2, Yasuo Honda wrote:

Yasuo Honda

unread,
Jun 22, 2018, 4:43:16 AM6/22/18
to oracle-...@googlegroups.com
I'd suggest you take a look at if you can connect to the database
using the command line first.

ruby -e "require 'oci8';
OCI8.new('username','password','database').exec('select * from dual')
do |r| puts r.join(','); end"


--
Yasuo Honda

Serguei Cambour

unread,
Jun 22, 2018, 4:45:17 AM6/22/18
to oracle-...@googlegroups.com
Where should put my host name in the command you suggested:

ruby -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"

Yasuo Honda

unread,
Jun 22, 2018, 4:47:37 AM6/22/18
to oracle-...@googlegroups.com
Here, `database` is a TNS alias name. Same as using sqlplus
username/password@<TNS alias> . Please contact your DBA what is the
TNS alias value configured.

--
Yasuo Honda

Serguei Cambour

unread,
Jun 22, 2018, 7:48:34 AM6/22/18
to oracle-...@googlegroups.com
I hope I DO NOT NEED to have Oracle Instant Client installed on my Mac to be able to run the above command ?

Serguei Cambour

unread,
Jun 22, 2018, 8:31:44 AM6/22/18
to oracle-...@googlegroups.com
I finally figured out how to get it working:

- I had to find my Mas host name by running `hostname`.
- then add the value of the above host name to `etc/hosts` file: 
before: `127.0.0.1 localhost` 
after: `127.0.0.1 localhost my_host_name`

With this in place, I could to connect to the DB with  sqlplus command.

Then a Ruby script to connect to the same DB works fine:

ActiveRecord::Base.establish_connection(
  adapter: 'oracle_enhanced',
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=my_db_host)(PORT=1531)))
    (CONNECT_DATA=(SID=my_db_sid_value))
  )",
  username: 'some_user',
  password: 'somePwd'
)

But if I use a different way, it does not work either:

ActiveRecord::Base.establish_connection(
  adapter: 'oracle_enhanced',
  host: 'my_db_host',
  port: '1531',
  database: 'my_db_sid_value',
  username: 'some_user',
  password: 'somePwd'
)

What's wrong with that ? Thank you!


Reply all
Reply to author
Forward
0 new messages