Class: Oci8Simple::Describe
- Inherits:
-
Object
- Object
- Oci8Simple::Describe
- Includes:
- Command
- Defined in:
- lib/oci8_simple/describe.rb
Overview
Description
This class creates a string describing a table’s columns, intended to be displayed in a fixed-width font.
Usage
Oci8Simple::Describe.new("development").run("users")
Constant Summary collapse
- SPACE_BETWEEN =
2
- FIELDS =
[ {:select => "NULLABLE", :header => "Required", :content => :format_nullable, :right => true}, {:select => "lower(COLUMN_NAME)", :header=> "Name"}, {:select => "lower(DATA_TYPE)", :header => "Type"}, {:select => "DATA_LENGTH", :header => "Size", :content => :format_size}, {:select => "CHAR_USED", :header => "Char?", :content => :format_char_used}, {:select => "CHAR_LENGTH", :header => "Char_size", :content => :format_char_length}, {:select => "DATA_PRECISION", :header => "Precision"}, {:select => "DATA_SCALE", :header => "Scale"}, {:select => "DATA_DEFAULT", :header => "Default", :content => :format_default, :max => 10} ]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(env = nil) ⇒ Describe
constructor
A new instance of Describe.
- #run(table) ⇒ Object
Methods included from Command
Constructor Details
#initialize(env = nil) ⇒ Describe
Returns a new instance of Describe.
35 36 37 |
# File 'lib/oci8_simple/describe.rb', line 35 def initialize(env=nil) @env = env || "development" end |
Class Method Details
.run_from_argv ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/oci8_simple/describe.rb', line 43 def self.run_from_argv o = (self.usage) if(ARGV[0].nil?) puts o else puts self.new(@options[:environment]).run(ARGV[0]) end end |
.usage ⇒ Object
39 40 41 |
# File 'lib/oci8_simple/describe.rb', line 39 def self.usage "Usage: #{$0} TABLE_NAME [ENVIRONMENT]" end |
Instance Method Details
#run(table) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/oci8_simple/describe.rb', line 23 def run(table) sql = <<-SQL select #{select_fields} from user_tab_columns where table_name='#{table.upcase}' order by column_name asc SQL results = client.run(sql) calculate_widths(results) format_results(results) end |