NAME

Parse::Dia::SQL::Output::SQLite3 - Create SQL for SQLite version 3.

SYNOPSIS

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

DESCRIPTION

This sub-class creates SQL for the SQLite database version 3.

new

The constructor.

Object names in SQLite have no inherent limit. 60 has been arbitrarily chosen.

_get_create_table_sql

Generate create table statement for a single table using SQLite syntax:

Includes class comments before the table definition.

Includes autoupdate triggers based on the class comment.

autoupdate triggers

If the class comment includes a line like:

<autoupdate:foo/>

Then an 'after update' trigger is generated for this table which executes the statement foo for the updated row.

Examples of use include tracking record modification dates (<autoupdate:dtModified=datetime('now')/>) or deriving a value from another field (<autoupdate:sSoundex=soundex(sName)/>)

get_schema_drop

Generate drop table statments for all tables using SQLite syntax:

drop table I<foo> if exists

get_view_drop

Generate drop view statments for all tables using SQLite syntax:

drop view I<foo> if exists

_get_fk_drop

Drop foreign key enforcement triggers using SQLite syntax:

drop trigger I<foo> if exists

The automatically generated foreign key enforcement triggers are:

See _get_create_association_sql for more details.

  • constraint_name_bi_tr

  • constraint_name_bu_tr

  • constraint_name_buparent_tr

  • constraint_name_bdparent_tr

_get_drop_index_sql

drop index statement using SQLite syntax:

drop index I<foo> if exists

get_permissions_create

SQLite doesn't support permissions, so supress this output.

get_permissions_drop

SQLite doesn't support permissions, so supress this output.

_get_create_association_sql

Create the foreign key enforcement triggers using SQLite syntax:

create trigger I<fkname>[_bi_tr|_bu_tr|_bdparent_tr|_buparent_tr]

Because SQLite doesn't natively enforce foreign key constraints (see http://www.sqlite.org/omitted.html), we use triggers to emulate this behaviour.

The trigger names are the default contraint name (something like parent_table_fk_fk_column) with suffixes:

  • constraint_name_bi_tr

    Before insert on the child table require that the parent key exists.

  • constraint_name_bu_tr

    Before update on the child table require that the parent key exists.

  • constraint_name_buparent_tr

    Before update on the parent table ensure that there are no dependant child records.

  • constraint_name_bdparent_tr

    Default trigger: Before delete on the parent table ensure that there are no dependant child records.

    If 'on delete cascade' is specified as the contraint (in the multiplicity field): Before delete on the parent table delete all dependant child records.