Alzabo::Driver - Alzabo base class for RDBMS drivers
use Alzabo::Driver; my $driver = Alzabo::Driver->new( rdbms => 'MySQL', schema => $schema );
This is the base class for all Alzabo::Driver modules. To instantiate a driver call this class's new method. See "SUBCLASSING Alzabo::Driver" for information on how to make a driver for the RDBMS of your choice.
new
This class throws several, exceptions, one of which, Alzabo::Exception::Driver, has additional methods not present in other exception classes. See "Alzabo::Exception::Driver METHODS" for a description of these methods.
A list of names representing the available Alzabo::Driver subclasses. Any one of these names would be appropriate as the rdbms parameter for the Alzabo::Driver->new method.
Alzabo::Driver
rdbms
Alzabo::Driver->new
rdbms => $rdbms_name
The name of the RDBMS being used.
schema => Alzabo::Schema object
Alzabo::Schema
A new Alzabo::Driver object of the appropriate subclass.
Alzabo::Exception::Eval
A list of strings containing the names of the tables in the database. See the DBI documentation of the DBI->tables method for more details.
DBI
DBI->tables
Alzabo::Exception::Driver
This method takes one optional parameter, a connected DBI handle. If this is given, then this handle is the new handle for the driver.
The active database handle.
Alzabo::Exception::Params
Some of these methods return lists of data (the rows, rows_hashref, and column methods). With large result sets, this can use a lot memory as these lists are created in memory before being returned to the caller. To avoid this, it may be desirable to use the functionality provided by the Alzabo::DriverStatement class, which allows you to fetch results one row at a time.
rows
rows_hashref
column
Alzabo::DriverStatement
sql => $sql_string
bind => $bind_value or \@bind_values
limit => [ $max, optional $offset ] (optional)
$offset defaults to 0.
$offset
This parameters has no effect for the methods that return only one row. For the others, it causes the drivers to skip $offset rows and then return only $max rows. This is useful if the RDBMS being used does not support LIMIT clauses.
$max
LIMIT
An array of array references containing the data requested.
An array of hash references containing the data requested. The hash reference keys are the columns being selected. All the key names are in uppercase.
An array or scalar containing the data returned, depending on context.
A hash containing the data requested. The hash keys are the columns being selected. All the key names are in uppercase.
An array containing the values for the first column of each row returned.
Use this for non-SELECT SQL statements.
The number of rows affected.
A new Alzabo::DriverStatement handle, ready to return data via the Alzabo::DriverStatement->next_row or Alzabo::DriverStatement->next_row_hash methods.
Alzabo::DriverStatement->next_row
Alzabo::DriverStatement->next_row_hash
This class is a wrapper around DBI's statement handles. It finishes automatically as appropriate so the end user does need not worry about doing this.
Use this method in a while loop to fetch all the data from a statement.
An array containing the next row of data for statement or an empty list if no more data is available.
A hash containing the next row of data for statement or an empty list if no more data is available. All the keys of the hash are in uppercase.
Executes the associated statement handle with the given bound parameters. If the statement handle is still active (it was previously executed and has more data left) then its finish method will be called first.
finish
In addition to the methods inherited from Exception::Class::Base, objects in this class also contain several methods specific to this subclass.
Exception::Class::Base
The SQL statement in use at the time the error occurred, if any.
A list of the the bound parameters for the SQL statement, if any.
To create a subclass of Alzabo::Driver for your particular RDBMS is fairly simple. First of all, there must be a DBD::* driver for it, as Alzabo::Driver is built on top of DBI.
DBD::*
Here's a sample header to the module using a fictional RDBMS called FooDB:
package Alzabo::Driver::FooDB; use strict; use vars qw($VERSION); use Alzabo::Driver; use DBI; use DBD::FooDB; use base qw(Alzabo::Driver);
The next step is to implement a new method and the methods listed under "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 {}, $class; 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.
Look at the included Alzabo::Driver 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, what its DBD::* driver is, and include the code you've written so far.
The following methods are not implemented in Alzabo::Driver itself and must be implemented in a subclass.
user => $db_username
password => $db_pw
host => $hostname
port => $port
All of these default to undef. See the appropriate DBD driver documentation for more details.
Some drivers may accept or require more arguments than specified above.
Note that Alzabo::Driver subclasses are not expected to cache connections. If you want to do this please use Apache::DBI under mod_perl or don't call connect more than once per process.
Apache::DBI
connect
Attempts to create a new database for the schema attached to the driver. Some drivers may accept or require more arguments than specified above.
Attempts to drop the database for the schema attached to the driver.
Alzabo::Column
This method is expected to return the value of the next sequence number based on a column object. For some databases (MySQL, for example), the appropriate value is undef. This is accounted for in Alzabo code that calls this method.
undef
Notify Alzabo that you wish to start a transaction.
Not yet determined.
Rolls back the current transaction.
Notify Alzabo that you wish to finish a transaction. This is basically the equivalent of calling commit.
The last primary key id created via a sequenced column.
Dave Rolsky, <dave@urth.org>
To install Alzabo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Alzabo
CPAN shell
perl -MCPAN -e shell install Alzabo
For more information on module installation, please visit the detailed CPAN module installation guide.