oci8_simple 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -0
- data/VERSION +1 -1
- data/bin/describe +5 -0
- data/lib/oci8_simple/client.rb +5 -2
- data/lib/oci8_simple/describe.rb +59 -0
- data/lib/oci8_simple.rb +2 -1
- data/oci8_simple.gemspec +7 -4
- data/test/describe_test.rb +30 -0
- metadata +10 -5
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/describe
ADDED
data/lib/oci8_simple/client.rb
CHANGED
@@ -90,12 +90,15 @@ environment:
|
|
90
90
|
ERR
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
# Create and return raw Oci8 connection
|
95
94
|
def conn
|
96
95
|
@conn ||= new_connection
|
97
96
|
end
|
98
97
|
|
98
|
+
private
|
99
|
+
|
100
|
+
|
101
|
+
|
99
102
|
def new_connection
|
100
103
|
c = OCI8.new(config["username"], config["password"], config["database"])
|
101
104
|
c.autocommit = true
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Oci8Simple::Describe
|
2
|
+
def initialize(env=nil)
|
3
|
+
@env = env || "development"
|
4
|
+
end
|
5
|
+
|
6
|
+
def run(table)
|
7
|
+
description = client.conn.describe_table(table)
|
8
|
+
c = description.columns.sort{|a,b| a.name <=> b.name }
|
9
|
+
max_name = max(c.map(&:name)) + 3
|
10
|
+
max_type = max(c.map {|col| type_and_size(col)}) + 1
|
11
|
+
c.map do |col|
|
12
|
+
"\"#{col.name}\"".ljust(max_name, ' ') + type_and_size(col).ljust(max_type, ' ') + null(col)
|
13
|
+
end.map(&:upcase).join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
def null(col)
|
17
|
+
col.nullable? ? "" : "NOT NULL"
|
18
|
+
end
|
19
|
+
|
20
|
+
def type_and_size(col)
|
21
|
+
str = "#{col.data_type}"
|
22
|
+
if(col.data_type.to_s =~ /varchar/i)
|
23
|
+
str << "(#{col.char_size} CHAR)"
|
24
|
+
elsif(col.data_type == :number)
|
25
|
+
str << "(#{col.precision})"
|
26
|
+
end
|
27
|
+
str
|
28
|
+
end
|
29
|
+
|
30
|
+
def max(arr)
|
31
|
+
arr.map(&:length).max
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.usage
|
35
|
+
"Usage: #{0} TABLE_NAME [ENVIRONMENT]"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.run_from_argv
|
39
|
+
o = OptionParser.new do |opt|
|
40
|
+
opt.banner = usage
|
41
|
+
opt.on("-v", "--version", "Show version") do
|
42
|
+
puts "version #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}"
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
o.parse!
|
47
|
+
if(ARGV[0].nil?)
|
48
|
+
puts o
|
49
|
+
else
|
50
|
+
puts self.new(ARGV[1]).run(ARGV[0])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def client
|
57
|
+
@client ||= Oci8Simple::Client.new(@env)
|
58
|
+
end
|
59
|
+
end
|
data/lib/oci8_simple.rb
CHANGED
data/oci8_simple.gemspec
CHANGED
@@ -5,17 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{oci8_simple}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.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-
|
13
|
-
s.default_executable = %q{oci8_simple}
|
12
|
+
s.date = %q{2011-06-10}
|
14
13
|
s.description = %q{Run single statements against an arbitrary Oracle schema. This client is intended to be used by simple
|
15
14
|
command-line scripts to aid automation. This is *not* meant to replace an ORM such as ActiveRecord + OracleEnhancedAdapter.
|
16
15
|
The only prerequisite to running this code is that you have installed the ruby-oci8 gem on your machine.}
|
17
16
|
s.email = %q{billy.reisinger@gmail.com}
|
18
|
-
s.executables = ["oci8_simple"]
|
17
|
+
s.executables = ["oci8_simple", "describe"]
|
19
18
|
s.extra_rdoc_files = [
|
20
19
|
"README.rdoc"
|
21
20
|
]
|
@@ -27,13 +26,16 @@ Gem::Specification.new do |s|
|
|
27
26
|
"README.rdoc",
|
28
27
|
"Rakefile",
|
29
28
|
"VERSION",
|
29
|
+
"bin/describe",
|
30
30
|
"bin/oci8_simple",
|
31
31
|
"lib/oci8_simple.rb",
|
32
32
|
"lib/oci8_simple/cli.rb",
|
33
33
|
"lib/oci8_simple/client.rb",
|
34
|
+
"lib/oci8_simple/describe.rb",
|
34
35
|
"oci8_simple.gemspec",
|
35
36
|
"test/cli_test.rb",
|
36
37
|
"test/client_test.rb",
|
38
|
+
"test/describe_test.rb",
|
37
39
|
"test/helper.rb"
|
38
40
|
]
|
39
41
|
s.homepage = %q{http://github.com/unclebilly/oci8_simple}
|
@@ -44,6 +46,7 @@ Gem::Specification.new do |s|
|
|
44
46
|
s.test_files = [
|
45
47
|
"test/cli_test.rb",
|
46
48
|
"test/client_test.rb",
|
49
|
+
"test/describe_test.rb",
|
47
50
|
"test/helper.rb"
|
48
51
|
]
|
49
52
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
class DescribeTest < Test::Unit::TestCase
|
3
|
+
context "Given a table and some data" do
|
4
|
+
setup do
|
5
|
+
@client = Oci8Simple::Client.new("test")
|
6
|
+
@client.run "DROP TABLE OCI8_SIMPLE_TEST CASCADE CONSTRAINTS" rescue nil
|
7
|
+
@client.run <<-SQL
|
8
|
+
CREATE TABLE "OCI8_SIMPLE_TEST"
|
9
|
+
(
|
10
|
+
"NAME" VARCHAR2(400 CHAR) NOT NULL ENABLE,
|
11
|
+
"ID" NUMBER(38,0) NOT NULL ENABLE,
|
12
|
+
"TEXTS" CLOB
|
13
|
+
)
|
14
|
+
SQL
|
15
|
+
@describe = Oci8Simple::Describe.new("test")
|
16
|
+
end
|
17
|
+
context "describing a table" do
|
18
|
+
setup do
|
19
|
+
end
|
20
|
+
should "format results for the command line" do
|
21
|
+
expected=<<-STR
|
22
|
+
"ID" NUMBER(38) NOT NULL
|
23
|
+
"NAME" VARCHAR2(400 CHAR) NOT NULL
|
24
|
+
"TEXTS" CLOB
|
25
|
+
STR
|
26
|
+
assert_equal(expected.chop, @describe.run("oci8_simple_test"))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Billy Reisinger
|
@@ -15,8 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-06-10 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ruby-oci8
|
@@ -117,6 +117,7 @@ description: |-
|
|
117
117
|
email: billy.reisinger@gmail.com
|
118
118
|
executables:
|
119
119
|
- oci8_simple
|
120
|
+
- describe
|
120
121
|
extensions: []
|
121
122
|
|
122
123
|
extra_rdoc_files:
|
@@ -129,13 +130,16 @@ files:
|
|
129
130
|
- README.rdoc
|
130
131
|
- Rakefile
|
131
132
|
- VERSION
|
133
|
+
- bin/describe
|
132
134
|
- bin/oci8_simple
|
133
135
|
- lib/oci8_simple.rb
|
134
136
|
- lib/oci8_simple/cli.rb
|
135
137
|
- lib/oci8_simple/client.rb
|
138
|
+
- lib/oci8_simple/describe.rb
|
136
139
|
- oci8_simple.gemspec
|
137
140
|
- test/cli_test.rb
|
138
141
|
- test/client_test.rb
|
142
|
+
- test/describe_test.rb
|
139
143
|
- test/helper.rb
|
140
144
|
has_rdoc: true
|
141
145
|
homepage: http://github.com/unclebilly/oci8_simple
|
@@ -174,4 +178,5 @@ summary: Run single statements against an arbitrary Oracle schema.
|
|
174
178
|
test_files:
|
175
179
|
- test/cli_test.rb
|
176
180
|
- test/client_test.rb
|
181
|
+
- test/describe_test.rb
|
177
182
|
- test/helper.rb
|