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

NAME

SeeAlso::Source::DBI - returns links stored in an SQL database (abstract class)

DESCRIPTION

This class wraps a SQL database that can deliver links for a given identifiers. It is an abstract subclass of SeeAlso::Source and should not used directly. Instead you should define a subclass that implements the following methods:

mQuery

The query method as required by SeeAlso::Source. The method gets a SeeAlso::Identifier object and returns a SeeAlso::Response object. The method should croak on errors.

createTable

Purges and (re)create the database table(s). Usually this is done via a <tt>DROP TABLE IF EXISTS ...</tt> followed by a <tt>CREATE TABLE ...</tt>.

insertQuery

Returns a prepared statement to insert a row into the database. You should either implement this method or set the property insertQuery.

loadTable

Returns the name of the standard table to load data into. By default returns the propery loadTable.

METHODS

new ( %options )

Create a new SeeAlso server with a given database connection. Subclasses should set the property dbh with DBI connect. It is recommended to support the following options:

dsi

First parameter for DBI connect method

user

Database user

password

Database Password

limit

A numerical limit for queries

Putting passwords into scripts is not recommended, so you should better use places like pg_service.conf (Postgres) or my.cfg (MySQL).

connected

Return whether a database connection has been established. By default returns the propery dbh.

insertQuery

Returns a prepared statement to insert a row into the database. By default returns the property insertQuery.

loadTable

Returns the name of the standard table to load data into. By default returns the propery loadTable.

loadFile ( %options )

Load data from a local file 'file' into the database. By default the prepared statement returned by insertQuery will be used for each line of the file. If the 'bulk' option is set, a much faster bulk import is tried and data is loaded into the table specified by loadTable. Usage example:

  $db->loadFile( file => "links.tab", bulk => 1 );

The file must contain tabular seperated data.

Up to now bulk import is only implemented for MySQL.

parseInsertString ( $string )

Parse a string to be inserted into the loadTable with insertQuery. Implementations of this method must return undef (on error) or an array that can directly be passed to insertQuery. By default the method just removes a trailing newline and splits the line by tabulators. Other implementations should also validate the data for not to fill the database with junk.

createTable

Purge and (re)create the table table(s). Usually this is done via a <tt>DROP TABLE IF EXISTS ...</tt> followed by a <tt>CREATE TABLE ...</tt>. This method is abstract and will always croak. Any implementation of a subclass should return true on success.

insertResponse ( $response )

Insert links from a SeeAlso::Response object. Not implemented by default.

AUTHOR

Jakob Voss <jakob.voss@gbv.de>

LICENSE

Copyright (C) 2007-2009 by Verbundzentrale Goettingen (VZG) and Jakob Voss

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.