Class: Orasaurus::SqlTeardownGenerator
- Defined in:
- lib/orasaurus/generator.rb
Instance Attribute Summary
Attributes inherited from Generator
#build_list, #name, #output_file_name, #output_path
Instance Method Summary collapse
Methods inherited from Generator
#full_output_file_name, #initialize
Constructor Details
This class inherits a constructor from Orasaurus::Generator
Instance Method Details
#generate ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/orasaurus/generator.rb', line 82 def generate if @build_list.empty? then puts "nothing in build list. no need for build file." else teardown_template = %q{ SET SERVEROUTPUT ON SET DEFINE OFF SPOOL teardown.log DECLARE CURSOR cur_drop_list IS SELECT * FROM USER_OBJECTS WHERE OBJECT_NAME IN ( <%=@sql_in_clause%> ) AND OBJECT_TYPE != 'PACKAGE BODY'; x BOOLEAN := FALSE; BEGIN DBMS_OUTPUT.PUT_LINE( 'starting work' ); FOR i IN cur_drop_list LOOP x := TRUE; BEGIN EXECUTE IMMEDIATE 'DROP '||i.object_type||' '||i.object_name||' CASCADE CONSTRAINTS'; DBMS_OUTPUT.PUT_LINE( 'DROPPED '||i.object_name ); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE( 'WHILE DROPPING '||i.object_type||' '||i.object_name ); DBMS_OUTPUT.PUT_LINE( SUBSTR( SQLERRM, 1, 255 ) ); END; END LOOP; IF NOT x THEN DBMS_OUTPUT.PUT_LINE( 'NOTHING FOUND TO DROP' ); END IF; DBMS_OUTPUT.PUT_LINE( 'completed successfully' ); END; / EXIT / } sql_in_clause = "" @build_list.each do |i| if i == build_list.first then sql_in_clause.concat( "'" + i.chomp( File.extname( i ) ).upcase + "'" ) else sql_in_clause.concat( ", '" + i.chomp( File.extname( i ) ).upcase + "'" ) end end script_contents = ERB.new( teardown_template, nil, ">" ).result(binding) script_file = File.new( full_output_file_name, "w" ) script_file.print( script_contents ) puts "creating " + full_output_file_name script_file.close end end |