The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Alzabo::RDBMSRules - Base class for Alzabo RDBMS rulesets

SYNOPSIS

  use Alzabo::RDBMSRules;

  my $rules = Alzabo::RDBMSRules( rules => 'MySQL' );

DESCRIPTION

This class is the base class for all Alzabo::RDBMSRules modules. To instantiate a subclass call this class's new method. See the "SUBCLASSING Alzabo::RDBMSRules" section for information on how to make a ruleset for the RDBMS of your choice.

METHODS

available

A list of names representing the available Alzabo::RDBMSRules subclasses. Any one of these names would be appropriate as the rdbms parameter for the Alzabo::RDBMSRules->new method.

new

Parameters

  • rdbms => $rdbms_name

    The name of the RDBMS being used.

Some subclasses may accept additional values.

Returns

A new Alzabo::RDBMSRules object of the appropriate subclass.

schema_sql (Alzabo::Create::Schema object)

Returns

A list of SQL statements.

index_sql (Alzabo::Create::Index object)

Returns

A list of SQL statements.

drop_table_sql (Alzabo::Create::Table object)

Returns

A list of SQL statements.

drop_index_sql (Alzabo::Create::Index object)

Returns

A list of SQL statements.

schema_sql_diff

Parameters

  • new => Alzabo::Create::Schema object

  • old => Alzabo::Create::Schema object

Given two schema objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

An array of SQL statements.

table_sql_diff

Parameters

  • new => Alzabo::Create::Table object

  • old => Alzabo::Create::Table object

Given two table objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

An array of SQL statements.

Virtual Methods

The following methods are not implemented in the Alzabo::RDBMSRules class itself and must be implemented in its subclasses.

validate_schema_name (Alzabo::Schema object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_table_name (Alzabo::Create::Table object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_column_name (Alzabo::Create::Column object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_column_type ($type_as_string)

Returns

A boolean value indicate whether or not this type is valid for the RDBMS.

Throws

Alzabo::Exception::RDBMSRules

validate_column_attribute

Parameters

  • column => Alzabo::Create::Column object

  • attribute => $attribute

This method is a bit different from the others in that it takes an existing column object and a potential attribute.

Returns

A boolean value indicating whether or not this attribute is acceptable for the column.

Throws

Alzabo::Exception::RDBMSRules

validate_primary_key (Alzabo::Create::Column object)

Returns

Returns a boolean value indicating whether or not the given column can be part of its table's primary key.

Throws

Alzabo::Exception::RDBMSRules

validate_sequenced_attribute (Alzabo::Create::Column object)

Given a column object, indicates whether or not the column can be sequenced.

Throws

Alzabo::Exception::RDBMSRules

validate_index (Alzabo::Create::Index object)

Returns

A boolean value indicating whether or not the index is valid.

Throws

Alzabo::Exception::RDBMSRules

table_sql (Alzabo::Create::Table object)

Returns

A list of SQL statements.

column_sql (Alzabo::Create::Column object)

Returns

A list of SQL statements.

foreign_key_sql (Alzabo::Create::ForeignKey object)

Returns

A list of SQL statements.

drop_column_sql (Alzabo::Create::Column object)

Returns

A list of SQL statements.

drop_foreign_key_sql (Alzabo::Create::ForeignKey object)

Returns

A list of SQL statements.

column_sql_add (Alzabo::Create::Column object)

Returns

A list of SQL statements.

column_sql_diff

Parameters

  • new => Alzabo::Create::Column object

  • old => Alzabo::Create::Column object

Given two column objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

index_sql_diff

Parameters

  • new => Alzabo::Create::Index object

  • old => Alzabo::Create::Index object

Given two index objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

foreign_key_sql_diff

Parameters

  • new => Alzabo::Create::ForeignKey object

  • old => Alzabo::Create::ForeignKey object

Given two foreign key objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

alter_primary_key_sql

Parameters

  • new => Alzabo::Create::Table object

  • old => Alzabo::Create::Table object

Given two table objects, this method compares them and generates the SQL necessary to give change the primary key from the 'old' one's primary key to the 'new' one's primary key.

Returns

A list of SQL statements.

reverse_engineer (Alzabo::Create::Schema object)

Given a schema object (which presumably has no tables), this method uses the schema's Alzabo::Driver object to connect to an existing database and reverse engineer it into the appopriate Alzabo objects.

SUBCLASSING Alzabo::RDBMSRules

To create a subclass of Alzabo::RDBMSRules for your particular RDBMS is fairly simple.

Here's a sample header to the module using a fictional RDBMS called FooDB:

 package Alzabo::RDBMSRules::FooDB;

 use strict;
 use vars qw($VERSION);

 use Alzabo::RDBMSRules;

 use base qw(Alzabo::RDBMSRules);

The next step is to implement a new method and the methods listed under the section "Virtual Methods". The new method should look a bit like this:

 1:  sub new
 2:  {
 3:      my $proto = shift;
 4:      my $class = ref $proto || $proto;
 5:      my %p = @_;
 6:
 7:      my $self = bless {}, $self;
 8:
 9:      return $self;
 10:  }

The hash %p contains any values passed to the Alzabo::RDBMSRules->new method by its caller.

Lines 1-7 should probably be copied verbatim into your own new method. Line 5 can be deleted if you don't need to look at the parameters.

The rest of your module should simply implement the methods listed under the "Virtual Methods" section of this documentation.

Look at the included Alzabo::RDBMSRules subclasses for examples. Feel free to contact me for further help if you get stuck. Please tell me what database you're attempting to implement, and include the code you've written so far.

AUTHOR

Dave Rolsky, <dave@urth.org>