class DbMeta::Oracle::Column

Attributes

comment[RW]
data_default[RW]
data_length[RW]
data_precision[RW]
data_scale[RW]
name[RW]
nullable[RW]
type[RW]

Public Class Methods

all(args = {}) click to toggle source
# File lib/db_meta/oracle/types/column.rb, line 16
def self.all(args = {})
  columns = []
  connection = Connection.instance.get
  cursor = connection.exec("select column_name, data_type, data_length, data_precision, data_scale, nullable, data_default from user_tab_columns where table_name = '#{args[:object_name]}' order by column_id")
  while (row = cursor.fetch)
    column = Column.new(row)
    column.name = row[0].to_s
    column.type = row[1].to_s
    column.data_length = row[2].to_i
    column.data_precision = row[3].to_i
    column.data_scale = row[4].to_i
    column.nullable = row[5].to_s
    column.data_default = row[6].to_s

    # column comments
    cursor2 = connection.exec("select comments from user_col_comments where table_name = '#{args[:object_name]}' and column_name = '#{column.name}'")
    while (row2 = cursor2.fetch)
      column.comment = row2[0].to_s
    end
    cursor2.close
    columns << column

  end
  cursor.close

  columns
rescue
  connection.loggoff
end
new(args = {}) click to toggle source
# File lib/db_meta/oracle/types/column.rb, line 6
def initialize(args = {})
end

Public Instance Methods

extract() click to toggle source
# File lib/db_meta/oracle/types/column.rb, line 9
def extract
  buffer = ("%-30s" % @name).to_s
  buffer << " #{convert_type}"
  buffer << " DEFAULT #{@data_default.strip}" if @data_default.size > 0
  buffer
end

Private Instance Methods

convert_type() click to toggle source
# File lib/db_meta/oracle/types/column.rb, line 48
def convert_type
  case @type
    when "FLOAT"
      buffer = @type.to_s
      buffer << "(#{@data_precision})" unless @data_precision == 0
      buffer
    when "NUMBER"
      buffer = @type.to_s
      buffer << "(#{@data_precision}" unless @data_precision == 0
      buffer << ",#{@data_scale}" unless @data_scale == 0
      buffer << ")" if buffer.include?("(")
      buffer
    when /CHAR|RAW/
      "#{@type}(#{@data_length} BYTE)"
    else
      @type
  end
end