NAME
DBIx::Class::Storage::DBI - DBI storage handler
SYNOPSIS
DESCRIPTION
This class represents the connection to the database
METHODS
new
throw_exception
Throws an exception - croaks.
connect_info
The arguments of connect_info
are always a single array reference.
This is normally accessed via "connection" in DBIx::Class::Schema, which encapsulates its argument list in an arrayref before calling connect_info
here.
The arrayref can either contain the same set of arguments one would normally pass to "connect" in DBI, or a lone code reference which returns a connected database handle.
In either case, there is an optional final element within the arrayref which can hold a hashref of connection-specific Storage::DBI options. These include on_connect_do
, and the sql_maker options limit_dialect
, quote_char
, and name_sep
. Examples:
->connect_info([ 'dbi:SQLite:./foo.db' ]);
->connect_info([ sub { DBI->connect(...) } ]);
->connect_info(
[
'dbi:Pg:dbname=foo',
'postgres',
'my_pg_password',
{ AutoCommit => 0 },
{ quote_char => q{`}, name_sep => q{@} },
]
);
->connect_info(
[
sub { DBI->connect(...) },
{ quote_char => q{`}, name_sep => q{@} },
]
);
on_connect_do
$schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
Call this after $schema->connect
to have the sql statements given executed on every db connect.
This option can also be set via "connect_info".
debug
Causes SQL trace information to be emitted on the debugobj
object. (or STDERR
if debugobj
has not specifically been set).
debugfh
Set or retrieve the filehandle used for trace/debug output. This should be an IO::Handle compatible ojbect (only the print
method is used. Initially set to be STDERR - although see information on the DBIX_CLASS_STORAGE_DBI_DEBUG environment variable.
debugobj
Sets or retrieves the object used for metric collection. Defaults to an instance of DBIx::Class::Storage::Statistics that is campatible with the original method of using a coderef as a callback. See the aforementioned Statistics class for more information.
debugcb
Sets a callback to be executed each time a statement is run; takes a sub reference. Callback is executed as $sub->($op, $info) where $op is SELECT/INSERT/UPDATE/DELETE and $info is what would normally be printed.
See debugobj for a better way.
disconnect
Disconnect the DBI handle, performing a rollback first if the database is not in AutoCommit
mode.
connected
Check if the DBI handle is connected. Returns true if the handle is connected.
ensure_connected
Check whether the database handle is connected - if not then make a connection.
dbh
Returns the dbh - a data base handle of class DBI.
sql_maker
Returns a sql_maker
object - normally an object of class DBIC::SQL::Abstract
.
txn_begin
Calls begin_work on the current dbh.
See DBIx::Class::Schema for the txn_do() method, which allows for an entire code block to be executed transactionally.
txn_commit
Issues a commit against the current dbh.
txn_rollback
Issues a rollback against the current dbh. A nested rollback will throw a DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION exception, which allows the rollback to propagate to the outermost transaction.
select
Handle a SQL select statement.
select_single
Performs a select, fetch and return of data - handles a single row only.
sth
Returns a DBI sth (statement handle) for the supplied SQL.
columns_info_for
Returns database type info for a given table columns.
last_insert_id
Return the row id of the last insert.
sqlt_type
Returns the database driver name.
create_ddl_dir (EXPERIMENTAL)
Creates an SQL file based on the Schema, for each of the specified database types, in the given directory.
Note that this feature is currently EXPERIMENTAL and may not work correctly across all databases, or fully handle complex relationships.
deployment_statements
Create the statements for "deploy" and "deploy" in DBIx::Class::Schema.
deploy
Sends the appropriate statements to create or modify tables to the db. This would normally be called through "deploy" in DBIx::Class::Schema.
datetime_parser
Returns the datetime parser class
datetime_parser_type
Defines (returns) the datetime parser class - currently hardwired to DateTime::Format::MySQL
build_datetime_parser
SQL METHODS
The module defines a set of methods within the DBIC::SQL::Abstract namespace. These build on SQL::Abstract::Limit to provide the SQL query functions.
The following methods are extended:-
- delete
- insert
- select
- update
- limit_dialect
-
Accessor for setting limit dialect. This is useful for JDBC-bridge among others where the remote SQL-dialect cannot be determined by the name of the driver alone.
This option can also be set via "connect_info".
- quote_char
-
Specifies what characters to use to quote table and column names. If you use this you will want to specify name_sep as well.
quote_char expectes either a single character, in which case is it is placed on either side of the table/column, or an arrayref of length 2 in which case the table/column name is placed between the elements.
For example under MySQL you'd use
quote_char('`')
, and user SQL Server you'd usequote_char(qw/[ ]/)
.This option can also be set via "connect_info".
- name_sep
-
This only needs to be used in conjunction with quote_char, and is used to specify the charecter that seperates elements (schemas, tables, columns) from each other. In most cases this is simply a
.
.This option can also be set via "connect_info".
ENVIRONMENT VARIABLES
DBIX_CLASS_STORAGE_DBI_DEBUG
If DBIX_CLASS_STORAGE_DBI_DEBUG
is set then SQL trace information is produced (as when the debug method is set).
If the value is of the form 1=/path/name
then the trace output is written to the file /path/name
.
This environment variable is checked when the storage object is first created (when you call connect on your schema). So, run-time changes to this environment variable will not take effect unless you also re-connect on your schema.
AUTHORS
Matt S. Trout <mst@shadowcatsystems.co.uk>
Andy Grundman <andy@hybridized.org>
LICENSE
You may distribute this code under the same terms as Perl itself.