oci8_simple 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,7 +8,8 @@ This gem installs a few command-line scripts:
8
8
  * a command to run arbitrary SQL
9
9
  * <code>describe </code>
10
10
  * a command to describe a table
11
-
11
+ * <code>show </code>
12
+ * a command to list things in the database (tables, views, etc.)
12
13
  You can also use oci8_simple in your Ruby scripts by creating an instance of <code>Oci8Simple::Client</code>
13
14
  (see more below).
14
15
 
@@ -37,8 +38,9 @@ an existing file into this directory if you already have one.
37
38
  All logging is done to <code>~/.oci8_simple/oci8_simple.log</code>.
38
39
 
39
40
  == Command-Line Examples
40
- This gem installs a bin script called <code>oci8_simple</code>. The script allows you to
41
- run single statements against an arbitrary Oracle schema via the command line.
41
+ === oci8_simple
42
+ This script allows you to run single statements against an
43
+ arbitrary Oracle schema via the command line.
42
44
 
43
45
  Run a query against development schema
44
46
  oci8_simple "select id, name from flavors"
@@ -49,10 +51,10 @@ run single statements against an arbitrary Oracle schema via the command line.
49
51
  Help
50
52
  oci8_simple --help
51
53
 
52
-
53
- <code>oci8_simple</code> also comes with a bin script called <code>describe</code>. This script
54
- shows a simple description of a table, including the column names (sorted), the type and size for
55
- each column, and the nullable status of the column.
54
+ === describe
55
+ This script shows a description of a table, including the column names (sorted),
56
+ the type and size for each column, the nullable status of the column, and the default
57
+ value, if any.
56
58
 
57
59
  Show column information for a table named "holidays"
58
60
  describe holidays
@@ -60,6 +62,19 @@ each column, and the nullable status of the column.
60
62
  Help
61
63
  describe --help
62
64
 
65
+ === show
66
+ This command can list the following items in the database:
67
+ functions, packages, procedures, sequences, synonyms, tables, types, and views.
68
+
69
+ Show a list of all tables in the database
70
+ show tables
71
+
72
+ Show a list of all views in the database
73
+ show views
74
+
75
+ Help
76
+ show --help
77
+
63
78
  == Code Examples
64
79
  * Initialize a client against the development schema
65
80
  require 'rubygems'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/bin/show ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ require 'oci8_simple'
4
+
5
+ Oci8Simple::Show.run_from_argv
@@ -6,6 +6,8 @@ module Oci8Simple
6
6
  # cli = Oci8Simple::Cli.new
7
7
  # cli.run "select id, name from foos" # "3, Bacon\n5, Cheese Puffs\n..."
8
8
  class Cli
9
+ include Command
10
+
9
11
  attr_accessor :env, :client
10
12
 
11
13
  def initialize(env=nil)
@@ -29,14 +31,7 @@ module Oci8Simple
29
31
  end
30
32
 
31
33
  def self.run_from_argv
32
- o = OptionParser.new do |opt|
33
- opt.banner = usage
34
- opt.on("-v", "--version", "Show version") do
35
- puts "version #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}"
36
- exit
37
- end
38
- end
39
- o.parse!
34
+ o = parse_options(self.usage)
40
35
  if(ARGV[0].nil?)
41
36
  puts o
42
37
  else
@@ -0,0 +1,24 @@
1
+ module Oci8Simple
2
+ module Command
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+ # Returns an OptionParser object.
10
+ def parse_options(banner)
11
+ o = OptionParser.new do |opt|
12
+ opt.banner = banner
13
+ opt.on("-v", "--version", "Show version") do
14
+ puts "#{self.to_s} #{Oci8Simple::VERSION}"
15
+ exit
16
+ end
17
+ end
18
+ o.parse!
19
+ o
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -5,6 +5,8 @@ module Oci8Simple
5
5
  # == Usage
6
6
  # Oci8Simple::Describe.new("development").run("users")
7
7
  class Describe
8
+ include Command
9
+
8
10
  SPACE_BETWEEN=2
9
11
  FIELDS=[
10
12
  {:select => "NULLABLE", :header => "Required", :content => :format_nullable, :right => true},
@@ -35,18 +37,11 @@ module Oci8Simple
35
37
  end
36
38
 
37
39
  def self.usage
38
- "Usage: #{0} TABLE_NAME [ENVIRONMENT]"
40
+ "Usage: #{$0} TABLE_NAME [ENVIRONMENT]"
39
41
  end
40
42
 
41
43
  def self.run_from_argv
42
- o = OptionParser.new do |opt|
43
- opt.banner = usage
44
- opt.on("-v", "--version", "Show version") do
45
- puts "version #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}"
46
- exit
47
- end
48
- end
49
- o.parse!
44
+ o = parse_options(self.usage)
50
45
  if(ARGV[0].nil?)
51
46
  puts o
52
47
  else
@@ -0,0 +1,49 @@
1
+ module Oci8Simple
2
+ class Show
3
+ include Command
4
+
5
+ TYPES={
6
+ "functions" => "Function",
7
+ "packages" => "Package",
8
+ "procedures" => "Procedure",
9
+ "sequences" => "Sequence",
10
+ "synonyms" => "Synonym",
11
+ "tables" => "Table",
12
+ "types" => "Type",
13
+ "views" => "View"
14
+ }
15
+
16
+ def run(type)
17
+ clazz = eval("OCI8::Metadata::#{TYPES[type]}")
18
+ objects = client.send(:conn).describe_schema(client.config["username"]).all_objects.find_all{|f| f.class == clazz}
19
+ objects.map(&:obj_name).map(&:downcase).sort
20
+ end
21
+
22
+ def initialize(env=nil)
23
+ @env = env || "development"
24
+ end
25
+
26
+ def self.run_from_argv
27
+ o = parse_options(self.usage)
28
+ if(ARGV[0].nil? || TYPES[ARGV[0]].nil?)
29
+ puts o
30
+ else
31
+ puts self.new(ARGV[1]).run(ARGV[0])
32
+ end
33
+ end
34
+
35
+ def self.usage
36
+ <<-STR
37
+ Usage: #{$0} TYPE [ENVIRONMENT]
38
+
39
+ TYPE is one of: #{TYPES.keys.sort.join(", ")}
40
+ STR
41
+ end
42
+
43
+ private
44
+
45
+ def client
46
+ @client ||= Oci8Simple::Client.new(@env)
47
+ end
48
+ end
49
+ end
data/lib/oci8_simple.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  require 'rubygems'
2
- require 'pp'
2
+
3
+ require 'abbrev'
3
4
  require 'bigdecimal'
4
- require 'yaml'
5
5
  require 'optparse'
6
+ require 'pp'
7
+ require 'yaml'
6
8
 
7
9
  gem 'ruby-oci8'
8
10
  require 'oci8'
9
11
 
12
+ require 'oci8_simple/command'
10
13
  require 'oci8_simple/cli'
11
14
  require 'oci8_simple/client'
12
- require 'oci8_simple/describe'
15
+ require 'oci8_simple/describe'
16
+ require 'oci8_simple/show'
17
+
18
+ module Oci8Simple
19
+ VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
20
+ end
data/oci8_simple.gemspec CHANGED
@@ -5,16 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oci8_simple}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Billy Reisinger"]
12
- s.date = %q{2011-06-30}
12
+ s.date = %q{2011-07-06}
13
13
  s.description = %q{Command-line tools for interacting with an Oracle database. This client is intended to be used
14
14
  to aid development and automation. This is *not* meant to replace an ORM such as ActiveRecord + OracleEnhancedAdapter.
15
15
  The only prerequisite to running this code is that you have installed the ruby-oci8 gem on your machine.}
16
16
  s.email = %q{billy.reisinger@gmail.com}
17
- s.executables = ["oci8_simple", "describe"]
17
+ s.executables = ["show", "oci8_simple", "describe"]
18
18
  s.extra_rdoc_files = [
19
19
  "README.rdoc"
20
20
  ]
@@ -28,15 +28,19 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "bin/describe",
30
30
  "bin/oci8_simple",
31
+ "bin/show",
31
32
  "lib/oci8_simple.rb",
32
33
  "lib/oci8_simple/cli.rb",
33
34
  "lib/oci8_simple/client.rb",
35
+ "lib/oci8_simple/command.rb",
34
36
  "lib/oci8_simple/describe.rb",
37
+ "lib/oci8_simple/show.rb",
35
38
  "oci8_simple.gemspec",
36
39
  "test/cli_test.rb",
37
40
  "test/client_test.rb",
38
41
  "test/describe_test.rb",
39
- "test/helper.rb"
42
+ "test/helper.rb",
43
+ "test/show_test.rb"
40
44
  ]
41
45
  s.homepage = %q{http://github.com/unclebilly/oci8_simple}
42
46
  s.licenses = ["MIT"]
@@ -47,7 +51,8 @@ Gem::Specification.new do |s|
47
51
  "test/cli_test.rb",
48
52
  "test/client_test.rb",
49
53
  "test/describe_test.rb",
50
- "test/helper.rb"
54
+ "test/helper.rb",
55
+ "test/show_test.rb"
51
56
  ]
52
57
 
53
58
  if s.respond_to? :specification_version then
data/test/show_test.rb ADDED
@@ -0,0 +1,124 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+ class ShowTest < Test::Unit::TestCase
3
+ def setup
4
+ @client = Oci8Simple::Client.new("test")
5
+ @show = Oci8Simple::Show.new("test")
6
+ end
7
+ def teardown
8
+
9
+ end
10
+ context "Show tables" do
11
+ setup do
12
+ @client.run "drop table oci8_simple_test" rescue nil
13
+ @client.run "drop table oci8_simple_test_2" rescue nil
14
+ @client.run <<-SQL
15
+ CREATE TABLE "OCI8_SIMPLE_TEST" ("ID" NUMBER(38,0) DEFAULT 7 NOT NULL ENABLE)
16
+ SQL
17
+ @client.run <<-SQL
18
+ CREATE TABLE "OCI8_SIMPLE_TEST_2" ("ID" NUMBER(38,0) NOT NULL ENABLE)
19
+ SQL
20
+ end
21
+ should "list the tables" do
22
+ assert_equal ["oci8_simple_test","oci8_simple_test_2"], @show.run("tables")
23
+ end
24
+ end
25
+
26
+ context "Show functions" do
27
+ setup do
28
+ @client.run "drop function oci8_simple_function" rescue nil
29
+ @client.run <<-SQL
30
+ CREATE FUNCTION oci8_simple_function
31
+ RETURN NUMBER
32
+ IS num NUMBER(1,0);
33
+ BEGIN
34
+ SELECT 1 INTO num FROM DUAL;
35
+ RETURN(num);
36
+ END
37
+ SQL
38
+ end
39
+ should "list the functions" do
40
+ assert_equal ["oci8_simple_function"], @show.run("functions")
41
+ end
42
+ end
43
+
44
+ context "Show packages" do
45
+ setup do
46
+ @client.run "drop package oci8_simple_package" rescue nil
47
+ @client.run <<-SQL
48
+ CREATE OR REPLACE PACKAGE oci8_simple_package AS
49
+ FUNCTION something(id NUMBER, foo NUMBER)
50
+ RETURN NUMBER;
51
+ END oci8_simple_package
52
+ SQL
53
+ end
54
+ should "list the packages" do
55
+ assert_equal ["oci8_simple_package"], @show.run("packages")
56
+ end
57
+ end
58
+
59
+ context "Show procedures" do
60
+ setup do
61
+ @client.run "drop procedure oci8_simple_procedure" rescue nil
62
+ @client.run <<-SQL
63
+ CREATE PROCEDURE oci8_simple_procedure AS
64
+ BEGIN
65
+ SELECT 1 FROM DUAL;
66
+ END
67
+ SQL
68
+ end
69
+ should "list the procedures" do
70
+ assert_equal ["oci8_simple_procedure"], @show.run("procedures")
71
+ end
72
+ end
73
+
74
+ context "Show sequences" do
75
+ setup do
76
+ @client.run "drop sequence oci8_simple_sequence" rescue nil
77
+ @client.run <<-SQL
78
+ CREATE SEQUENCE oci8_simple_sequence
79
+ SQL
80
+ end
81
+ should "list the sequences" do
82
+ assert_equal ["oci8_simple_sequence"], @show.run("sequences")
83
+ end
84
+ end
85
+
86
+ context "show synonyms" do
87
+ setup do
88
+ @client.run "drop synonym oci8_simple_synonym" rescue nil
89
+ @client.run <<-SQL
90
+ CREATE SYNONYM oci8_simple_synonym
91
+ FOR DUAL
92
+ SQL
93
+ end
94
+ should "list the synonyms" do
95
+ assert_equal ["oci8_simple_synonym"], @show.run("synonyms")
96
+ end
97
+ end
98
+
99
+ context "show types" do
100
+ setup do
101
+ @client.run "drop type oci8_simple_type" rescue nil
102
+ @client.run <<-SQL
103
+ CREATE TYPE oci8_simple_type AS OBJECT
104
+ ( id NUMBER(6))
105
+ SQL
106
+ end
107
+ should "list the types" do
108
+ assert_equal ["oci8_simple_type"], @show.run("types")
109
+ end
110
+ end
111
+
112
+ context "show views" do
113
+ setup do
114
+ @client.run "drop view oci8_simple_view" rescue nil
115
+ @client.run <<-SQL
116
+ CREATE VIEW oci8_simple_view AS
117
+ SELECT sysdate AS dabba FROM DUAL
118
+ SQL
119
+ end
120
+ should "list the views" do
121
+ assert_equal ["oci8_simple_view"], @show.run("views")
122
+ end
123
+ end
124
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oci8_simple
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Billy Reisinger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-30 00:00:00 -05:00
18
+ date: 2011-07-06 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,6 +116,7 @@ description: |-
116
116
  The only prerequisite to running this code is that you have installed the ruby-oci8 gem on your machine.
117
117
  email: billy.reisinger@gmail.com
118
118
  executables:
119
+ - show
119
120
  - oci8_simple
120
121
  - describe
121
122
  extensions: []
@@ -132,15 +133,19 @@ files:
132
133
  - VERSION
133
134
  - bin/describe
134
135
  - bin/oci8_simple
136
+ - bin/show
135
137
  - lib/oci8_simple.rb
136
138
  - lib/oci8_simple/cli.rb
137
139
  - lib/oci8_simple/client.rb
140
+ - lib/oci8_simple/command.rb
138
141
  - lib/oci8_simple/describe.rb
142
+ - lib/oci8_simple/show.rb
139
143
  - oci8_simple.gemspec
140
144
  - test/cli_test.rb
141
145
  - test/client_test.rb
142
146
  - test/describe_test.rb
143
147
  - test/helper.rb
148
+ - test/show_test.rb
144
149
  has_rdoc: true
145
150
  homepage: http://github.com/unclebilly/oci8_simple
146
151
  licenses:
@@ -180,3 +185,4 @@ test_files:
180
185
  - test/client_test.rb
181
186
  - test/describe_test.rb
182
187
  - test/helper.rb
188
+ - test/show_test.rb