oci8_simple

This gem installs a bin script called oci8_simple. The script allows you to run single statements against an arbitrary Oracle schema via the command line, utilizing the power of your favorite shell.

The script uses a simple Ruby client 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.

Prerequisites:

Installation

gem install oci8_simple

Configuration

To configure environments and schema settings, edit the database.yml file in ~/.oci8_simple/. The database.yml format is compatible with the Rails format, so you may just symlink an existing file into this directory if you already have one.

development:
  database: oracle.hostname:1521/sid
  username: foo_dev
  password: OMG333
test:
  database: oracle.hostname:1521/sid
  username: foo_test
  password: OMG333

Logging

All logging is done to ~/.oci8_simple/oci8_simple.log.

Shell Examples

Run a query against development schema

oci8_simple "select id, name from flavors"

Run a query against a different schema

oci8_simple "select id, name from flavors" int

Help

oci8_simple --help

Code Examples

  • Initialize a client against the development schema

    require 'rubygems'
    require 'oci8_simple'
    client = Oci8Simple::Client.new
    
  • Run a simple select query against development schema

    client.run('select id, name from foos') => [[2, "lol"], [3, "hey"], ...]
    
  • Update something

    client.run <<-SQL
      UPDATE foos SET bar='baz' WHERE id=1233
    SQL
    
  • Run some DDL

    client.run <<-SQL
      CREATE TABLE foos (
         ID NUMBER(38) NOT NULL
      )
    SQL
    
  • Run some PL/SQL

    client.run <<-SQL
      DECLARE
        a NUMBER;
        b NUMBER;
      BEGIN
        SELECT e,f INTO a,b FROM T1 WHERE e>1;
        INSERT INTO T1 VALUES(b,a);
      END;
    SQL
    
  • Run a query against stage schema

    Oci8Simple::Client.new("stage").run('select id, name from foos') => [[2, "lol"], [3, "hey"], ...]
    

Contributing to oci8_simple

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 Billy Reisinger. See LICENSE.txt for further details.