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, if the final argument in your connect_info happens to be a hashref, connect_info will look there for several connection-specific options:
This can be set to an arrayref of literal sql statements, which will be executed immediately after making the connection to the database every time we [re-]connect.
Sets the 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 expects 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 ..
.
These options can be mixed in with your other DBI connection attributes, or placed in a seperate hashref after all other normal DBI connection arguments.
Every time connect_info is invoked, any previous settings for these options will be cleared before setting the new ones, regardless of whether any options are specified in the new connect_info.
Examples:
# Simple SQLite connection ->connect_info([ 'dbi:SQLite:./foo.db' ]); # Connect via subref ->connect_info([ sub { DBI->connect(...) } ]); # A bit more complicated ->connect_info( [ 'dbi:Pg:dbname=foo', 'postgres', 'my_pg_password', { AutoCommit => 0 }, { quote_char => q{"}, name_sep => q{.} }, ] ); # Equivalent to the previous example ->connect_info( [ 'dbi:Pg:dbname=foo', 'postgres', 'my_pg_password', { AutoCommit => 0, quote_char => q{"}, name_sep => q{.} }, ] ); # Subref + DBIC-specific connection options ->connect_info( [ sub { DBI->connect(...) }, { quote_char => q{`}, name_sep => q{@}, on_connect_do => ['SET search_path TO myschema,otherschema,public'], }, ] );
This method is deprecated in favor of setting 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
This is the equivalent to setting "DBIC_TRACE" in your shell environment.
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 DBIC_TRACE 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 column.
Return the row id of the last insert.
Returns the database driver name.
Creates a 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.
Returns the statements used by "deploy" and "deploy" in DBIx::Class::Schema. The database driver name is given by $type, though the value from "sqlt_type" is used if it is not specified.
$type
$directory is used to return statements from files in a previously created "create_ddl_dir" directory and is optional. The filenames are constructed from "ddl_filename" in DBIx::Class::Schema, the schema name and the $version.
$directory
$version
If no $directory is specified then the statements are constructed on the fly using SQL::Translator and $version is ignored.
See "METHODS" in SQL::Translator for a list of values for $sqlt_args.
$sqlt_args
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:-
See "connect_info" for details. For setting, this method is deprecated in favor of "connect_info".
If DBIC_TRACE is set then SQL trace information is produced (as when the debug method is set).
DBIC_TRACE
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.
Old name for DBIC_TRACE
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.