Chris Winters > OpenInteract-1.99_06 > OpenInteract2::Datasource::DBI

Download:
OpenInteract-1.99_06.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.17   Source  

NAME ^

OpenInteract2::Datasource::DBI - Create DBI database handles

SYNOPSIS ^

 # Define the parameters for a database handle 'main' using PostgreSQL
 
 [datasource main]
 type          = DBI
 dbi_type      = Pg
 dsn           = dbname=urkelweb
 username      = webuser
 password      = urkelnut
 
 # Define a handle 'win32' that uses Microsoft SQL Server and connects
 # with ODBC
 
 [datasource win32]
 type          = DBI
 dbi_type      = MSSQL
 use_odbc      = yes
 dsn           = MyDSN
 username      = webuser
 password      = urkelnut
 
 # Request the datasource 'main' from the context object (which in
 # turn requests it from the OpenInteract2::DatasourceManager object,
 # which in turn requests it from this class)
 
 my $dbh = CTX->datasource( 'main' );
 my $sth = $dbh->prepare( "SELECT * FROM urkel_fan" );
 $sth->execute;
 ...

DESCRIPTION ^

No, we do not subclass DBI with this. No, we do not override any of the DBI methods. Instead, we provide the means to connect to the database from one location using nothing more than a datasource name. This is somewhat how the Java Naming and Directory Interface (JNDI) allows you to manage objects, including database connections.

Note that if you are using it this should work flawlessly (although pointlessly) with Apache::DBI, and if you are using this on a different persistent Perl platform (say, PerlEx) then this module gives you a single location from which to retrieve database handles -- this makes using the BEGIN/END tricks ActiveState recommends in their FAQ pretty trivial.

METHODS ^

connect( $datasource_name, \%datasource_info )

Returns: A DBI database handle with the following parameters set:

 RaiseError:  1
 PrintError:  0
 ChopBlanks:  1
 AutoCommit:  1 (for now...)
 LongReadLen: 32768 (or from 'long_read_len' of \%datasource_info)
 LongTruncOk: 0     (or from 'long_trunc_ok' of \%datasource_info)

The parameter \%datasource_info defines how we connect to the database and is pulled from your 'datasource.$name' server configuration.

Any errors encountered will throw an exception, usually of the OpenInteract2::Exception::Datasource variety.

resolve_datasource_info( $name, \%datasource_info )

Internal method used to resolve some shortcuts we allow for usability. This will look at the 'dbi_type' and add keys to the datasource information:

spops

Lists the SPOPS class to use.

driver_name

Lists the DBI driver name to use -- this is what you'd use in the second ':' place in the DBI connect() call.

Returns a new hashref of information. For backwards compatibility, if we see the key spops in \%datasource_info we just return a new hashref with the same data.

SEE ALSO ^

OpenInteract2::Exception::Datasource

Apache::DBI

DBI - http://www.symbolstone.org/technology/perl/DBI

PerlEx - http://www.activestate.com/Products/PerlEx/

COPYRIGHT ^

Copyright (c) 2002-2005 Chris Winters. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS ^

Chris Winters <chris@cwinters.com>

syntax highlighting: