= oci8_simple
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.
This gem installs a few command-line scripts:
* oci8_simple
* a command to run arbitrary SQL
* describe
* a command to describe a table
You can also use oci8_simple in your Ruby scripts by creating an instance of Oci8Simple::Client
(see more below).
== Prerequisites
* Oracle Instant Client (http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)
* ruby-oci8
== 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
.
== Command-Line Examples
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.
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
oci8_simple
also comes with a bin script called describe
. This script
shows a simple description of a table, including the column names (sorted), the type and size for
each column, and the nullable status of the column.
Show column information for a table named "holidays"
describe holidays
Help
describe --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
Copyright (c) 2011 Billy Reisinger. See LICENSE.txt for
further details.