NAME

Parse::Dia::SQL::Output - Base sql formatter class.

SYNOPSIS

use Parse::Dia::SQL;
my $dia = Parse::Dia::SQL->new(...);
my $output = $dia->get_output_instance();
print $output->get_sql();

DESCRIPTION

This is the base sql formatter class for creating sql. It contains basic functionality, which can be overridden in subclasses, one for each RDBMS.

SEE ALSO

Parse::Dia::SQL::Output::DB2
Parse::Dia::SQL::Output::Oracle

new

The constructor. Arguments:

db    - the target database type

_init_log

Initialize logger

_init_const

Initialize Constants component

_init_utils

Initialize Parse::Dia::SQL::Utils class.

get_comment

Return string with comment containing target database, $VERSION, time and list of files etc.

get_sql

Return all sql

get_inserts

Return insert statements. These are based on content of the components, and split on the linefeed character ("\n").

Add $self->{end_of_statement} to each statement.

get_constraints_drop

drop all constraints (e.g. foreign keys and indices)

This sub is split into two parts to make it easy sub subclass either.

_get_fk_drop

drop all foreign keys

_get_index_drop

drop all indices

_get_drop_index_sql

create drop index for index on table with given name. Note that the tablename is not used here, but many of the overriding subclasses use it, so we include both the tablename and the indexname as arguments to keep the interface consistent.

get_view_drop

create drop view for all views

_check_components

Sanity check on internal state.

Return true if and only if

$self->{components} should be a defined array ref with 1 or more
hash ref elements having two keys 'name' and 'text'

otherwise false.

_check_classes

Sanity check on internal state.

Return true if and only if

$self->{classes} should be a defined array ref with 1 or more elements

_check_associations

Sanity check on internal state.

Return true if and only if

$self->{associations} should be a defined array ref with 1 or more elements

otherwise false.

_check_attlist

Sanity check on given reference.

Return true if and only if

$arg should be a defined hash ref with 1 or more elements
$arg->{name} exists and is a defined scalar
$arg->{attList} exists and is a defined array ref.

otherwise false.

get_schema_drop

create drop table for all tables

TODO: Consider rename to get_table[s]_drop

get_permissions_drop

Create revoke sql

get_permissions_create

Create grant sql

get_associations_create

create associations statements:

This includes the following elements

- foreign key
- index
- unique index

get_schema_create

create table statements

get_view_create

create view statements

_create_pk_string

Create primary key clause, e.g.

constraint pk_<tablename> primary key (<column1>,..,<columnN>)

Returns undefined if list of primary key is empty (i.e. if there are no primary keys on given table).

_get_create_table_sql

Create sql for given table.

_format_columns

	Format columns in tabular form using Text::Table.

 Input:  arrayref of arrayrefs
 Output: arrayref of arrayrefs

_get_create_view_sql

Create sql for given view.

Similar to _get_create_table_sql, but must handle 'from', 'where', 'order by', 'group by',

TODO: ADD support for 'having' clause.

_get_create_association_sql

Create sql for given association.

_get_create_index_sql

Create sql for all indices for given table.

Super class for outputting SQL