NAME

Persist::Driver::DBI - Base class for Persist DBI drivers

SYNOPSIS

package Some::Driver;

use strict;
use warnings;

use Persist qw(:constants);

use base 'Persist::Driver::DBI';

sub new { ... }
sub is_dba { ... }
sub new_source { ... }
sub delete_source { ... }
sub new_table { ... }
sub delete_table { ... }
sub columns { ... }
sub indexes { ... }
sub sequence_value { ... }

DESCRIPTION

This is a base class for drivers that implement DBI based database access. This provides some basic functionality that should be fairly common to most DBI drivers.

This POD document is intended for use by driver developers and shouldn't (generally) be relevent to developers just using the library. However, for those interested in internals, feel free to read on.

$driver = new Persist::Driver::DBI(%args)

After connecting to the database in it's new method, the implementor should pass the reference to the DBI handle to this new method to instantiate the class. The handle will be stored in the ``-database'' key of the blessed hash for the object--however, it should be accessed through handle.

The arguments %args accepted are:

$database

A DBI database handle.

$dbh = $driver->handle

This method provides access to the DBI dabatase connection handle.

@tables = $driver->tables

Uses the DBI tables method to fetch the tables in the current schema.

$pp_filter = $driver->preprocess_filter(%args)

Processes a filter to turn it into a proper WHERE clause for the DBI driver. The default implementation returns the string unchanged or raises an exception if it is not parsable by "parse_filter" in Persist::Filter. Implementations that need to process a filter should look into using Persist::Filter as an aid.

This method is called whenever a filter is used in an SQL query.

The arguments %args accepted are:

$aliases

The $aliases argument is a hash reference of tables and aliases. Each key is an alias to the table the key points to. This allows the preprocessor to perform processing based upon the structure of the tables. If the tables aren't aliased, then the table names will be both the key and value.

$filter

The filter to process.

Returns the processed filter.

$handle = $driver->open_table(%args)

Returns a two element array reference. The first element of this reference is another array reference containing the name of the table opened. The second element is a reference to a DBI statement handle. The filter will be processed via preprocess_filter prior to being inserted as the WHERE clause of the SQL statement.

See Persist::Driver for a description of the arguments.

$handle = $driver->open_join(%args)

Returns a two element array of the same form returned by open_table, except that the first element is an array reference containing the names of all tables joined. The tables are joined using an INNER JOIN expression in the FROM clause based upon the information returned by indexes. The filters will be joined together with an AND operator and then processed by preprocess_filter.

The ON clauses of the joins are not currently run through preprocess_filter, this is not yet considered a bug, but will be if such preprocessing is needed by a derived driver in the future. (The ON clauses are simple enough that it is probably reasonable to assume that such preprocessing is only likely to add overhead rather than utility.)

See Persist::Driver for a description of the arguments.

$handle = $driver->open_explicit_join(%args)

Returns an array reference of the same form returned by open_join. The tables are joined using an INNER JOIN expression with the ON clauses specified by the user. The filter is processed by preprocess_filter prior to being used in the WHERE clause.

As in open_join, the ON expressions are not preprocessed. This is, again, not yet considered a bug, but will be if it is discovered that this behavior is problematic. Since the ON expressions are specified by the user rather than by this package definition, it is much more likely that this will have problems, but since ON filters are still, generally, very simple, such problems aren't expected.

See Persist::Driver for a description of the arguments.

$rows = $driver->insert(%args)

See Persist::Driver for a description of this method..

$rows = $driver->update(%args)

Updates zero or more rows. The filter is processed by preprocess_filter prior to use in the WHERE clause.

$rows = $driver->delete(%args)

Delets zero or more rows. The filter is processed by preprocess_filter prior to use in the WHERE clause.

$row = $driver->first($handle)

In accordance with the DBI specification, the finish method is called on the handle to clean up the statement handle, then execute is called again and the first row is fetched. This method probably has much higher overhead than a simple next call.

$row = $driver->next($handle)

Fetches the next row.

$driver->DESTROY

Disconnects from the database. If a derived driver needs to override DESTROY it is important that the driver make a call to SUPER::DESTROY to disconnect from the database as some DBD drivers don't like to reach DESTROY without seeing a disconnect first.

SEE ALSO

Persist, Persist::Driver, DBI

AUTHOR

Andrew Sterling Hanenkamp, <hanenkamp@users.sourceforge.net>

COPYRIGHT AND LICENSE

Copyright (c) 2003, Andrew Sterling Hanenkamp
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
are met:

  * Redistributions of source code must retain the above copyright 
    notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright 
    notice, this list of conditions and the following disclaimer in 
    the documentation and/or other materials provided with the 
    distribution.
  * Neither the name of the Contentment nor the names of its 
    contributors may be used to endorse or promote products derived 
    from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.