DBIx::SearchBuilder::Handle - Perl extension which is a generic DBI handle use DBIx::SearchBuilder::Handle; my $handle = DBIx::SearchBuilder::Handle->new(); $handle->Connect( Driver => 'mysql', Database => 'dbname', Host => 'hostname', User => 'dbuser', Password => 'dbpassword'); This class provides a wrapper for DBI handles that can also perform a number of additional functions.

new
Generic constructor

Connect PARAMHASH: Driver, Database, Host, User, Password
Takes a paramhash and connects to your DBI datasource. You should _always_ set DisconnectHandleOnDestroy => 1 unless you have a legacy app like RT2 or RT 3.0.{0,1,2} that depends on the broken behaviour. =cut sub Connect { my $self = shift; my %args = ( Driver => undef, Database => undef, Host => undef, SID => undef, Port => undef, User => undef, Password => undef, RequireSSL => undef, DisconnectHandleOnDestroy => undef, @_); my $dsn = $self->DSN; # Setting this actually breaks old RT versions in subtle ways. So we need to explicitly call it $self->{'DisconnectHandleOnDestroy'} = $args{'DisconnectHandleOnDestroy'}; $self->BuildDSN(%args); # Only connect if we're not connected to this source already if ((! $self->dbh ) || (!$self->dbh->ping) || ($self->DSN ne $dsn) ) { my $handle = DBI->connect($self->DSN, $args{'User'}, $args{'Password'}) || croak "Connect Failed $DBI::errstr\n" ; #databases do case conversion on the name of columns returned. #actually, some databases just ignore case. this smashes it to something consistent $handle->{FetchHashKeyName} ='NAME_lc'; #Set the handle $self->dbh($handle); return (1); } return(undef); } # }}} # {{{ BuildDSN

BuildDSN PARAMHASH
Takes a bunch of parameters: Required: Driver, Database, Optional: Host, Port and RequireSSL Builds a DSN suitable for a DBI connection

DSN
Returns the DSN for this database connection.

RaiseError [MODE]
Turns on the Database Handle's RaiseError attribute.

PrintError [MODE]
Turns on the Database Handle's PrintError attribute.

LogSQLStatements BOOL
Takes a boolean argument. If the boolean is true, SearchBuilder will log all SQL statements, as well as their invocation times and execution times. Returns whether we're currently logging or not as a boolean

_LogSQLStatement STATEMENT DURATION
add an SQL statement to our query log

ClearSQLStatementLog
Clears out the SQL statement log.

SQLStatementLog
Returns the current SQL statement log as an array of arrays. Each entry is a triple of (Time, Statement, Duration)

AutoCommit [MODE]
Turns on the Database Handle's AutoCommit attribute.

Disconnect
Disconnect from your DBI datasource

dbh [HANDLE]
Return the current DBI handle. If we're handed a parameter, make the database handle that.

UpdateRecordValue
Takes a hash with fields: Table, Column, Value PrimaryKeys, and IsSQLFunction. Table, and Column should be obvious, Value is where you set the new value you want the column to have. The primary_keys field should be the lvalue of DBIx::SearchBuilder::Record::PrimaryKeys(). Finally IsSQLFunction is set when the Value is a SQL function. For example, you might have ('Value'=>'PASSWORD(string)'), by setting IsSQLFunction that string will be inserted into the query directly rather then as a binding.

UpdateTableValue TABLE COLUMN NEW_VALUE RECORD_ID IS_SQL
Update column COLUMN of table TABLE where the record id = RECORD_ID. if IS_SQL is set, don\'t quote the NEW_VALUE

SimpleQuery QUERY_STRING, [ BIND_VALUE, ... ]
Execute the SQL string specified in QUERY_STRING

FetchResult QUERY, [ BIND_VALUE, ... ]
Takes a SELECT query as a string, along with an array of BIND_VALUEs If the select succeeds, returns the first row as an array. Otherwise, returns a Class::ResturnValue object with the failure loaded up.

BinarySafeBLOBs
Returns 1 if the current database supports BLOBs with embedded nulls. Returns undef if the current database doesn't support BLOBs with embedded nulls

KnowsBLOBs
Returns 1 if the current database supports inserts of BLOBs automatically. Returns undef if the current database must be informed of BLOBs for inserts.

BLOBParams FIELD_NAME FIELD_TYPE
Returns a hash ref for the bind_param call to identify BLOB types used by the current database for a particular column type.

DatabaseVersion
Returns the database's version. The base implementation uses a "SELECT VERSION"

CaseSensitive
Returns 1 if the current database's searches are case sensitive by default Returns undef otherwise

_MakeClauseCaseInsensitive FIELD OPERATOR VALUE
Takes a field, operator and value. performs the magic necessary to make your database treat this clause as case insensitive. Returns a FIELD OPERATOR VALUE triple.

BeginTransaction
Tells DBIx::SearchBuilder to begin a new SQL transaction. This will temporarily suspend Autocommit mode. Emulates nested transactions, by keeping a transaction stack depth.

Commit
Tells DBIx::SearchBuilder to commit the current SQL transaction. This will turn Autocommit mode back on.

Rollback [FORCE]
Tells DBIx::SearchBuilder to abort the current SQL transaction. This will turn Autocommit mode back on. If this method is passed a true argument, stack depth is blown away and the outermost transaction is rolled back

ForceRollback
Force the handle to rollback. Whether or not we're deep in nested transactions

TransactionDepth
Return the current depth of the faked nested transaction stack.

ApplyLimits STATEMENTREF ROWS_PER_PAGE FIRST_ROW
takes an SQL SELECT statement and massages it to return ROWS_PER_PAGE starting with FIRST_ROW;

Join { Paramhash }
Takes a paramhash of everything Searchbuildler::Record does plus a parameter called 'SearchBuilder' that contains a ref to a SearchBuilder object'. This performs the join.

DistinctQuery STATEMENTREF
takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result set.

DistinctCount STATEMENTREF
takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result set.

Log MESSAGE
Takes a single argument, a message to log. Currently prints that message to STDERR

DESTROY
When we get rid of the Searchbuilder::Handle, we need to disconnect from the database Jesse Vincent, jesse@fsck.com perl(1), DBIx::SearchBuilder