Class: DbMeta::Oracle::Index
- Defined in:
- lib/db_meta/oracle/types/index.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#index_type ⇒ Object
readonly
Returns the value of attribute index_type.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#tablespace ⇒ Object
readonly
Returns the value of attribute tablespace.
-
#uniqueness ⇒ Object
readonly
Returns the value of attribute uniqueness.
Attributes inherited from Base
#extract_type, #name, #status, #system_object, #type
Instance Method Summary collapse
- #extract(args = {}) ⇒ Object
- #fetch(args = {}) ⇒ Object
-
#initialize(args = {}) ⇒ Index
constructor
A new instance of Index.
Methods inherited from Base
#ddl_drop, from_type, register_type, #system_object?
Methods included from Helper
#block, #create_folder, #pluralize, #remove_folder, #type_sequence, #write_buffer_to_file
Constructor Details
#initialize(args = {}) ⇒ Index
Returns a new instance of Index.
8 9 10 11 12 13 |
# File 'lib/db_meta/oracle/types/index.rb', line 8 def initialize(args = {}) super @extract_type = :embedded @columns = [] end |
Instance Attribute Details
#index_type ⇒ Object (readonly)
Returns the value of attribute index_type.
6 7 8 |
# File 'lib/db_meta/oracle/types/index.rb', line 6 def index_type @index_type end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/db_meta/oracle/types/index.rb', line 6 def table_name @table_name end |
#tablespace ⇒ Object (readonly)
Returns the value of attribute tablespace.
6 7 8 |
# File 'lib/db_meta/oracle/types/index.rb', line 6 def tablespace @tablespace end |
#uniqueness ⇒ Object (readonly)
Returns the value of attribute uniqueness.
6 7 8 |
# File 'lib/db_meta/oracle/types/index.rb', line 6 def uniqueness @uniqueness end |
Instance Method Details
#extract(args = {}) ⇒ Object
45 46 47 |
# File 'lib/db_meta/oracle/types/index.rb', line 45 def extract(args = {}) "CREATE#{(@uniqueness == "UNIQUE") ? " UNIQUE" : nil} INDEX #{@name} ON #{@table_name}(#{@columns.join(", ")});" end |
#fetch(args = {}) ⇒ Object
15 16 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 |
# File 'lib/db_meta/oracle/types/index.rb', line 15 def fetch(args = {}) connection_class = args[:connection_class] || Connection connection = connection_class.instance.get cursor = connection.exec("select index_type, table_name, uniqueness, tablespace_name from user_indexes where index_name = '#{@name}'") while (row = cursor.fetch) @index_type = row[0].to_s @table_name = row[1].to_s @uniqueness = row[2].to_s @tablespace = row[3].to_s end cursor.close # involved columns cursor = connection.exec("select column_name from user_ind_columns where index_name = '#{@name}' order by column_position") while (row = cursor.fetch) @columns << row[0].to_s end cursor.close # columns for function based indexs cursor = connection.exec("select column_expression, column_position from user_ind_expressions where index_name = '#{@name}' order by column_position") while (row = cursor.fetch) idx = row[1].to_i - 1 @columns[idx] = row[0] # replace sys_... entry end cursor.close ensure connection.logoff end |