DBIx::Class::Storage::DBI - DBI storage handler
This class represents the connection to the database
Throws an exception - croaks.
The arguments of connect_info are always a single array reference.
connect_info
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:
on_connect_do
limit_dialect
quote_char
name_sep
->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{@} }, ] );
$schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
Call this after $schema->connect to have the sql statements given executed on every db connect.
$schema->connect
This option can also be set via "connect_info".
Causes SQL trace information to be emitted on the debugobj object. (or STDERR if debugobj has not specifically been set).
debugobj
STDERR
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.
print
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.
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 the DBI handle, performing a rollback first if the database is not in AutoCommit mode.
AutoCommit
Check if the DBI handle is connected. Returns true if the handle is connected.
Check whether the database handle is connected - if not then make a connection.
Returns the dbh - a data base handle of class DBI.
Returns a sql_maker object - normally an object of class DBIC::SQL::Abstract.
sql_maker
DBIC::SQL::Abstract
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.
Issues a commit against the current dbh.
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.
Handle a SQL select statement.
Performs a select, fetch and return of data - handles a single row only.
Returns a DBI sth (statement handle) for the supplied SQL.
Returns database type info for a given table columns.
Return the row id of the last insert.
Returns the database driver name.
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.
Create the statements for "deploy" and "deploy" in DBIx::Class::Schema.
Sends the appropriate statements to create or modify tables to the db. This would normally be called through "deploy" in DBIx::Class::Schema.
Returns the datetime parser class
Defines (returns) the datetime parser class - currently hardwired to DateTime::Format::MySQL
See "datetime_parser"
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:-
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.
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 use quote_char(qw/[ ]/).
quote_char('`')
quote_char(qw/[ ]/)
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 ..
.
If DBIX_CLASS_STORAGE_DBI_DEBUG is set then SQL trace information is produced (as when the debug method is set).
DBIX_CLASS_STORAGE_DBI_DEBUG
If the value is of the form 1=/path/name then the trace output is written to the file /path/name.
1=/path/name
/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.
Matt S. Trout <mst@shadowcatsystems.co.uk>
Andy Grundman <andy@hybridized.org>
You may distribute this code under the same terms as Perl itself.
To install DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class
CPAN shell
perl -MCPAN -e shell install DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.