View on GitHub

oci8_simple

Run single sql statements against an Oracle schema

Download this project as a .zip file Download this project as a tar.gz file

This gem is a thin wrapper around the ruby-oci8 gem. The client is intended to be used by simple scripts to aid automation. The code is intentionally light-weight and featureless, with very little startup time.

It is not meant to be a Ruby ORM for Oracle - if you want that, look at the OracleEnhancedAdapter.

Installation

Before installing, you must have Oracle Instantclient installed on your machine. See http://www.oracle.com/technetwork/database/features/instant-client/index-100365.html for details.

$ gem install oci8_simple

oci8_simple uses the same database configuration file format that ActiveRecord uses. It will look in the following places for the configuration file, in order:

Dir.pwd + "/database.yml"
Dir.pwd + "/config/database.yml"
~/.oci8_simple/database.yml

As an example, this database.yml defines the 'development' and 'test' schema connections:

development:
  database: 192.168.1.3:1521/xe
  username: rash_doctor
  password: N33dlez

test:
  database: 192.168.1.3:1521/xe
  username: skin_doctor
  password: N33dlez

Shell helpers

Oci8Simple installs several shell scripts. Each script takes an optional parameter to specify which database to connect to. Database configuration is pulled from ~/oci8_simple/database.yml. If no database is specified, Oci8Simple uses "development."

oci8_simple

run arbitrary SQL

$ oci8_simple 'select id, name from rashes'
214381688, Psoriasis
1418205031, Dermatitis
2104832561, Chicken Pox
1600313148, Impetigo

describe

describe a table

$ describe rashes
Required  Name             Type      Size    Char?  Char_size  Precision  Scale  Default   
-------------------------------------------------------------------------------------------
          description      clob                                                            
       *  id               number    22.0                      38.0       0.0              
          oozing_pus       number    22.0                      1.0        0.0    1         
          name             varchar2  1020.0  *      255.0                                  
          itchy            number    22.0                      1.0        0.0    0         

show

list things in the database (tables, views, etc.)

$ show tables
infections
rashes
sores
wounds

Ruby code

You can also use oci8_simple in your Ruby scripts by creating an instance of Oci8Simple::Client.

require 'rubygems'
require 'oci8_simple'

# connect to the "test" database defined in ~/.oci8_simple/database.yml
client = Oci8Simple::Client.new("test")  
   
# please oh god make the pain stop
client.run("select id, name from rashes")

# [[214381688, "Psoriasis"], 
#  [1418205031, "Dermatitis"], 
#  [2104832561, "Chicken Pox"], 
#  [1600313148, "Impetigo"]]