Class: DbMeta::Oracle::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/db_meta/oracle/types/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Column

Returns a new instance of Column.



7
8
# File 'lib/db_meta/oracle/types/column.rb', line 7

def initialize(args={})
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def comment
  @comment
end

#data_defaultObject

Returns the value of attribute data_default.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def data_default
  @data_default
end

#data_lengthObject

Returns the value of attribute data_length.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def data_length
  @data_length
end

#data_precisionObject

Returns the value of attribute data_precision.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def data_precision
  @data_precision
end

#data_scaleObject

Returns the value of attribute data_scale.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def data_scale
  @data_scale
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def name
  @name
end

#nullableObject

Returns the value of attribute nullable.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def nullable
  @nullable
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/db_meta/oracle/types/column.rb', line 5

def type
  @type
end

Class Method Details

.all(args = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/db_meta/oracle/types/column.rb', line 17

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

Instance Method Details

#extractObject



10
11
12
13
14
15
# File 'lib/db_meta/oracle/types/column.rb', line 10

def extract
  buffer = "#{'%-30s' % @name}"
  buffer << " #{convert_type}"
  buffer << " DEFAULT #{@data_default.strip}" if @data_default.size > 0
  return buffer
end