class DataMetaDom::MySqlLexer::SqlOutput

Encapsulates 4 parts of DDL related SQL output:

Attributes

couple[R]

Open output file into the couple SQL DDL statements, creating foreign keys

create[R]

Open output file into create SQL DDL statements (CREATE TABLE)

drop[R]

Open output file into drop SQL DDL statements (DROP TABLE)

uncouple[R]

Open output file into the uncouple SQL DDL statements, dropping foreign keys

Public Class Methods

new(sqlTargetDir) click to toggle source

Creates an instance into the given target directory in which all 4 parts of the SQL DDL process will be created.

# File lib/dataMetaDom/mySql.rb, line 91
        def initialize(sqlTargetDir)
            @selTargetDir = sqlTargetDir
            @create = File.new("#{sqlTargetDir}/DDL-create.sql", 'wb')
            @drop = File.new("#{sqlTargetDir}/DDL-drop.sql", 'wb')
            @couple = File.new("#{sqlTargetDir}/DDL-couple.sql", 'wb')
            @uncouple = File.new("#{sqlTargetDir}/DDL-uncouple.sql", 'wb')
            @allScriptFiles = [@create, @drop, @couple, @uncouple]
            @dropScripts = [@uncouple, @drop]
            @allScriptFiles.each { |f|
                f.puts %q</* Generated by DataMeta DOM MySQL utility
DO NOT EDIT MANUALLY, update the DataMeta DOM source and regen.
*/
>
            }
            @dropScripts.each { |ds|
                ds.puts %q<
/* Disable all checks for safe dropping without any errors */
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

>
            }
        end

Public Instance Methods

close() click to toggle source

Safely closes all the output files.

# File lib/dataMetaDom/mySql.rb, line 119
        def close
            @dropScripts.each { |ds|
                ds.puts %q<

/* Re-enable all checks disabled earlier */
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
>
            }
            @allScriptFiles.each { |f|
                begin
                    f.close
                rescue Exception => x;
                    $stderr.puts x.message
                end
            }
        end