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 "es" in SUBCLASSING Alzabo::RDBMRul section for information on how to make a ruleset for the RDBMS of your choice.

METHODS

  • available

    Returns a list of strings listing the avaiable Alzabo::Driver subclasses. This is a class method.

  • new

    Takes the following parameters:

  • -- rules => $string

    A string giving the name of a ruleset to instantiate. Ruleset names are the name of the Alzabo::RDBMSRules subclass without the leading 'Alzabo::RDBMSRules::' part. For example, the driver name of the Alzabo::RDBMSRules::MySQL class is 'MySQL'.

    Some subclasses may accept additional values.

    The return value of this method is a new Alzabo::RDBMRules object of the appropriate subclass.

  • schema_sql_diff

    Takes the following parameters:

  • -- new => Alzabo::Schema object

  • -- old => Alzabo::Schema object

    Given two schema objects, this method compares them and returns an array of SQL statements which would turn the old schema into the new schema.

  • table_sql_diff

    Takes the following parameters:

  • -- new => Alzabo::Table object

  • -- old => Alzabo::Table object

    Given two table objects, this method compares them and returns an array of SQL statements which would turn the old table into the new table.

Virtual Methods

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

  • validate_schema_name (Alzabo::Schema object)

    Given a schema object, indicates whether its current name is acceptable under the ruleset.

    Exceptions:

    AlzaboRDBMSRulesException - The name is not acceptable

  • validate_table_name (Alzabo::Table object)

    Given a table object, indicates whether its current name is acceptable under the ruleset.

    Exceptions:

    AlzaboRDBMSRulesException - The name is not acceptable

  • validate_column_name (Alzabo::Column object)

    Given a column object, indicates whether its current name is acceptable under the ruleset.

    Exceptions:

    AlzaboRDBMSRulesException - The name is not acceptable

  • validate_column_type ($type_as_string)

    Given a string indicating a column type (such as 'INT' or 'CHAR'), indicates whether or not this is a valid column type.

    Exceptions:

    AlzaboRDBMSRulesException - The column type is not valid

  • validate_column_attribute

    Takes the following parameters:

  • -- column => Alzabo::Column object

  • -- attribute => $attribute

    Given a column and a potential attribute, indicates whether that attribute is valid for the column.

    Exceptions:

    AlzaboRDBMSRulesException - The attribute is not valid

  • validate_primary_key (Alzabo::Column object)

    Given a column object, indicates whether or not the column can be part of a primary key.

    Exceptions:

    AlzaboRDBMSRulesException - The column cannot be part of a primary key

  • validate_sequenced_attribute (Alzabo::Column object)

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

    Exceptions:

    AlzaboRDBMSRulesException - The column cannot be sequenced.

  • validate_index

    Given an index object, indicates whether or not it is valid.

    Exceptions:

    AlzaboRDBMSRulesException - The index is not valid

  • schema_sql

    Given a schema object, returns an array of SQL statements which would create that schema.

  • table_sql

    Given a table object, returns an array of SQL statements which would create that table.

  • column_sql

    Given a column object, returns an array of SQL statements which would create that column.

  • index_sql

    Given a index object, returns an array of SQL statements which wouldcreate that index

  • foreign_key_sql

    Given a foreign key object, returns an array of SQL statements which would create that foreign key. .

  • drop_table_sql

    Given a table object, returns an array of SQL statements which would drop that table.

  • drop_column_sql

    Given a column object, returns an array of SQL statements which would drop that column.

  • drop_index_sql

    Given a index object, returns an array of SQL statements which would drop that index.

  • drop_foreign_key_sql

    Given a foreign key object, returns an array of SQL statements which would drop that foreign key.

  • column_sql_add

    Given a column object, returns an array of SQL statements which would add that column to the appropriate table.

  • column_sql_diff

    Takes the following parameters:

  • -- new => Alzabo::Column object

  • -- old => Alzabo::Column object

    Given two column objects, this method compares them and returns an array of SQL statements which would turn the old column into the new column.

  • index_sql_diff

    Takes the following parameters:

  • -- new => Alzabo::Index object

  • -- old => Alzabo::Index object

    Given two index objects, this method compares them and returns an array of SQL statements which would turn the old index into the new index.

  • foreign_key_sql_diff

    Takes the following parameters:

  • -- new => Alzabo::ForeignKey object

  • -- old => Alzabo::ForeignKey object

    Given two foreign key objects, this method compares them and returns an array of SQL statements which would turn the old foreign key into the new foreign key.

  • alter_primary_key_sql

    Takes the following parameters:

  • -- new => Alzabo::Table object

  • -- old => Alzabo::Table object

    Given two table objects with different primary keys, this method compares them and returns an array of SQL statements which would turn the old table's primary key into the new table's primary key.

  • reverse_engineer (Alzabo::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::Driver 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::Driver->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>

16 POD Errors

The following errors were encountered while parsing the POD:

Around line 325:

Expected '=item *'

Around line 341:

Expected '=item *'

Around line 343:

Expected '=item *'

Around line 353:

Expected '=item *'

Around line 355:

Expected '=item *'

Around line 410:

Expected '=item *'

Around line 412:

Expected '=item *'

Around line 500:

Expected '=item *'

Around line 502:

Expected '=item *'

Around line 512:

Expected '=item *'

Around line 514:

Expected '=item *'

Around line 524:

Expected '=item *'

Around line 526:

Expected '=item *'

Around line 536:

Expected '=item *'

Around line 538:

Expected '=item *'

Around line 550:

You forgot a '=back' before '=head1'