Class: DbMeta::Oracle::View
- Defined in:
- lib/db_meta/oracle/types/view.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#extract_type, #name, #status, #system_object, #type
Instance Method Summary collapse
- #extract(args = {}) ⇒ Object
- #fetch(args = {}) ⇒ Object
-
#initialize(args = {}) ⇒ View
constructor
A new instance of View.
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 = {}) ⇒ View
6 7 8 9 10 |
# File 'lib/db_meta/oracle/types/view.rb', line 6 def initialize(args={}) super(args) @comment = nil # view level comment end |
Instance Method Details
#extract(args = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/db_meta/oracle/types/view.rb', line 28 def extract(args={}) buffer = [block(@name)] buffer << "CREATE OR REPLACE VIEW #{@name}" buffer << '(' # add columns @columns.each_with_index do |c, index| buffer << " #{c.name}#{',' if index+1 < @columns.size}" end buffer << ')' buffer << "AS" buffer << @source.strip buffer[-1] += ';' buffer << nil # view comments if @comment buffer << "COMMENT ON VIEW #{@name} IS '#{@comment.text("'","''")}';" end # view column comments @columns.each do |column| next if column.comment.size == 0 buffer << "COMMENT ON COLUMN #{@name}.#{column.name} IS '#{column.comment.gsub("'","''")}';" end buffer.join("\n") end |
#fetch(args = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/db_meta/oracle/types/view.rb', line 12 def fetch(args={}) @comment = Comment.find(type: 'TABLE', name: @name) @columns = Column.all(object_name: @name) @source = "" connection = Connection.instance.get cursor = Connection.instance.get.exec("select text from user_views where view_name = '#{@name}'") while row = cursor.fetch() @source << row[0].to_s end cursor.close ensure connection.logoff end |