Class: OracleToMysql::Command::WriterSqlplusCommandsToFile

Inherits:
OracleToMysql::Command show all
Defined in:
lib/oracle_to_mysql/command/write_sqlplus_commands_to_file.rb

Defined Under Namespace

Classes: MaxLineExceeded

Instance Attribute Summary

Attributes inherited from OracleToMysql::Command

#client_class

Instance Method Summary collapse

Methods inherited from OracleToMysql::Command

#error, #execute, #finished, #info, #output, #started, #warn

Instance Method Details

#execute_internalObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/oracle_to_mysql/command/write_sqlplus_commands_to_file.rb', line 51

def execute_internal
  bytes_written = 0      
  File.open(self.client_class.otm_get_file_name_for(:oracle_commands),'w') do |f|        
    bytes_written = f.write(self.string_to_write_commands_file_name)
  end
  if bytes_written > 0
    self.info("#{bytes_written} bytes written to #{self.client_class.otm_get_file_name_for(:oracle_commands)}")
  else
    self.error("could not write to #{self.client_class.otm_get_file_name_for(:oracle_commands)}, bytes_written=#{bytes_written}")
  end
end

#string_to_write_commands_file_nameObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oracle_to_mysql/command/write_sqlplus_commands_to_file.rb', line 22

def string_to_write_commands_file_name
  self.validate_otm_source_sql
  the_file_to_spool_output_to = self.client_class.otm_get_file_name_for(:oracle_output)
  return "
      WHENEVER SQLERROR EXIT 2;
      spool on;
      set heading off
      set echo off
      set verify off
      set termout off
      SET NEWPAGE 0;
      SET SPACE 0;
      SET PAGESIZE 0;
      SET FEEDBACK OFF;
      SET TRIMSPOOL ON;
      SET TAB OFF;
      set linesize 2000;
      spool #{the_file_to_spool_output_to}
      #{self.client_class.otm_source_sql}
      spool off;
      exit;          
      "      
end

#temp_file_symbolsObject

overridden from parent to help CleanupTempFilesAndTables do it’s job



47
48
49
# File 'lib/oracle_to_mysql/command/write_sqlplus_commands_to_file.rb', line 47

def temp_file_symbols
  [:oracle_commands]
end

#validate_otm_source_sqlObject

Oracle and sqlplus is so finicky, this captures some of the errors I’ve come across, it is not exhuastive



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/oracle_to_mysql/command/write_sqlplus_commands_to_file.rb', line 7

def validate_otm_source_sql
  the_source_sql = self.client_class.otm_source_sql

  # last character minus white space must be a ";"
  raise "otm_source_sql not terminated with a ';'" if the_source_sql.strip[-1..-1] != ';'
  
  # Detect and prevent sqlplus from SP2-0027: Input is too long (> 2499 characters) - line ignored
  the_source_sql.each_line {|x| raise MaxLineExceeded.new("Ruby detection and prevention of Oracle error SP2-0027: Input is too long (> 2499 characters) - line ignored") if x.length > 2499}
  
  # other sqlplus CAVEATS (that could be programmed, TODO-ish)
  # If you're "IN" statements has more than 1000 elements, Oracle will barf out a ORA-01795 error
  # 
end