text: # $Id: DBI.pm 10994 2008-03-24 14:06:48Z timbo $ # vim: ts=8:sw=4 # # Copyright (c) 1994-2007 Tim Bunce Ireland # # See COPYRIGHT section in pod text below for usage and distribution rights. # require 5.006_00; BEGIN { $DBI::$fh") || return undef; $fh = \*FH; } while(defined($self->blob_read($field, $len, $blocksize, \$buf))) { print $fh $buf; $len += length $buf; } close(FH); $len; } sub more_results { shift->{syb_more_results}; # handy grandfathering } } unless ($DBI::PurePerl) { # See install_driver { @DBD::_mem::dr::ISA = qw(DBD::_mem::common); } { @DBD::_mem::db::ISA = qw(DBD::_mem::common); } { @DBD::_mem::st::ISA = qw(DBD::_mem::common); } # DBD::_mem::common::DESTROY is implemented in DBI.xs } 1; __END__ =head1 I<driver> modules. It is the driver modules which do most of the real work. The DBI provides a standard interface and framework for the drivers to operate within. =head2. =head2. =head2 Outline Usage To use DBI, first you need to load the DBI module: use DBI; use strict; (The C<use strict;> isn't required but is strongly recommended.) Then you need to L</connect> to your data source and get a I<handle> for that connection: $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 }); Since connecting can be expensive, you generally just connect at the start of your program and disconnect at the end. Explicitly defining the required C C<$sth> in our examples. The typical method call sequence for a I<non>-C<SELECT> statement is: prepare, execute, execute, execute. for example: $sth = $dbh->prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)"); while(<CSV>) { chomp; my ($foo,$bar,$baz) = split /,/; $sth->execute( $foo, $bar, $baz ); } The C<do()> method can be used for non repeated I<non>-C<SELECT> statement (or with drivers that don't support placeholders): $rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1"); To commit your changes to the database (when L</AutoCommit> is off): $dbh->commit; # or call $dbh->rollback; to undo changes Finally, when you have finished working with the data source, you should L</disconnect> from it: $dbh->disconnect; =head2 General Interface Rules & Caveats The DBI does not have a concept of a "current session". Every session has a handle object (i.e., a C<$dbh>) returned from the C<connect> method. That handle object is used to invoke database related methods. Most data is returned to the Perl script as strings. (Null values are returned as (C< C<CursorName> attribute for an alternative. Individual driver implementors are free to provide any private functions and/or handle attributes that they feel are useful. Private driver functions can be invoked using the DBI C<func()> method. Private driver attributes are accessed just like standard attributes. Many methods have an optional C<\%attr> parameter which can be used to pass information to the driver implementing the method. Except where specifically documented, the C<\%attr> parameter can only be used to pass driver specific hints. In general, you can ignore C<\%attr> parameters or pass it as C<undef>. =head2 Naming Conventions and Name Space The DBI package and all packages below it (C<DBI::*>) are reserved for use by the DBI. Extensions and related modules use the C<DBIx::> namespace (see L<>). Package names beginning with C<DBD::> are reserved for use by DBI database drivers. All environment variables used by the DBI or by individual DBDs begin with "C<DBI_>" or ., "C<ora_>" for Oracle, "C<ing_>" for Ingres, etc). =head2 SQL - A Query Language Most DBI drivers require applications to use a dialect of SQL (Structured Query Language) to interact with the database engine. The L</prepare> or L</do> methods. For an interesting diversion on the I<real> history of RDBMS and SQL, from the people who made it happen, see: Follow the "Full Contents" then "Intergalactic dataspeak" links for the SQL history. =head2 Placeholders and Bind Values Some drivers support placeholders and bind values. I C<?> characters are the placeholders. The association of actual values with placeholders is known as I<binding>, and the values are referred to as I<bind values>. Note that the C<?> is not enclosed in quotation marks, even when the placeholder represents a string. Some drivers also allow placeholders like C<:>I<name> and C<:>I<n> (e.g., C<:1>, C<:2>, and so on) in addition to C<LIKE> qualifier, you must remember that the placeholder substitutes for the whole string. So you should use "C<... LIKE ? ...>" and include any wildcard characters in the value that you bind to the placeholder. B<NULL Values> Undefined values, or C<undef>, are used to indicate NULL values. You can insert and update columns with a NULL value as you would a non-NULL value. These examples insert and update the column C C<WHERE> clause. Consider: SELECT fullname FROM people WHERE age = ? Binding an C<undef> (NULL) to the placeholder will I<not> select rows which have a NULL C<age>! At least for database engines that conform to the SQL standard. Refer to the SQL manual for your database engine or any SQL book for the reasons for this. To explicitly select NULLs you have to say "C<WHERE age IS NULL>". A common issue is to have a code fragment handle a value that could be either C<defined> or C<WHERE> clause with several columns, whose associated values (C<defined> or C<WHERE> clause that supports both NULL and non-NULL comparisons. Its SQL statement would need to be prepared only once for all cases, thus improving performance. Several examples of C<WHERE> clauses that support this are presented below. But each example lacks portability, robustness, or simplicity. Whether an example is supported on your database engine depends on what SQL extensions it provides, and where it supports the C<WHERE> clauses require execute statements as follows. The arguments are required, whether their values are C<defined> or * Works only because Example 0 works. DBI provides a sample perl script that will test the examples above on your database engine and tell you which ones work. It is located in the F<ex/> subdirectory of the DBI source distribution, or here: L<> Please use the script to help us fill-in and maintain this table. B L</execute> and L</bind_param> for more details.. See also the L</bind_columns> method, which is used to associate Perl variables with the output columns of a C<SELECT> statement. =head1 THE DBI PACKAGE AND CLASS In this section, we cover the DBI class methods, utility functions, and the dynamic attributes associated with generic DBI handles. =head2 DBI Constants Constants representing the values of the SQL standard types can be imported individually by name, or all together by importing the special C<:sql_types> tag. The names and values of all the defined SQL standard types can be produced like this: foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) { printf "%s=%d\n", $_, &{"DBI::$_"}; } These constants are defined by SQL/CLI, ODBC or both. C<SQL_BIGINT> is (currently) omitted, because SQL/CLI and ODBC provide conflicting codes. See the L</type_info>, L</type_info_all>, and L</bind_param> methods for possible uses. Note that just because the DBI defines a named constant for a given data type doesn't mean that drivers will support that data type. =head2 DBI Class Methods The following methods are provided by the DBI class: =head3 C. =head3 C<connect> $dbh = DBI->connect($data_source, $username, $password) or die $DBI::errstr; $dbh = DBI->connect($data_source, $username, $password, \%attr) or die $DBI::errstr; Establishes a database connection, or session, to the requested C<$data_source>. Returns a database handle object if the connection succeeds. Use C<$dbh-E<gt>disconnect> to terminate the connection. If the connect fails (see below), it returns C<undef> and sets both C<$DBI::err> and C<$DBI::errstr>. (It does I<not> explicitly set C<$!>.) You should generally test the return status of C<connect> and C<print $DBI::errstr> if it has failed. Multiple simultaneous connections to multiple databases through multiple drivers can be made via the DBI. Simply make one C<connect> call for each database and keep a copy of each returned database handle. The C<$data_source> value must begin with "C<dbi:>I<driver_name>C<:>". The I<driver_name> specifies the driver that will be used to make the connection. (Letter case is significant.) As a convenience, if the C<$data_source> parameter is undefined or empty, the DBI will substitute the value of the environment variable C<DBI_DSN>. If just the I<driver_name> part is empty (i.e., the C<$data_source> prefix is "C<dbi::>"), the environment variable C<DBI_DRIVER> is used. If neither variable is set, then C<connect> dies. Examples of C<$data_source> values are: dbi:DriverName:database_name dbi:DriverName:database_name@hostname:port dbi:DriverName:database=database_name;host=hostname;port=port There is I that they support the three common names 'C<host>', 'C<port>', and 'C<database>' (plus 'C<db>' as an alias for C<database>). This simplifies automatic construction of basic DSNs: C< C<DBI_AUTOPROXY> is defined (and the driver in C<$data_source> is not "C<Proxy>") then the connect request will automatically be changed to: $ENV{DBI_AUTOPROXY};dsn=$data_source C<DBI_AUTOPROXY> is typically set as "C<dbi:Proxy:hostname=...;port=...>". If $ENV{DBI_AUTOPROXY} doesn't begin with 'C<dbi:>' then "dbi:Proxy:" will be prepended to it first. See the DBD::Proxy documentation for more details. If C<$username> or C<$password> are undefined (rather than just empty), then the DBI will substitute the values of the C<DBI_USER> and. C<DBI-E<gt>connect> automatically installs the driver if it has not been installed yet. Driver installation either returns a valid driver handle, or it I<dies> with an error message that includes the string "C<install_driver>" and the underlying problem. So C<DBI-E<gt>connect> will die on a driver installation failure and will only return C<undef> on a connect failure, in which case C<$DBI::errstr> will hold the error message. Use C<eval { ... }> if you need to catch the "C<install_driver>" error. The C<$data_source> argument (with the "C<dbi:...:>" prefix removed) and the C<$username> and C<$password> arguments are then passed to the driver for processing. The DBI does not define any interpretation for the contents of these fields. The driver is free to interpret the C<$data_source>, C<$username>, and C<$password> fields in any way, and supply whatever defaults are appropriate for the engine being accessed. (Oracle, for example, uses the ORACLE_SID and TWO_TASK environment variables if no C<$data_source> is specified.) The C<AutoCommit> and C<PrintError> attributes for each connection default to "on". (See L</AutoCommit> and L</PrintError> for more information.) However, it is strongly recommended that you explicitly define C<AutoCommit> rather than rely on the default. The C<PrintWarn> attribute defaults to on if $^W is true, i.e., perl is running with warnings enabled. The C<\%attr> parameter can be used to alter the default settings of C<PrintError>, C<RaiseError>, C<AutoCommit>, and other attributes. For example: $dbh = DBI->connect($data_source, $user, $pass, { PrintError => 0, AutoCommit => 0 }); The username and password can also be specified using the attributes C<Username> and C<Password>, in which case they take precedence over the C<$username> and C<$password> parameters. You can also define connection attribute values within the C<$data_source> parameter. For example: dbi:DriverName(PrintWarn=>1,PrintError=>0,Taint=>1):... Individual attributes values specified in this way take precedence over any conflicting values specified via the C<\%attr> parameter to C<connect>. The (C< C<connect> (instead of C<\%attr>): $dbh = DBI->connect($data_source, $user, $pass, $driver); In this "old-style" form of C<connect>, the C<$data_source> should not start with "C<dbi:driver_name:>". (If it does, the embedded driver_name will be ignored). Also note that in this older form of C<connect>, the C<$dbh-E<gt>{AutoCommit}> attribute is I<undefined>, the C<$dbh-E<gt>{PrintError}> attribute is off, and the old C<DBI_DBNAME> environment variable is checked if C<DBI_DSN> is not defined. Beware that this "old-style" C<connect> will soon be withdrawn in a future version of DBI. =head3 C<connect_cached> $dbh = DBI->connect_cached($data_source, $username, $password) or die $DBI::errstr; $dbh = DBI->connect_cached($data_source, $username, $password, \%attr) or die $DBI::errstr; C<connect_cached> is like L</connect>, except that the database handle returned is also stored in a hash associated with the given parameters. If another call is made to C<connect_cached> with the same parameter values, then the corresponding cached C<$dbh> will be returned if it is still valid. The cached database handle is replaced with a new connection if it has been disconnected or if the C<ping> method fails. That the behaviour of this method differs in several respects from the behaviour of persistent connections implemented by Apache::DBI. However, if Apache::DBI is loaded then C C<private_foo_cachekey> here as an example, you can use any attribute name with a conections for separate parts of the code, the database handles are isolated from any attribute changes made to other handles. The cache can be accessed (and cleared) via the L</CachedKids> attribute: my $CachedKids_hashref = $dbh->{Driver}->{CachedKids}; %$CachedKids_hashref = () if $CachedKids_hashref; =head3 C<available_drivers> @ary = DBI->available_drivers; @ary = DBI->available_drivers($quiet); Returns a list of all available drivers by searching for C<DBD::*> modules through the directories in C<@INC>. By default, a warning is given if some drivers are hidden by others of the same name in earlier directories. Passing a true value for C<$quiet> will inhibit the warning. =head3 C<installed_drivers>  L</available_drivers>. Added in DBI 1.49. =head3 C L C<DBI> version, C<OS> name, etc. When called in a void context the installed_versions() method will print out a formatted list of the hash contents, one per line.. =head3 C<data_sources> @ary = DBI->data_sources($driver); @ary = DBI->data_sources($driver, \%attr); Returns a list of data sources (databases) available via the named driver. If C<$driver> is empty or C<undef>, then the value of the C<DBI_DRIVER> environment variable is used. The driver will be loaded if it hasn't been already. Note that if the driver loading fails then data_sources() I<dies> with an error message that includes the string "C<install_driver>" and the underlying problem. Data sources are returned in a form suitable for passing to the L</connect> method (that is, they will include the "C<dbi:$driver:>" prefix). Note that many drivers have no way of knowing what data sources might be available for it. These drivers return an empty or incomplete list or may require driver-specific attributes. There is also a data_sources() method defined for database handles. =head3 C<trace> DBI->trace($trace_setting) DBI->trace($trace_setting, $trace_filename) DBI->trace($trace_setting, $trace_filehandle) $trace_setting = DBI->trace; The C<DBI-E<gt>trace> method sets the I<global default> trace settings and returns the I<previous> trace settings. It can also be used to change where the trace output is sent. There's a similar method, C<$h-E<gt>trace>, which sets the trace settings for the specific handle it's called on. See the L</TRACING> section for full details about the DBI's powerful tracing facilities. =head2 DBI Utility Functions In addition to the DBI methods listed in the previous section, the DBI package also provides several utility functions. These can be imported into your code by listing them in the C<use> statement. For example: use DBI qw(neat data_diff); Alternatively, all these utility functions (except hash) can be imported using the C<:utils> import tag. For example: use DBI qw(:utils); =head3 C C<UTF8> on/off refers to Perl's internal SvUTF8 flag. If $string has the SvUTF8 flag set but the sequence of bytes it contains are not a valid UTF-8 encoding then data_string_desc() will report C<UTF8 on but INVALID encoding>. The C<ASCII> vs C<non-ASCII> portion shows C<ASCII> if I<all> the characters in the string are ASCII (have code points <= 127). The data_string_desc() function was added in DBI 1.46. =head3 C C<\x{XXXX}> format. Unicode code points in the range U+0800 to U+08FF are unassigned and most likely to occur due to double-encoding. Characters in this range are reported as C<\x{08XX}='C'> where C<C> is the corresponding latin-1 character. The data_string_diff() function only considers logical I<characters> and not the underlying encoding. See L</data_diff> for an alternative. The data_string_diff() function was added in DBI 1.46. =head3 C<data_diff> $diff = data_diff($a, $b); $diff = data_diff($a, $b, $logical); Returns an informal description of the difference between two strings. It calls L</data_string_desc> and L</data_string_diff> and returns the combined results as a multi-line string. For example, C I<and> their physical encoding then data_diff() returns an empty string. If $logical is true then physical encoding differences are ignored (but are still reported if there is a difference in the characters). The data_diff() function was added in DBI 1.46. =head3 C<neat> $str = neat($value); $str = neat($value, $maxlen); Return a string containing a neat (and tidy) representation of the supplied value. Strings will be quoted, although internal quotes will I<not> be escaped. Values known to be numeric will be unquoted. Undefined (NULL) values will be shown as C<undef> (without quotes). If the string is flagged internally as utf8 then double quotes will be used, otherwise single quotes are used and unprintable characters will be replaced by dot (.). For result strings longer than C<$maxlen> the result string will be truncated to C<$maxlen-4> and "C<...'>" will be appended. If C<$maxlen> is 0 or C<undef>, it defaults to C<$DBI::neat_maxlen> which, in turn, defaults to 400. This function is designed to format values for human consumption. It is used internally by the DBI for L</trace> output. It should typically I<not> be used for formatting values for database use. (See also L</quote>.) =head3 C<neat_list> $str = neat_list(\@listref, $maxlen, $field_sep); Calls C<neat> on each element of the list and returns a string containing the results joined with C<$field_sep>. C<$field_sep> defaults to C<", ">. =head3 C<looks_like_number> @bool = looks_like_number(@array); Returns true for each element that looks like a number. Returns false for each element that does not look like a number. Returns C<undef> for each element that is undefined or empty. =head3 C L<> for more information. Both types are implemented in C and are very fast. This function doesn't have much to do with databases, except that it can be handy to store hash values in a database. =head2 DBI Dynamic Attributes Dynamic attributes are always associated with the I<last handle used> (that handle is represented by I<immediately> after calling the method that "sets" them. If in any doubt, use the corresponding method call. =head3 C<$DBI::err> Equivalent to C<$h-E<gt>err>. =head3 C<$DBI::errstr> Equivalent to C<$h-E<gt>errstr>. =head3 C<$DBI::state> Equivalent to C<$h-E<gt>state>. =head3 C<$DBI::rows> Equivalent to C<$h-E<gt>rows>. Please refer to the documentation for the L</rows> method. =head3 C<$DBI::lasth> Returns the DBI object handle used for the most recent DBI method call. If the last DBI method call was a DESTROY then $DBI::lasth will return the handle of the parent of the destroyed handle, if there is one. =head1 METHODS COMMON TO ALL HANDLES The following methods can be used by all types of DBI handles. =head3 C<err> $rv = $h->err; Returns the I I<and> have your program be portable to different database engines, then you'll need to determine what the corresponding error codes are for all those engines and test for all of them. The DBI uses the value of $DBI::stderr as the C<err> value for internal errors. Drivers should also do likewise. The default value for $DBI::stderr is 2000000000. A driver may return C L</set_err> for more information. =head3 C<errstr> $str = $h->errstr; Returns the native database engine error message from the last DBI method called. This has the same lifespan issues as the L</set_err> for more information. =head3 C<state> $str = $h->state; Returns a state code in the standard SQLSTATE five character format. Note that the specific success code C<00000> is translated to any empty string (false). If the driver does not support SQLSTATE (and most don't), then state() will return C<S1000> (General Error) for all errors. The driver is free to return any value via C<state>, e.g., warning codes, even if it has not declared an error by returning a true value via the L</err> method described above. The state() method should not be used to test for errors, use err() for that, because drivers may return a 'success with information' or warning state code via state() for methods that have not 'failed'. =head3 C<set_err> $rv = $h->set_err($err, $errstr); $rv = $h->set_err($err, $errstr, $state); $rv = $h->set_err($err, $errstr, $state, $method); $rv = $h->set_err($err, $errstr, $state, $method, $rv); Set the C<err>, C<errstr>, and C<state> values for the handle. This method is typically only used by DBI drivers and DBI subclasses. If the L</HandleSetErr> attribute holds a reference to a subroutine it is called first. The subroutine can alter the $err, $errstr, $state, and $method values. See L</HandleSetErr> for full details. If the subroutine returns a true value then the handle C<err>, C<errstr>, and C<state> values are not altered and set_err() returns an empty list (it normally returns $rv which defaults to undef, see below). Setting C<err> to a I<true> value indicates an error and will trigger the normal DBI error handling mechanisms, such as C<RaiseError> and C<HandleError>, if they are enabled, when execution returns from the DBI back to the application. Setting C<err> to C<""> indicates an 'information' state, and setting it to C<"0"> indicates a 'warning' state. Setting C<err> to C<undef> also sets C<errstr> to undef, and C<state> to C<"">, irrespective of the values of the $errstr and $state parameters. The $method parameter provides an alternate method name for the C<RaiseError>/C<PrintError>/C<PrintWarn> error string instead of the fairly unhelpful 'C<set_err>'. The C<set_err> method normally returns undef. The $rv parameter provides an alternate return value. Some special rules apply if the C<err> or C<errstr> values for the handle are I<already> set... If C<errstr> is true then: "C< [err was %s now %s]>" is appended if $err is true and C<err> is already true and the new err value differs from the original one. Similarly "C< [state was %s now %s]>" is appended if $state is true and C<state> is already true and the new state value differs from the original one. Finally "C<\n>" and the new $errstr are appended if $errstr differs from the existing errstr value. Obviously the C<%s>'s above are replaced by the corresponding values. The handle C<err> value is set to $err if: $err is true; or handle C<err> value is undef; or $err is defined and the length is greater than the handle C<err> length. The effect is that an 'information' state only overrides undef; a 'warning' overrides undef or 'information', and an 'error' state overrides anything. The handle C<state> value is set to $state if $state is true and the handle C<err> value was set (by the rules above). Support for warning and information states was added in DBI 1.41. =head3 C, C<DBI-E<gt>trace>, which sets the global default trace settings. See the L</TRACING> section for full details about the DBI's powerful tracing facilities. =head3 C<trace_msg> $h->trace_msg($message_text); $h->trace_msg($message_text, $min_level); Writes C<$message_text> to the trace file if the trace level is greater than or equal to $min_level (which defaults to 1). Can also be called as C<DBI-E<gt>trace_msg($msg)>. See L</TRACING> for more details. =head3 C<func> $h->func(@func_arguments, $func_name) or die ...; The C<func> method can be used to call private non-standard and non-portable methods implemented by the driver. Note that the function name is given as the I L<DBI::DBD> for how you can avoid needing to use func() and gain direct access to driver-private methods. =head3 C. =head3 C ("C<|>") or comma ("C<,>") characters. For example: C<"SQL|3|foo">. It uses the parse_trace_flag() method, described below, to process the individual trage flag names. The parse_trace_flags() method was added in DBI 1.42. =head3 C. =head3 C<private_attribute_info> $hash_ref = $h->private_attribute_info(); Returns a reference to a hash whose keys are the names of driver-private. =head3 C I<inner> hash that actually holds the contents. The swap_inner_handle() method swaps the inner hashes between two handles. The $h1 and $h2 handles still point to the same tied hashes, but what those hashes are tied to has been swapped. In effect $h1 I) =head1 =head3 C<Warn> (boolean, inherited) The C<Warn> attribute enables useful warnings for certain bad practices. It is enabled by default and should only be disabled in rare circumstances. Since warnings are generated using the Perl C<warn> function, they can be intercepted using the Perl C<$SIG{__WARN__}> hook. The C<Warn> attribute is not related to the C<PrintWarn> attribute. =head3 C<Active> (boolean, read-only) The C<Active> attribute is true if the handle object is "active". This is rarely used in applications. The exact meaning of active is somewhat vague at the moment. For a database handle it typically means that the handle is connected to a database (C<$dbh-E<gt>disconnect> sets C<Active> off). For a statement handle it typically means that the handle is a C<SELECT> that may have more data to fetch. (Fetching all the data or calling C<$sth-E<gt>finish> sets C<Active> off.) =head3 C<Executed> (boolean) The C<Executed> attribute is true if the handle object has been "executed". Currently only the $dbh do() method and the $sth execute(), execute_array(), and execute_for_fetch() methods set the C<Executed> attribute. When it's set on a handle it is also set on the parent handle at the same time. So calling execute() on a $sth also sets the C<Executed> attribute on the parent $dbh. The C<Executed> attribute for a database handle is cleared by the commit() and rollback() methods (even if they fail). The C<Executed> attribute of a statement handle is not cleared by the DBI under any circumstances and so acts as a permanent record of whether the statement handle was ever used. The C<Executed> attribute was added in DBI 1.41. =head3 C<Kids> (integer, read-only) For a driver handle, C<Kids> is the number of currently existing database handles that were created from that driver handle. For a database handle, C<Kids> is the number of currently existing statement handles that were created from that database handle. For a statement handle, the value is zero. =head3 C<ActiveKids> (integer, read-only) Like C<Kids>, but only counting those that are C<Active> (as above). =head3 C<CachedKids> (hash ref) For a database handle, C<CachedKids> returns a reference to the cache (hash) of statement handles created by the L</prepare_cached> method. For a driver handle, returns a reference to the cache (hash) of database handles created by the L</connect_cached> method. =head3 C<Type> (scalar, read-only) The C<Type> attribute identifies the type of a DBI handle. Returns "dr" for driver handles, "db" for database handles and "st" for statement handles. =head3 C<ChildHandles> (array ref) The ChildHandles attribute contains a reference to an array of all the handles created by this handle which are still accessible. The contents of the array are weak-refs and will become undef when the handle goes out of scope. C<ChildHandles> returns undef if your perl version does not support weak references (check the L<Scalar::Util); =head3 C<CompatMode> (boolean, inherited) The. =head3 C I<database engine> related effects of DESTROYing a handle will be skipped. Think of the name as meaning 'treat the handle as not-Active in the DESTROY method'. For a database handle, this attribute does not disable an I<explicit> call to the disconnect method, only the implicit call from DESTROY that happens if the handle is still marked as C<Active>. This attribute is specifically designed for use in Unix applications that "fork" child processes. Either the parent or the child process, but not both, should set C<InactiveDestroy> true I<every> method call if the DBI trace level (not handle trace level) is set high enough to show the trace from the DBI's method dispatcher, e.g. >= 9. =head3 C<PrintWarn> (boolean, inherited) The C<PrintWarn> attribute controls the printing of warnings recorded by the driver. When set to a true value the DBI will check method calls to see if a warning condition has been set. If so, the DBI will effectively do a C<warn("$class $method warning: $DBI::errstr")> where C<$class> is the driver class and C<$method> is the name of the method which failed. E.g., DBD::Oracle::db execute warning: ... warning text here ... By default, C<DBI-E<gt>connect> sets C<PrintWarn> "on" if $^W is true, i.e., perl is running with warnings enabled. If desired, the warnings can be caught and processed using a C<$SIG{__WARN__}> handler or modules like CGI::Carp and CGI::ErrorWrap. See also L</set_err> for how warnings are recorded and L</HandleSetErr> for how to influence it. Fetching the full details of warnings can require an extra round-trip to the database server for some drivers. In which case the driver may opt to only fetch the full details of warnings if the C<PrintWarn> attribute is true. If C<PrintWarn> is false then these drivers should still indicate the fact that there were warnings by setting the warning string to, for example: "3 warnings". =head3 C<PrintError> (boolean, inherited) The C<PrintError> attribute can be used to force errors to generate warnings (using C<warn>) in addition to returning error codes in the normal way. When set "on", any method which results in an error occuring will cause the DBI to effectively do a C<warn("$class $method failed: $DBI::errstr")> where C<$class> is the driver class and C<$method> is the name of the method which failed. E.g., DBD::Oracle::db prepare failed: ... error text here ... By default, C<DBI-E<gt>connect> sets C<PrintError> "on". If desired, the warnings can be caught and processed using a C<$SIG{__WARN__}> handler or modules like CGI::Carp and CGI::ErrorWrap. =head3 C<RaiseError> (boolean, inherited) The C<RaiseError> attribute can be used to force errors to raise exceptions rather than simply return error codes in the normal way. It is "off" by default. When set "on", any method which results in an error will cause the DBI to effectively do a C<die("$class $method failed: $DBI::errstr")>, where C<$class> is the driver class and C<$method> is the name of the method that failed. E.g., DBD::Oracle::db prepare failed: ... error text here ... If you turn C<RaiseError> on then you'd normally turn C<PrintError> off. If C<PrintError> is also on, then the C<PrintError> is done first (naturally). Typically C<RaiseError> is used in conjunction with C<eval { ... }> to catch the exception that's been thrown and followed by an C<if ($@) { ... }> block to handle the caught exception. L</Transactions>. If you want to temporarily turn C C<PrintError>. =head3 C<HandleError> (code ref, inherited) The C<HandleError> attribute can be used to provide your own alternative behaviour in case of errors. If set to a reference to a subroutine then that subroutine is called when an error is detected (at the same point that C<RaiseError> and C<PrintError> are handled). The subroutine is called with three parameters: the error message string that C<RaiseError> and C<PrintError> would use, the DBI handle being used, and the first value being returned by the method that failed (typically undef). If the subroutine returns a false value then the C<RaiseError> and/or C<PrintError> attributes are checked and acted upon as normal. For example, to C<my> inside a subroutine to store the previous C<HandleError> value is important. See L<perlsub> and L<perlref> for more information about I<closures>. It is possible for C<HandleError> to alter the error message that will be used by C<RaiseError> and C<PrintError> if it returns false. It can do that by altering the value of $_[0]. This example appends a stack trace to all errors and, unlike the previous example using Carp::confess, this will work C<PrintError> as well as C<RaiseError>: $h->{HandleError} = sub { $_[0]=Carp::longmess($_[0]); 0; }; It is also possible for C<HandleError> to hide an error, to a limited degree, by using L< I<good> use for it then please let me know. =head3 C<HandleSetErr> (code ref, inherited) The C<HandleSetErr> attribute can be used to intercept the setting of handle C<err>, C<errstr>, and C<err>, C<errstr>, and C<state> values being set, and the method name. These can be altered by changing the values in the @_ array. The return value affects set_err() behaviour, see L</set_err> for details. It is possible to 'stack' multiple HandleSetErr handlers by using closures. See L</HandleError> for an example. The C<HandleSetErr> and C<HandleError> subroutines differ in subtle but significant ways. HandleError is only invoked at the point where the DBI is about to return to the application with C<err> set true. It's not invoked by the failure of a method that's been called by another DBI method. HandleSetErr, on the other hand, is called whenever set_err() is called with a defined C C<HandleSetErr> attribute was added in DBI 1.41. =head3 C<ErrCount> (unsigned integer) The C<ErrCount> attribute is incremented whenever the set_err() method records an error. It isn't incremented by warnings or information states. It is not reset by the DBI at any time. The C<ErrCount> attribute was added in DBI 1.41. Older drivers may not have been updated to use set_err() to record errors and so this attribute may not be incremented when using them. =head3 C<ShowErrorStatement> (boolean, inherited) The C<ShowErrorStatement> attribute can be used to cause the relevant Statement text to be appended to the error messages generated by the C<RaiseError>, C<PrintError>, and C<PrintWarn> attributes. Only applies to errors on statement handles plus the prepare(), do(), and the various C<select*()> database handle methods. (The exact format of the appended text is subject to change.) If C<$h-E<gt>{ParamValues}> returns a hash reference of parameter (placeholder) values then those are formatted and appended to the end of the Statement text in the error message. =head3 C<TraceLevel> (integer, inherited) The C<TraceLevel> attribute can be used as an alternative to the L</trace> method to set the DBI trace level and trace flags for a specific handle. See L</TRACING> for more details. The C<TraceLevel> attribute is especially useful combined with C<local> to alter the trace settings for just a single block of code. =head3 C<FetchHashKeyName> (string, inherited) The C<FetchHashKeyName> attribute is used to specify whether the fetchrow_hashref() method should perform case conversion on the field names used for the hash keys. For historical reasons it defaults to 'C<NAME>' but it is recommended to set it to 'C<NAME_lc>' (convert to lower case) or 'C<NAME_uc>' (convert to upper case) according to your preference. It can only be set for driver and database handles. For statement handles the value is frozen when prepare() is called. =head3 C<ChopBlanks> (boolean, inherited) The C<undef> as the attribute value. =head3 C<LongReadLen> (unsigned integer, inherited) The C<LongReadLen> attribute may be used to control the maximum length of 'long' type fields (LONG, BLOB, CLOB, MEMO, etc.) which the driver will read from the database automatically when it fetches each row of data. The C<LongReadLen> attribute only relates to fetching and reading long values; it is not involved in inserting or updating them. A value of 0 means not to automatically fetch any long data. Drivers may return undef or an empty string for long fields when C, C<LongReadLen> relates to the underlying data length and not the doubled-up length of the encoded string. Changing the value of C<LongReadLen> for a statement handle after it has been C<prepare>'d will typically have no effect, so it's common to set C<LongReadLen> on the C<$dbh> before calling C L</LongTruncOk> for information on truncation of long types. =head3 C<LongTruncOk> (boolean, inherited) The C<LongTruncOk> attribute may be used to control the effect of fetching a long field value which has been truncated (typically because it's longer than the value of the C<LongReadLen> attribute). By default, C C<LongTruncOk> is false, many drivers will allow you to continue fetching further rows. See also L</LongReadLen>. =head3 C<TaintIn> (boolean, inherited) If the C<TaintIn> attribute is set to a true value I<and> Perl is running in taint mode (e.g., started with the C<-T> option), then all the arguments to most DBI method calls are checked for being C<TaintIn> attribute was added in DBI 1.31. =head3 C<TaintOut> (boolean, inherited) If the C<TaintOut> attribute is set to a true value I<and> Perl is running in taint mode (e.g., started with the C<-T> option), then most data fetched from the database is considered C<TaintOut> attribute was added in DBI 1.31. =head3 C<Taint> (boolean, inherited) The C<Taint> attribute is a shortcut for L</TaintIn> and L</TaintOut> (it is also present for backwards compatibility). Setting this attribute sets both L</TaintIn> and L</TaintOut>, and retrieving it returns a true value if and only if L</TaintIn> and L</TaintOut> are both set to true values. =head3 C<Profile> (inherited) The C<Profile> attribute enables the collection and reporting of method call timing statistics. See the L<DBI::Profile> module documentation for I<much> more detail. The C<Profile> attribute was added in DBI 1.24. =head3 C<ReadOnly> (boolean, inherited) An application can set the (by issuing a statement like "C<set transaction read only>" as needed, for example) then it should. Otherwise the attribute is simply advisory. A driver can set the C<ReadOnly> attribute itself to indicate that the data it is connected to cannot be changed for some reason. Library modules and proxy drivers can use the attribute to influence their behavior. For example, the DBD::Gofer driver considers the C<ReadOnly> attribute when making a decison about whether to retry an operation that failed. The attribute should be set to 1 or 0 (or undef). Other values are reserved. =head3 C<private_your_module_name_*> The DBI provides a way to store extra information in a DBI handle as "private" attributes. The DBI will allow you to store and retrieve any attribute which has a name starting with "C<private_>". It is I<strongly> recommended that you use just I<one> private attribute (e.g., use a hash ref) I<and> give it a long and unambiguous name that includes the module or application name that the attribute relates to (e.g., "C<private_YourFullModuleName_thingy>"). Because of the way the Perl tie mechanism works you cannot reliably use the. =head1 DBI DATABASE HANDLE OBJECTS This section covers the methods and attributes associated with database handles. =head2 Database Handle Methods The following methods are specified for DBI database handles: =head3 C<clone> $new_dbh = $dbh->clone(); $new_dbh = $dbh->clone(\%attr); The C<clone> method was added in DBI 1.33. It is very new and likely to change. =head3 C L</connect> method (that is, they will include the "C<dbi:$driver:>" prefix). The data_sources() method, for a $dbh, was added in DBI 1.38. =head3 C<do> $rows = $dbh->do($statement) or die $dbh->errstr; $rows = $dbh->do($statement, \%attr) or die $dbh->errstr; $rows = $dbh->do($statement, \%attr, @bind_values) or die ... Prepare and execute a single statement. Returns the number of rows affected or C<undef> on error. A return value of C<-1> means the number of rows is not known, not applicable, or not available. This method is typically most useful for I<non>-C<SELECT> statements that either cannot be prepared in advance (due to a limitation of the driver) or do not need to be executed repeatedly. It should not be used for C<SELECT> statements because it does not return a statement handle (so you can't fetch any data). The default C C<@bind_values> with the C<do> method can be useful because it avoids the need to correctly quote any variables in the C<$statement>. But if you'll be executing the statement many times then it's more efficient to C<prepare> it once and call C<execute> many times instead.. =head3 C I<auto_increment> or I C<undef> for each. There are several caveats to be aware of with this method if you want to use it for portable applications: B<*> For some drivers the value may only available immediately after the insert statement has executed (e.g., mysql, Informix). B<*> For some drivers the $catalog, $schema, $table, and $field parameters are required, for others they are ignored (e.g., mysql). B<*> Drivers may return an indeterminate value if no insert has been performed yet. B<*> For some drivers the value may only be available if placeholders have I<not> been used (e.g., Sybase, MS SQL). In this case the value returned would be from the last non-placeholder insert statement. B<*> Some drivers may need driver-specific hints about how to get the value. For example, being told the name of the database 'sequence' object that holds the value. Any such hints are passed as driver-specific attributes in the \%attr parameter. B<*> If the underlying database offers nothing better, then some drivers may attempt to implement this method by executing "C<select max($field) from $table>". Drivers using any approach like this should issue a warning if C<AutoCommit> is true because it is generally unsafe - another process may have modified the table between your insert and the select. For situations where you know it is safe, such as when you have locked the table, you can silence the warning by passing C<Warn> => 0 in \%attr. B<*> If no insert has been performed yet, or the last insert failed, then the value is implementation defined. Given all the caveats above, it's clear that this method must be used with care. The C<last_insert_id> method was added in DBI 1.38. =head3 C<selectrow_array> @row_ary = $dbh->selectrow_array($statement); @row_ary = $dbh->selectrow_array($statement, \%attr); @row_ary = $dbh->selectrow_array($statement, \%attr, @bind_values); This utility method combines L</prepare>, L</execute> and L</fetchrow_array> into a single call. If called in a list context, it returns the first row of data from the statement. The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. If any method fails, and L</RaiseError> is not set, C<selectrow_array> in a scalar context, or just don't do that. =head3 C<selectrow_arrayref> $ary_ref = $dbh->selectrow_arrayref($statement); $ary_ref = $dbh->selectrow_arrayref($statement, \%attr); $ary_ref = $dbh->selectrow_arrayref($statement, \%attr, @bind_values); This utility method combines L</prepare>, L</execute> and L</fetchrow_arrayref> into a single call. It returns the first row of data from the statement. The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. If any method fails, and L</RaiseError> is not set, C<selectrow_array> will return undef. =head3 C<selectrow_hashref> $hash_ref = $dbh->selectrow_hashref($statement); $hash_ref = $dbh->selectrow_hashref($statement, \%attr); $hash_ref = $dbh->selectrow_hashref($statement, \%attr, @bind_values); This utility method combines L</prepare>, L</execute> and L</fetchrow_hashref> into a single call. It returns the first row of data from the statement. The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. If any method fails, and L</RaiseError> is not set, C<selectrow_hashref> will return undef. =head3 C<selectall_arrayref> $ary_ref = $dbh->selectall_arrayref($statement); $ary_ref = $dbh->selectall_arrayref($statement, \%attr); $ary_ref = $dbh->selectall_arrayref($statement, \%attr, @bind_values); This utility method combines L</prepare>, L</execute> and L</fetchall_arrayref> into a single call. It returns a reference to an array containing a reference to an array (or hash, see below) for each row of data fetched. The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. This is recommended if the statement is going to be executed many times. If L</RaiseError> is not set and any method except C<fetchall_arrayref> fails then C<selectall_arrayref> will return C<undef>; if C<fetchall_arrayref> fails then it will return with whatever data has been fetched thus far. You should check C<$sth-E<gt>err> afterwards (or use the C<RaiseError> attribute) to discover if the data is complete or was truncated due to an error. The L</fetchall_arrayref> method called by C<selectall_arrayref> supports a $max_rows parameter. You can specify a value for $max_rows by including a 'C<MaxRows>' attribute in \%attr. In which case finish() is called for you after fetchall_arrayref() returns. The L</fetchall_arrayref> method called by C<selectall_arrayref> also supports a $slice parameter. You can specify a value for $slice by including a 'C<Slice>' or 'C<Columns>' attribute in \%attr. The only difference between the two is that if C<Slice> is not defined and C<Columns> is an array ref, then the array is assumed to contain column index values (which count from 1), rather than perl array index values. In which case the array is copied and each value decremented before passing to C</fetchall_arrayref>. You may often want to fetch an array of rows where each row is stored as a hash. That can be done simple L</fetchall_arrayref> method for more details. =head3 C<selectall_hashref> $hash_ref = $dbh->selectall_hashref($statement, $key_field); $hash_ref = $dbh->selectall_hashref($statement, $key_field, \%attr); $hash_ref = $dbh->selectall_hashref($statement, $key_field, \%attr, @bind_values); This utility method combines L</prepare>, L</execute> and L</fetchall_hashref> into a single call. It returns a reference to a hash containing one entry, at most, for each row, as returned by fetchall_hashref(). The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. This is recommended if the statement is going to be executed many times. The C<fetchrow_hashref> fails, and L</RaiseError> is not set, C<selectall_hashref> will return C<undef>. If C<fetchrow_hashref> fails and L</RaiseError> is not set, then it will return with whatever data it has fetched thus far. $DBI::err should be checked to catch that. See fetchall_hashref() for more details. =head3 C<selectcol_arrayref> $ary_ref = $dbh->selectcol_arrayref($statement); $ary_ref = $dbh->selectcol_arrayref($statement, \%attr); $ary_ref = $dbh->selectcol_arrayref($statement, \%attr, @bind_values); This utility method combines L</prepare>, L</execute>, and fetching one column from all the rows, into a single call. It returns a reference to an array containing the values of the first column from each row. The C<$statement> parameter can be a previously prepared statement handle, in which case the C<prepare> is skipped. This is recommended if the statement is going to be executed many times. If any method except C<fetch> fails, and L</RaiseError> is not set, C<selectcol_arrayref> will return C<undef>. If C<fetch> fails and L</RaiseError> is not set, then it will return with whatever data it has fetched thus far. $DBI::err should be checked to catch that. The C<selectcol_arrayref> method defaults to pushing a single column value (the first) from each row into the result array. However, it can also push another column, or even multiple columns per row, into the result array. This behaviour can be specified via a  'C<MaxRows>' attribute in \%attr. =head3 C L</execute> method. See L</Statement Handle Methods>. Drivers for engines without the concept of preparing a statement will typically just store the statement in the returned handle and process it when C<$sth-E<gt>execute> is called. Such drivers are unlikely to give much useful information about the statement, such as C<$sth-E<gt>{NUM_OF_FIELDS}>, until after C<$sth-E<gt>execute> has been called. Portable applications should take this into account. In general, DBI drivers do not parse the contents of the statement (other than simply counting any L<. =head3 C<prepare_cached> $sth = $dbh->prepare_cached($statement) $sth = $dbh->prepare_cached($statement, \%attr) $sth = $dbh->prepare_cached($statement, \%attr, $if_active) Like L</prepare> except that the statement handle returned will be stored in a hash associated with the C<$dbh>. If another call is made to C<prepare_cached> with the same C<$statement> and C<%attr> parameter values, then the corresponding cached C<$sth> will be returned without contacting the database server. The C<$if_active> parameter lets you adjust the behaviour if an already cached statement handle is still Active. There are several alternatives: =over 4 =item B<0>: A warning will be generated, and finish() will be called on the statement handle before it is returned. This is the default behaviour if $if_active is not passed. =item B<1>: finish() will be called on the statement handle, but the warning is suppressed. =item B<2>: Disables any checking. =item B] =back Here are some examples of); } I, C<$sth2> will not be its own statement handle, but a duplicate of. If you'd like the cache to managed intelligently, you can tie the hashref returned by C<CachedKids> to an appropriate caching module, such as L<Tie::Cache::LRU>: my $cache; tie %$cache, 'Tie::Cache::LRU', 500; $dbh->{CachedKids} = $cache; =head3 C<commit> $rc = $dbh->commit or die $dbh->errstr; Commit (make permanent) the most recent series of database changes if the database supports transactions and AutoCommit is off. If C<AutoCommit> is on, then calling C<commit> will issue a "commit ineffective with AutoCommit" warning. See also L</Transactions> in the L</FURTHER INFORMATION> section below. =head3 C<rollback> $rc = $dbh->rollback or die $dbh->errstr; Rollback (undo) the most recent series of uncommitted database changes if the database supports transactions and AutoCommit is off. If C<AutoCommit> is on, then calling C<rollback> will issue a "rollback ineffective with AutoCommit" warning. See also L</Transactions> in the L</FURTHER INFORMATION> section below. =head3 C<begin_work> $rc = $dbh->begin_work or die $dbh->errstr; Enable transactions (by turning C<AutoCommit> off) until the next call to C<commit> or C<rollback>. After the next C<commit> or C<rollback>, C<AutoCommit> will automatically be turned on again. If C<AutoCommit> is already off when C<begin_work> is called then it does nothing except return an error. If the driver does not support transactions then when C<begin_work> attempts to set C<AutoCommit> off the driver will trigger a fatal error. See also L</Transactions> in the L</FURTHER INFORMATION> section below. =head3 C<disconnect> $rc = $dbh->disconnect or warn $dbh->errstr; Disconnects the database from the database handle. C<disconnect> is typically only used before exiting the program. The handle is of little use after disconnecting. The transaction behaviour of the C<disconnect> method is, sadly, undefined. Some database systems (such as Oracle and Ingres) will automatically commit any outstanding changes, but others (such as Informix) will rollback any outstanding changes. Applications not using C<AutoCommit> should explicitly call C<commit> or C<rollback> before calling C<disconnect>. The database is automatically disconnected by the C<DESTROY> method if still connected when there are no longer any references to the handle. The C<DESTROY> method for each driver should implicitly call C<rollback> to undo any uncommitted changes. This is vital behaviour to ensure that incomplete transactions don't get committed simply because Perl calls C<DESTROY> on every object before exiting. Also, do not rely on the order of object destruction during "global destruction", as it is undefined. Generally, if you want your changes to be commited or rolled back when you disconnect, then you should explicitly call L</commit> or C<finish> method on the active handles. =head3 C<ping> $rc = $dbh->ping; Attempts to determine, in a reasonably efficient way, if the database server is still running and the connection to it is still working. Individual drivers should implement this function in the most suitable manner for their database engine. The current I<default> implementation always returns true without actually doing anything. Actually, it returns "C. =head3 C<get_info> $value = $dbh->get_info( $info_type ); Returns information about the implementation, i.e. driver and data source capabilities, restrictions etc. It returns C<undef> for unknown or unimplemented information types. For example: $database_version = $dbh->get_info( 18 ); # SQL_DBMS_VER $max_select_tables = $dbh->get_info( 106 ); # SQL_MAXIMUM_TABLES_IN_SELECT See L</ L<DBI::Const::GetInfoType> for more details. Because some DBI methods make use of get_info(), drivers are strongly encouraged to support I =head3 C ('C<_>'): =over 4 =item * If the value of $catalog is '%' and $schema and $table name are empty strings, the result set contains a list of catalog names. For example: $sth = $dbh->table_info('%', '', ''); =item * If the value of $schema is '%' and $catalog and $table are empty strings, the result set contains a list of schema names. =item * If the value of $type is '%' and $catalog, $schema, and $table are all empty strings, the result set contains a list of table types. =back. B<TABLE_CAT>: Table catalog identifier. This field is NULL (C<undef>) if not applicable to the data source, which is usually the case. This field is empty if not applicable to the table. B<TABLE_SCHEM>: The name of the schema containing the TABLE_NAME value. This field is NULL (C<undef>) if not applicable to data source, and empty if not applicable to the table. B<TABLE_NAME>: Name of the table (or view, synonym, etc). B<TABLE_TYPE>: One of the following: "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM" or a type identifier that is specific to the data source. B<REMARKS>: A description of the table. May be NULL (C<undef>). Note that C<table_info> might not return records for all tables. Applications can use any valid table regardless of whether it's returned by C<table_info>. See also L</tables>, L</"Catalog Methods"> and L</"Standards Reference Information">. =head3 C. If the arguments don't match any tables then you'll still get a statement handle, it'll just return no rows.. Note: A driver may provide column metadata not only for base tables, but also for derived objects like SYNONYMS etc. B<COLUMN_NAME>: The column identifier. B<DATA_TYPE>: The concise data type code. B<TYPE_NAME>: A data source dependent data type name. B<COLUMN_SIZE>: The column size. This is the maximum length in characters for character data types, the number of digits or bits for numeric data types or the length in the representation of temporal types. See the relevant specifications for detailed information. B<BUFFER_LENGTH>: The length in bytes of transferred data. B<DECIMAL_DIGITS>: The total number of significant digits to the right of the decimal point. B<NUM_PREC_RADIX>: The radix for numeric precision. The value is 10 or 2 for numeric data types and NULL (C<undef>) if not applicable. B<NULLABLE>: Indicates if a column can accept NULLs. The following values are defined: SQL_NO_NULLS 0 SQL_NULLABLE 1 SQL_NULLABLE_UNKNOWN 2 B<REMARKS>: A description of the column. B<COLUMN_DEF>: The default value of the column. B<SQL_DATA_TYPE>: The SQL data type. B<SQL_DATETIME_SUB>: The subtype code for datetime and interval data types. B<CHAR_OCTET_LENGTH>: The maximum length in bytes of a character or binary data type column. B<ORDINAL_POSITION>: The column sequence number (starting with 1). L</"Catalog Methods"> and L</"Standards Reference Information">. =head3 C<COLUMN_NAME>: The column identifier. B<KEY_SEQ>: The column sequence number (starting with 1). Note: This field is named B<ORDINAL_POSITION> in SQL/CLI. B<PK_NAME>: The primary key constraint identifier. This field is NULL (C<undef>) if not applicable to the data source. See also L</"Catalog Methods"> and L</"Standards Reference Information">. =head3 C. =head3 C()). C<$pk_catalog>, C<$pk_schema>, C<$pk_table> identify the primary (unique) key table (B<PKT>). C<$fk_catalog>, C<$fk_schema>, C<$fk_table> identify the foreign key table (B<FKT>). If both B<PKT> and B<FKT> are given, the function returns the foreign key, if any, in table B<FKT> that refers to the primary (unique) key of table B<PKT>. (Note: In SQL/CLI, the result is implementation-defined.) If only B<PKT> is given, then the result set contains the primary key of that table and all foreign keys that refer to it. If only B. B<PKTABLE_CAT ( UK_TABLE_CAT )>: The primary (unique) key table catalog identifier. This field is NULL (C<undef>) if not applicable to the data source, which is often the case. This field is empty if not applicable to the table. B<PKTABLE_SCHEM ( UK_TABLE_SCHEM )>: The primary (unique) key table schema identifier. This field is NULL (C<undef>) if not applicable to the data source, and empty if not applicable to the table. B<PKTABLE_NAME ( UK_TABLE_NAME )>: The primary (unique) key table identifier. B<PKCOLUMN_NAME (UK_COLUMN_NAME )>: The primary (unique) key column identifier. B<FKTABLE_CAT ( FK_TABLE_CAT )>: The foreign key table catalog identifier. This field is NULL (C<undef>) if not applicable to the data source, which is often the case. This field is empty if not applicable to the table. B<FKTABLE_SCHEM ( FK_TABLE_SCHEM )>: The foreign key table schema identifier. This field is NULL (C<undef>) if not applicable to the data source, and empty if not applicable to the table. B<FKTABLE_NAME ( FK_TABLE_NAME )>: The foreign key table identifier. B<FKCOLUMN_NAME ( FK_COLUMN_NAME )>: The foreign key column identifier. B<KEY_SEQ ( ORDINAL_POSITION )>: The column sequence number (starting with 1). B<UPDATE_RULE ( UPDATE_RULE )>: The referential action for the UPDATE rule. The following codes are defined: CASCADE 0 RESTRICT 1 SET NULL 2 NO ACTION 3 SET DEFAULT 4 B<DELETE_RULE ( DELETE_RULE )>: The referential action for the DELETE rule. The codes are the same as for UPDATE_RULE. B<FK_NAME ( FK_NAME )>: The foreign key name. B<PK_NAME ( UK_NAME )>: The primary (unique) key name. B<DEFERRABILITY ( DEFERABILITY )>: The deferrability of the foreign key constraint. The following codes are defined: INITIALLY DEFERRED 5 INITIALLY IMMEDIATE 6 NOT DEFERRABLE 7 B< ( L</"Catalog Methods"> and L</"Standards Reference Information">. =head3 C<statistics_info> B L<<NON_UNIQUE>: Unique index indicator. Returns 0 for unique indexes, 1 for non-unique indexes B<INDEX_QUALIFIER>: Index qualifier identifier. The identifier that is used to qualify the index name when doing a C<DROP INDEX>; NULL (C<undef>) is returned if an index qualifier is not supported by the data source. If a non-NULL (defined) value is returned in this column, it must be used to qualify the index name on a C<DROP INDEX> statement; otherwise, the TABLE_SCHEM should be used to qualify the index name. B<INDEX_NAME>: The index identifier. B (C<undef>). B<ORDINAL_POSITION>: Column sequence number (starting with 1). B<COLUMN_NAME>: The column identifier. B<ASC_OR_DESC>: Column sort sequence. C<A> for Ascending, C<D> for Descending, or NULL (C<undef>) if not supported for this index. B<CARDINALITY>: Cardinality of the table or index. For indexes, this is the number of unique values in the index. For tables, this is the number of rows in the table. If not supported, the value will be NULL (C<undef>). B<PAGES>: Number of storage pages used by this table or index. If not supported, the value will be NULL (C<undef>). B<FILTER_CONDITION>: The index filter condition as a string. If the index is not a filtered index, or it cannot be determined whether the index is a filtered index, this value is NULL (C<undef>). If the index is a filtered index, but the filter condition cannot be determined, this value is the empty string C<''>. Otherwise it will be the literal filter condition as a string, such as C<SALARY <= 4500>. See also L</"Catalog Methods"> and L</"Standards Reference Information">. =head3 C<tables> @names = $dbh->tables( $catalog, $schema, $table, $type ); @names = $dbh->tables; # deprecated Simple interface to table_info(). Returns a list of matching table names, possibly including a catalog/schema prefix. See L</table_info> for a description of the parameters. If C<$dbh-E<gt>get_info(29)> returns true (29 is SQL_IDENTIFIER_QUOTE_CHAR) then the table names are constructed and quoted by L</quote_identifier> to ensure they are usable even if they contain whitespace or reserved words etc. This means that the table names returned will include quote characters. =head3 C C<Name =>E<gt> C C<DATA_TYPE> field if there are different ways to spell the type name and/or there are variants of the type with different attributes (e.g., with and without C<AUTO_UNIQUE_VALUE> set, with and without C<UNSIGNED_ATTRIBUTE>, etc). The rows are ordered by C<DATA_TYPE> first and then by how closely each type maps to the corresponding ODBC SQL data type, closest first. The meaning of the fields is described in the documentation for the L</type_info> method provides a more usable and useful interface to the data. =head3 C<type_info> @type_info = $dbh->type_info($data_type); Returns a list of hash references holding information about one or more variants of $data_type. The list is ordered by C<DATA_TYPE> first and then by how closely each type maps to the corresponding ODBC SQL data type, closest first. If called in a scalar context then only the first (best) element is returned. If $data_type is undefined or C<SQL_ALL_TYPES>, then the list will contain hashes for all data type variants supported by the database and driver. If $data_type is an array reference then C<type_info> returns the information for the I<first> type in the array that has any matches. The keys of the hash follow the same letter case conventions as the rest of the DBI (see L</Naming Conventions and Name Space>). The following uppercase items should always exist, though may be undef: =over 4 =item TYPE_NAME (string) Data type name for use in CREATE TABLE statements etc. =item DATA_TYPE (integer) SQL data type number. =item. =item LITERAL_PREFIX (string) Characters used to prefix a literal. A typical prefix is "C<'>" for characters, or possibly "C<0x>" for binary values passed as hexadecimal. NULL (C<undef>) is returned for data types for which this is not applicable. =item LITERAL_SUFFIX (string) Characters used to suffix a literal. Typically "C<'>" for characters. NULL (C<undef>) is returned for data types where this is not applicable. =item CREATE_PARAMS (string) Parameter names for data type definition. For example, C<CREATE_PARAMS> for a C<DECIMAL> would be "C<precision,scale>" if the DECIMAL type should be declared as C<DECIMAL(>I<precision,scale>C<)> where I<precision> and I<scale> are integer values. For a C<VARCHAR> it would be "C<max length>". NULL (C<undef>) is returned for data types for which this is not applicable. =item NULLABLE (integer) Indicates whether the data type accepts a NULL value: C<0> or an empty string = no, C<1> = yes, C<2> = unknown. =item CASE_SENSITIVE (boolean) Indicates whether the data type is case sensitive in collations and comparisons. =item SEARCHABLE (integer) Indicates how the data type can be used in a WHERE clause, as follows: 0 - Cannot be used in a WHERE clause 1 - Only with a LIKE predicate 2 - All comparison operators except LIKE 3 - Can be used in a WHERE clause with any comparison operator =item UNSIGNED_ATTRIBUTE (boolean) Indicates whether the data type is unsigned. NULL (C<undef>) is returned for data types for which this is not applicable. =item FIXED_PREC_SCALE (boolean) Indicates whether the data type always has the same precision and scale (such as a money type). NULL (C<undef>) is returned for data types for which this is not applicable. =item AUTO_UNIQUE_VALUE (boolean) Indicates whether a column of this data type is automatically set to a unique value whenever a new row is inserted. NULL (C<undef>) is returned for data types for which this is not applicable. =item LOCAL_TYPE_NAME (string) Localized version of the C<TYPE_NAME> for use in dialog with users. NULL (C<undef>) is returned if a localized name is not available (in which case C<TYPE_NAME> should be used). =item MINIMUM_SCALE (integer) The minimum scale of the data type. If a data type has a fixed scale, then C<MAXIMUM_SCALE> holds the same value. NULL (C<undef>) is returned for data types for which this is not applicable. =item MAXIMUM_SCALE (integer) The maximum scale of the data type. If a data type has a fixed scale, then C<MINIMUM_SCALE> holds the same value. NULL (C<undef>) is returned for data types for which this is not applicable. =item SQL_DATA_TYPE (integer) This column is the same as the C<DATA_TYPE> column, except for interval and datetime data types. For interval and datetime data types, the C<SQL_DATA_TYPE> field will return C<SQL_INTERVAL> or C<SQL_DATETIME>, and the C<SQL_DATETIME_SUB> field below will return the subcode for the specific interval or datetime data type. If this field is NULL, then the driver does not support or report on interval or datetime subtypes. =item SQL_DATETIME_SUB (integer) For interval or datetime data types, where the C<SQL_DATA_TYPE> field above is C<SQL_INTERVAL> or C<SQL_DATETIME>, this field will hold the I<subcode> for the specific interval or datetime data type. Otherwise it will be NULL (C<undef>). Although not mentioned explicitly in the standards, it seems there is a simple relationship between these values: DATA_TYPE == (10 * SQL_DATA_TYPE) + SQL_DATETIME_SUB =item NUM_PREC_RADIX (integer) The radix value of the data type. For approximate numeric types, C<NUM_PREC_RADIX> contains the value 2 and C<COLUMN_SIZE> holds the number of bits. For exact numeric types, C<NUM_PREC_RADIX> contains the value 10 and C<COLUMN_SIZE> holds the number of decimal digits. NULL (C<undef>) is returned either for data types for which this is not applicable or if the driver cannot report this information. =item INTERVAL_PRECISION (integer) The interval leading precision for interval types. NULL is returned either for data types for which this is not applicable or if the driver cannot report this information. =back C<SQL_SMALLINT>, C<SQL_INTEGER>, C<SQL_DECIMAL>, etc. See also L</"Standards Reference Information">. =head3 C C<'Don''t'> (including the outer quotation marks). An undefined C<$value> value will be returned as the string C<NULL> (without single quotation marks) to match how NULLs are represented in SQL. If C<$data_type> is supplied, it is used to try to determine the required quoting behaviour by using the information returned by L</type_info>. As a special case, the standard numeric types are optimized to return C<$value> without calling C<type_info>. Quote will probably I I<not> be used with L</"Placeholders and Bind Values">. =head3 C (C<.>) character. For example: $id = $dbh->quote_identifier( undef, 'Her schema', 'My table' ); would, for most database types, return C<"Her schema"."My table"> (including all the double quotation marks). If three names are supplied then the first is assumed to be a catalog name and special rules may be applied based on what L</get_info> returns for SQL_CATALOG_NAME_SEPARATOR (41) and SQL_CATALOG_LOCATION (114). For example, for Oracle: $id = $dbh->quote_identifier( 'link', 'schema', 'table' ); would return C<"schema"."table"@"link">. =head3 C C<DESTROY> will generate a warning and return undef. Why would you want to do this? You don't, forget I even mentioned it. Unless, that is, you're implementing something advanced like a multi-threaded connection pool. See L<DBI::Pool>. The returned $imp_data can be passed as a C<dbi_imp_data> attribute to a later connect() call, even in a separate thread in the same process, where the driver can use it to 'adopt' the existing connection that the implementation data was taken from. Some things to keep in mind... B<*> the $imp_data holds the only reference to the underlying database API connection data. That connection is still 'live' and won't be cleaned up properly unless the $imp_data is used to create a new $dbh which is then allowed to disconnect() normally. B<*> using the same $imp_data to create more than one other new $dbh at a time may well lead to unpleasant problems. Don't do that. Any child statement handles are effectively destroyed when take_imp_data() is called. The C<take_imp_data> method was added in DBI 1.36 but wasn't useful till 1.49. =head2 =head3 C<AutoCommit> (boolean) If true, then database changes cannot be rolled-back (undone). If false, then database changes automatically occur within a "transaction", which must either be committed or rolled back using the C<commit> or C<rollback> methods. Drivers should always default to C<AutoCommit> mode (an unfortunate choice largely forced on the DBI by ODBC and JDBC conventions.) Attempting to set C<AutoCommit> to an unsupported value is a fatal error. This is an important feature of the DBI. Applications that need full transaction behaviour can set C<$dbh-E<gt>{AutoCommit} = 0> (or set C<AutoCommit> to 0 via L<'>). B<* Databases which don't support transactions at all> For these databases, attempting to turn C<AutoCommit> off is a fatal error. C<commit> and C<rollback> both issue warnings about being ineffective while C<AutoCommit> is in effect. B<* Databases in which a transaction is always active> These are typically mainstream commercial relational databases with "ANSI standard" transaction behaviour. If C<AutoCommit> is off, then changes to the database won't have any lasting effect unless L</commit> is called (but see also L</disconnect>). If L</rollback> is called then any changes since the last commit are undone. If C<AutoCommit> is on, then the effect is the same as if the DBI called C<commit> automatically after every successful database operation. So calling C<commit> or C<rollback> explicitly while C<AutoCommit> is on would be ineffective because the changes would have already been commited. Changing C<AutoCommit> from off to on will trigger a L</commit>. For databases which don't support a specific auto-commit mode, the driver has to commit each statement automatically using an explicit C<COMMIT> after it completes successfully (and roll it back using an explicit C<ROLLBACK> if it fails). The error information reported to the application will correspond to the statement which was executed, unless it succeeded and the commit or rollback failed. B<* Databases in which a transaction must be explicitly started> For these databases, the intention is to have them act like databases in which a transaction is always active (as described above). To do this, the driver will automatically begin an explicit transaction when C<AutoCommit> is turned off, or after a L</commit> or L</rollback> (or when the application issues the next database operation after one of those events). In this way, the application does not have to treat these databases as a special case. See L</commit>, L</disconnect> and L</Transactions> for other important notes about transactions. =head3 C<Driver> (handle) Holds the handle of the parent driver. The only recommended use for this is to find the name of the driver using: $dbh->{Driver}->{Name} =head3 C<Name> (string) Holds the "name" of the database. Usually (and recommended to be) the same as the "C<dbi:DriverName:...>" string used to connect to the database, but with the leading "C<dbi:DriverName:>" removed. =head3 C<Statement> (string, read-only) Returns the statement string passed to the most recent L</prepare> method called in this database handle, even if that method failed. This is especially useful where C<RaiseError> is enabled and the exception handler checks $@ and sees that a 'prepare' method call failed. =head3 C<RowCacheSize> (integer) A hint to the driver indicating the size of the local row cache that the application would like the driver to use for future C<SELECT> statements. If a row cache is not implemented, then setting C<RowCacheSize> is ignored and getting the value returns C<undef>. Some C (I<cached rows * maximum size of row>). Also, a large cache will cause a longer delay not only for the first fetch, but also whenever the cache needs refilling. See also the L</RowsInCache> statement handle attribute. =head3 C<Username> (string) Returns the username used to connect to the database. =head1 DBI STATEMENT HANDLE OBJECTS This section lists the methods and attributes associated with DBI statement handles. =head2 Statement Handle Methods The DBI defines the following methods for use on DBI statement handles: =head3 C<bind_param> $sth->bind_param($p_num, $bind_value) $sth->bind_param($p_num, $bind_value, \%attr) $sth->bind_param($p_num, $bind_value, $bind_type) The C<bind_param> method takes a copy of $bind_value and associates it (binds it) with a placeholder, identified by $p_num, embedded in the prepared statement. Placeholders are indicated with question mark character (C<?>). For example: $dbh->{RaiseError} = 1; # save having to check each method call $sth = $dbh->prepare("SELECT name, age FROM people WHERE name LIKE ?"); $sth->bind_param(1, "John%"); # placeholders are numbered from 1 $sth->execute; DBI::dump_results($sth); See L</"Placeholders and Bind Values"> for more information. B<Data Types for Placeholders> The C<\%attr> hash reference. This example is equivalent to the one above: $sth->bind_param(1, $value, SQL_INTEGER); The C<TYPE> value indicates the standard (non-driver-specific) type for this parameter. To specify the driver-specific type, the driver may support a driver-specific attribute, such as C<{ ora_type =E<gt> 97 }>. The SQL_INTEGER and other related constants can be imported using use DBI qw(:sql_types); See L</"DBI Constants"> for more information. The data type for a placeholder cannot be changed after the first C<bind_param> call. In fact the whole \%attr parameter is 'sticky' in the sense that a driver only needs to consider the \%attr parameter C<bind_param> call, you can let the driver pass the value as the default type (C<VARCHAR>). You can then use an SQL function to convert the type within the statement. For example: INSERT INTO price(code, price) VALUES (?, CONVERT(MONEY,?)) The C<CONVERT> function used here is just an example. The actual function and syntax will vary between different databases and is non-portable. See also L</"Placeholders and Bind Values"> for more information. =head3 C L</bind_param>, but also enables values to be updated by the statement. The statement is typically a call to a stored procedure. The C<$bind_value> must be passed as a reference to the actual value to be used. Note that unlike L</bind_param>, the C<$bind_value> variable is not copied when C<bind_param_inout> is called. Instead, the value in the variable is read at the time L</execute> is called. The additional C<$max_len> parameter specifies the minimum amount of memory to allocate to C<undef> are used to indicate null values. See also L</"Placeholders and Bind Values"> for more information. =head3 C<bind_param_array> $rc = $sth->bind_param_array($p_num, $array_ref_or_value) $rc = $sth->bind_param_array($p_num, $array_ref_or_value, \%attr) $rc = $sth->bind_param_array($p_num, $array_ref_or_value, $bind_type) The C<bind_param_array> method is used to bind an array of values to a placeholder embedded in the prepared statement which is to be executed with C<%attr> ($bind_type) argument is the same as defined for L</bind_param>. Refer to L</bind_param> for general details on using placeholders. (Note that bind_param_array() can I<not> be used to expand a placeholder into a list of values for a statement like "SELECT foo WHERE bar IN (?)". A placeholder can only ever represent one value per execution.) Scalar values, including C<undef>, may also be bound by C<bind_param_array>. In which case the same value will be used for each L</execute> call. Driver-specific implementations may behave differently, e.g., when binding to a stored procedure call, some databases may permit mixing scalars and arrays as arguments. The default implementation provided by DBI (for drivers that have not implemented array binding) is to iteratively call L<, C<bind_param_array> and L</bind_param> cannot be mixed in the same statement execution, and C<bind_param_array> must be used with L</execute_array>; using C<bind_param_array> will have no effect for L</execute>. The C<bind_param_array> method was added in DBI 1.22. =head3 C<execute> $rv = $sth->execute or die $sth->errstr; $rv = $sth->execute(@bind_values) or die $sth->errstr; Perform whatever processing is necessary to execute the prepared statement. An C<undef> is returned if an error occurs. A successful C<execute> always returns true regardless of the number of rows affected, even if it's zero (see below). It is always important to check the return status of C<execute> (and most other DBI methods) for errors if you're not using L</RaiseError>. For a I<non>-C<SELECT> statement, C<execute> returns the number of rows affected, if known. If no rows were affected, then C<execute> returns "C<0E0>", which Perl will treat as 0 but will regard as true. Note that it is I<not> an error for no rows to be affected by a statement. If the number of rows affected is not known, then C<execute> returns -1. For C<SELECT> statements, execute simply "starts" the query within the database engine. Use one of the fetch methods to retrieve the data after calling C<execute>. The C<execute> method does I<not> return the number of rows that will be returned by the query (because most databases can't tell in advance), it simply returns a true value. You can tell if the statement was a C<SELECT> statement by checking if C<$sth-E<gt>{NUM_OF_FIELDS}> is greater than zero after calling C<execute>. If any arguments are given, then C<execute> will effectively call L</bind_param> for each value before executing the statement. Values bound in this way are usually treated as C<SQL_VARCHAR> types unless the driver can determine the correct type (which is rare), or unless C<bind_param> (or C<bind_param_inout>) has already been used to specify the type. If execute() is called on a statement handle that's still active ($sth->{Active} is true) then it should effectively call finish() to tidy up the previous execution results before starting this new execution. =head3 C L</bind_param_array>, or via a reference passed in \%attr. When called in scalar context the execute_array() method returns the number of tuples executed, or C<undef> if an error occured. C<ArrayTupleFetch> attribute, or else column-wise in the C<@bind_values> argument, or else column-wise by prior calls to L</bind_param_array>. Where column-wise binding is used (via the I<variable> length array with all elements having the same value. It's does not influence the number of tuples executed, so if all bound arrays have zero elements then zero tuples will be executed. If I<all> bound values are scalars then one tuple will be executed, making execute_array() act just like execute(). The C<@bind_values> are given, then C<execute_array> will effectively call L</bind_param_array> for each value before executing the statement. Values bound in this way are usually treated as C<SQL_VARCHAR> types unless the driver can determine the correct type (which is rare), or unless C<bind_param>, C<bind_param_inout>, C<bind_param_array>, or C<bind_param_inout_array> has already been used to specify the type. See L</bind_param_array> for details. The C<ArrayTupleStatus> attribute can be used to specify a reference to an array which will receive the execute status of each executed parameter tuple. Note the C<ArrayTupleStatus> attribute was mandatory until DBI 1.38. B<any> tuple execution returns an error, C<execute_array> will return C, C<execute_array> returns the number tuples executed. If no tuples were executed, then execute_array() returns "C C<AutoCommit> is on, the default DBI implementation will cause each parameter tuple to be inidividually committed (or rolled back in the event of an error). If C C<AutoCommit> turned off, and using explicit C<commit> after each C<execute_array> call. The C<execute_array> method was added in DBI 1.22, and ArrayTupleFetch was added in 1.36. =head3 C is most often used via the execute_array() method, not directly. C C<execute_for_fetch> method was added in DBI 1.38. =head3 C<fetchrow_arrayref> $ary_ref = $sth->fetchrow_arrayref; $ary_ref = $sth->fetch; # alias Fetches the next row of data and returns a reference to an array holding the field values. Null fields are returned as C<undef> values in the array. This is the fastest way to fetch data, particularly if used with C<$sth-E<gt>bind_columns>. If there are no more rows or if an error occurs, then C<fetchrow_arrayref> returns an C<undef>. You should check C<$sth-E<gt>err> afterwards (or use the C<RaiseError> attribute) to discover if the L</bind_columns>. =head3 C<fetchrow_array> @ary = $sth->fetchrow_array; An alternative to C<fetchrow_arrayref>. Fetches the next row of data and returns it as a list containing the field values. Null fields are returned as C<undef> values in the list. If there are no more rows or if an error occurs, then C<fetchrow_array> returns an empty list. You should check C<$sth-E<gt>err> afterwards (or use the<fetchrow_array> in a scalar context. =head3 C<fetchrow_hashref> $hash_ref = $sth->fetchrow_hashref; $hash_ref = $sth->fetchrow_hashref($name); An alternative to C<fetchrow_arrayref>. Fetches the next row of data and returns it as a reference to a hash containing field name and field value pairs. Null fields are returned as C<undef> values in the hash. If there are no more rows or if an error occurs, then C<fetchrow_hashref> returns an C<undef>. You should check C<$sth-E<gt>err> afterwards (or use the C<RaiseError> attribute) to discover if the C<undef> returned was due to an error. The optional C<$name> parameter specifies the name of the statement handle attribute. For historical reasons it defaults to "C<NAME>", however using either "C<NAME_lc>" or "C<NAME_uc>" is recomended for portability. The keys of the hash are the same names returned by C<$sth-E<gt>{$name}>. If more than one field has the same name, there will only be one entry in the returned hash for those fields. Because of the extra work C<fetchrow_hashref> and Perl have to perform, it is not as efficient as C<fetchrow_arrayref> or. =head3 C<fetchall_arrayref> $tbl_ary_ref = $sth->fetchall_arrayref; $tbl_ary_ref = $sth->fetchall_arrayref( $slice ); $tbl_ary_ref = $sth->fetchall_arrayref( $slice, $max_rows ); The C<fetchall_arrayref> method can be used to fetch all the data to be returned from a prepared and executed statement handle. It returns a reference to an array that contains one reference per row. If there are no rows to return, C<fetchall_arrayref> returns a reference to an empty array. If an error occurs, C<fetchall_arrayref> returns the data fetched thus far, which may be none. You should check C<$sth-E<gt>err> afterwards (or use the C<RaiseError> attribute) to discover if the data is complete or was truncated due to an error. If $slice is an array reference, C<fetchall_arrayref> uses L<, C<fetchall_arrayref> acts as if passed an empty array ref. If $slice is a hash reference, C<fetchall_arrayref> uses L< L< I<might> be the fastest way to fetch and process lots of rows using the DBI, but it depends on the relative cost of method calls vs memory allocation. A standard C(). =head3 C<fetchall_hashref> $hash_ref = $sth->fetchall_hashref($key_field); The, C<fetchall_hashref> returns a reference to an empty hash. If an error occurs, C<fetchall_hashref> returns the data fetched thus far, which may be none. You should check C<$sth-E<gt>err> afterwards (or use the returing. =head3 C<finish> $rc = $sth->finish; Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. The C<finish> method is rarely needed, and frequently overused, but can sometimes be helpful in a few very specific situations to allow the server to free up resources (such as sort buffers). When all the data has been fetched from a C<SELECT> statement, the driver should automatically call C<finish> for you. So you should I<not> normally need to call it explicitly I<except> when you know that you've not fetched all the data from a statement handle. The most common example is when you only want to fetch one row, but in that case the C<selectrow_*> methods are usually better anyway. Adding calls to C<finish> method can be used to tell the server that the buffer space can be freed. Calling C<finish> resets the L</Active> attribute for the statement. It may also make some statement handle attributes (such as C<NAME> and C<TYPE>) unavailable if they have not already been accessed (and thus cached). The C<finish> method does not affect the transaction status of the database connection. It has nothing to do with transactions. It's mostly an internal "housekeeping" method that is rarely needed. See also L</disconnect> and the L</Active> attribute. The C<finish> method should have been called C<discard_pending_rows>. =head3 C<rows> $rv = $sth->rows; Returns the number of rows affected by the last row affecting command, or -1 if the number of rows is not known or not available. Generally, you can only rely on a row count after a I<non>-C<SELECT> C<execute> (for some specific operations like C<UPDATE> and C<DELETE>), or after fetching all the rows of a C<SELECT> statement. For C<rows> method or C<$DBI::rows> with C<SELECT> statements is not recommended. One alternative method to get a row count for a C<SELECT> is to execute a "SELECT COUNT(*) FROM ..." SQL statement with the same "..." as your query and then fetch the row count from that. =head3 C<SELECT> statement. Column numbers count up from 1. You do not need to bind output columns in order to fetch data. For maximum portability between drivers, bind_col() should be called after execute() and not before. See also C L</bind_param> method performs a similar, but opposite, function for input variables. B<Data Types for Column Binding> The value and not just a particular bound variable. As a short-cut for the common case, the data type can be passed directly, in place of the C<\%attr> hash reference. This example is equivalent to the one above: $sth->bind_col(1, undef, SQL_DATETIME); The C<TYPE> value indicates the standard (non-driver-specific) type for this parameter. To specify the driver-specific type, the driver may support a driver-specific attribute, such as C<{ ora_type =E<gt> 97 }>. The SQL_DATETIME and other related constants can be imported using use DBI qw(:sql_types); See L</"DBI Constants"> for more information. The data type for a bind variable cannot be changed after the first C. =head3 C<bind_columns> $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind); Calls L</bind_col> for each column of the C<SELECT> statement. The list of references should have the same number of elements as the number of columns in the C<SELECT> statement. If it doesn't then C<bind_columns> will bind the elements given, upto C<undef> or a hash reference. Here's a more fancy example that binds columns to the values I<inside> a hash (thanks to H.Merijn Brand): $sth->execute; my %row; $sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } )); while ($sth->fetch) { print "$row{region}: $row{sales}\n"; } =head3 C<dump_results> $rows = $sth->dump_results($maxlen, $lsep, $fsep, $fh); Fetches all the rows from C<$sth>, calls C<DBI::neat_list> for each row, and prints the results to C<$fh> (defaults to C<STDOUT>) separated by C<$lsep> (default C<"\n">). C<$fsep> defaults to C<", "> and C<$maxlen> defaults to 35. This method is designed as a handy utility for prototyping and testing queries. Since it uses L</neat_list> to format and edit the string for reading by humans, it is not recomended for data transfer applications. =head2 C<$sth-E<gt>execute> has been successfully called. Typically the attribute will be C<undef> in these situations. Some attributes, like NAME, are not appropriate to some types of statement, like SELECT. Typically the attribute will be C<undef> in these situations. For drivers which support stored procedures and multiple result sets (see L</more_results>) these attributes relate to the I<current> result set. See also L</finish> to learn more about the effect it may have on some attributes. =head3 C<NUM_OF_FIELDS> (integer, read-only) Number of fields (columns) in the data the prepared statement may return. Statements that don't return rows of data, like C<DELETE> and C<CREATE> set C<NUM_OF_FIELDS> to 0 (though it may be undef in some drivers). =head3 C<NUM_OF_PARAMS> (integer, read-only) The number of parameters (placeholders) in the prepared statement. See SUBSTITUTION VARIABLES below for more details. =head3 C L</NAME_lc> or L</NAME_uc>. print "First column name: $sth->{NAME}->[0]\n"; =head3 C<NAME_lc> (array-ref, read-only) Like L</NAME> but always returns lowercase names. =head3 C<NAME_uc> (array-ref, read-only) Like L</NAME> but always returns uppercase names. =head3 C<NAME_hash> (hash-ref, read-only) =head3 C<NAME_lc_hash> (hash-ref, read-only) =head3 C<NAME_uc_hash> (hash-ref, read-only) The C<NAME_hash>, C<NAME_lc_hash>, and C<NAME_uc_hash> attributes return column name information as a reference to a hash. The keys of the hash are the names of the columns. The letter case of the keys corresponds to the letter case returned by the C<NAME>, C<NAME_lc>, and"; =head3 C<TYPE> should have at least one entry in the output of the C<type_info_all> method (see L</type_info_all>). =head3 C<PRECISION> .) =head3 C<SCALE> (array-ref, read-only) Returns a reference to an array of integer values for each column. NULL (C<undef>) values indicate columns where scale is not applicable. =head3 C<NULLABLE> (array-ref, read-only) Returns a reference to an array indicating the possibility of each column returning a null. Possible values are C<0> (or an empty string) = no, C<1> = yes, C<2> = unknown. print "First column may return NULL\n" if $sth->{NULLABLE}->[0]; =head3 C<CursorName> (string, read-only) Returns the name of the cursor associated with the statement handle, if available. If not available or if the database driver does not support the C<"where current of ..."> SQL syntax, then it returns C<undef>. =head3 C<Database> (dbh, read-only) Returns the parent $dbh of the statement handle. =head3 C<ParamValues> (hash ref, read-only) Returns a reference to a hash containing the values currently bound to placeholders. The keys of the hash are the 'names' of the placeholders, typically integers starting at 1. Returns undef if not supported by the driver. See L</ShowErrorStatement> for an example of how this is used. If the driver supports C C<ParamValues> are not I C<ParamValues> can be passed to another bind_param() method with the same TYPE and will be seen by the database as the same value. It is also possible that the keys in the hash returned by C<ParamValues> are not exactly the same as those implied by the prepared statement. For example, DBD::Oracle translates 'C<?>' placeholders into 'C<:pN>' where N is a sequence number starting at 1. The C<ParamValues> attribute was added in DBI 1.28. =head3 C<ParamArrays> (hash ref, read-only) Returns a reference to a hash containing the values currently bound to placeholders with L</execute_array> or C<ParamArrays> are not I<exactly> the same as those passed to L</bind_param_array> or C<ParamArrays> are not exactly the same as those implied by the prepared statement. For example, DBD::Oracle translates 'C<?>' placeholders into 'C<:pN>' where N is a sequence number starting at 1. =head3 L</bind_param> for the format and values), plus anything else that was passed as the third argument to bind_param(). Returns undef if not supported by the driver. If the driver supports C C<ParamTypes> are not I C<ParamTypes> are not exactly the same as those implied by the prepared statement. For example, DBD::Oracle translates 'C<?>' placeholders into 'C<:pN>' where N is a sequence number starting at 1. The C<ParamTypes> attribute was added in DBI 1.49. Implementation is the responsibility of individual drivers; the DBI layer default implementation simply returns undef. =head3 C<Statement> (string, read-only) Returns the statement string passed to the L</prepare> method. =head3 C<RowsInCache> (integer, read-only) If the driver supports a local row cache for C<SELECT> statements, then this attribute holds the number of un-fetched rows in the cache. If the driver doesn't, then it returns C<undef>. Note that some drivers pre-fetch rows on execute, whereas others wait till the first fetch. See also the L</RowCacheSize> database handle attribute. =head1 FURTHER INFORMATION =head2 Catalog Methods An application can retrieve metadata information from the DBMS by issuing appropriate queries on the views of the Information Schema. Unfortunately, C C<undef> to an optional argument does not constrain the search for that argument. However, an empty string ('') is treated as a regular search criteria and will only match an empty value. B<Note>: SQL/CLI and ODBC differ in the handling of empty strings. An empty string will not restrict the result set in SQL/CLI. Most arguments in the catalog methods accept only I<ordinary values>, e.g. the arguments of C<primary_key_info()>. Such arguments are treated as a literal string, i.e. the case is significant and quote characters are taken literally. Some arguments in the catalog methods accept I<search patterns> (strings containing '_' and/or '%'), e.g. the C<$table> argument of C<column_info()>. Passing '%' is equivalent to leaving the argument C<undef>. B I<list value arguments>) are treated as I<identifier> if the C<SQL_ATTR_METADATA_ID> attribute is set to C<SQL_TRUE>. I<Quoted identifiers> are very similar to I<ordinary values>, i.e. their body (the string within the quotes) is interpreted literally. I<Unquoted identifiers> are compared in UPPERCASE. The DBI (currently) does not support the C<SQL_ATTR_METADATA_ID> attribute, i.e. it behaves like an ODBC driver where C<SQL_ATTR_METADATA_ID> is set to C<SQL_FALSE>. =head2 Transactions Transactions are a fundamental part of any robust database system. They protect against errors and database corruption by ensuring that sets of related changes to the database take place in atomic (indivisible, all-or-nothing) units. This section applies to databases that support transactions and where C<AutoCommit> is off. See L</AutoCommit> for details of using C<AutoCommit> with various types of databases. The recommended way to implement robust transactions in Perl applications is to use C<RaiseError> and S<C<eval { ... }>> (which is very fast, unlike S<C C<RaiseError> attribute is not set, then DBI calls would need to be manually checked for errors, typically like this: $h->method(@args) or die $h->errstr; With C<RaiseError> set, the DBI will automatically C<die> if any DBI method call on that handle (or a child handle) fails, so you don't have to test the return value of each method call. See L</RaiseError> for more details. A major advantage of the C<eval> approach is that the transaction will be properly rolled back if I<any> code (not just DBI calls) in the inner application dies for any reason. The major advantage of using the C<$h-E<gt>{RaiseError}> attribute is that all DBI calls will be checked automatically. Both techniques are strongly recommended. After calling C<commit> or C<rollback> many drivers will not let you fetch from a previously active C<SELECT> statement handle that's a child of the same database handle. A typical way round this is to connect the the database twice and use one connection for C<SELECT> statements. See L</AutoCommit> and L</disconnect> for other important information about transactions. =head2 C<SELECT> statement (unlike other data types), some special handling is required. In this situation, the value of the C<$h-E<gt>{LongReadLen}> attribute is used to determine how much buffer space to allocate when fetching such fields. The C<$h-E<gt>{LongTruncOk}> attribute is used to determine how to behave if a fetched value can't fit into the buffer. See the description of L</LongReadLen> for more information. When trying to insert long or binary values, placeholders should be used since there are often limits on the maximum size of an C<INSERT> statement and the L</quote> method generally can't cope with binary data. See L</Placeholders and Bind Values>. =head2 C C<q{...}> style quoting used in these examples avoids clashing with quotes that may be used in the SQL statement. Use the double-quote like C<qq{...}> operator if you want to interpolate variables into the string. See L<perlop/"Quote and Quote-like Operators"> for more details. =head2 Threads and Thread Safety Perl 5.7 and later support a new threading model called iThreads. (The old  I<not> at the same time, can cause problems. You have been warned. Using DBI with perl threads is not yet recommended for production environments. For more information see L<> Note: There is a bug in perl 5.8.2 when configured with threads and debugging enabled (bug #24463) which causes a DBI test to fail. =head2 Signal Handling and Canceling Operations [The following only applies to systems with unix-like signal handling. I'd welcome additions for other systems, especially Windows.] The first thing to say is that signal handling in Perl versions less than 5.8 is I I<not> run the %SIG handler. The handling is 'defered' until a 'safe' moment. Although this change made signal handling safe, it also lead to a problem with signals being defered untill C<alarm()> and C<$SIG{ALRM}>. =over 4 =item Cancel The DBI provides a C<cancel> method for statement handles. The C<cancel> method should abort the current operation and is designed to be called from a signal handler. For example: $SIG{INT} = sub { $sth->cancel }; However, few drivers implement this (the DBI provides a default method that just returns C<undef>) and, even if implemented, there is still a possibility that the statement handle, and even the parent database handle, will not be usable afterwards. If C<cancel> returns true, then it has successfully invoked the database engine's own cancel function. If it returns false, then C<cancel> failed. If it returns C<undef>, then the database driver does not have cancel implemented - very few do. =item Timeout The traditional way to implement a timeout is to set C<" ) { ... }. =back The solution on these systems is to use the I<not> work with perl versions less than perl 5.8 where C<POSIX::sigaction()> appears to be broken. For a cleaner implementation that works across perl versions, see Lincoln Baxter's Sys::SigAction module at L<>. The documentation for Sys::SigAction includes an longer discussion of this problem, and a DBD::Oracle test script. Be sure to read all the signal handling sections of the L<perlipc> manual. And finally, two more points to keep firmly in mind. Firstly, remember that what we've done here is essentially revert to old style I<unsafe> handling of these signals. So do as little as possible in the handler. Ideally just die(). Secondly, the handles in use at the time the signal is handled may not be safe to use afterwards. =head2 Subclassing the DBI DBI can be subclassed and extended just like any other object oriented module. Before we talk about how to do that, it's important to be clear about the various DBI classes and how they work together. By default C<$dbh = DBI-E<gt>connect(...)> returns a $dbh blessed into the C<DBI::db> class. And the C<$dbh-E<gt>prepare> method returns an $sth blessed into the C<DBI::st> class (actually it simply changes the last four characters of the calling handle class to be C<::st>). The leading 'C<DBI>' is known as the 'root class' and the extra 'C<::db>' or 'C<::st>' are the 'handle type suffixes'. If you want to subclass the DBI you'll need to put your overriding methods into the appropriate classes. For example, if you want to use a root class of C<MySubDBI> and override the do(), prepare() and execute() methods, then your do() and prepare() methods should be in the C<MySubDBI::db> class and the execute() method should be in the C<MySubDBI::st> class. To setup the inheritance hierarchy the @ISA variable in C<MySubDBI::db> should include C<DBI::db> and the @ISA variable in C<MySubDBI::st> should include C<DBI::st>. The C<MySubDBI> root class itself isn't currently used for anything visible and so, apart from setting @ISA to include C C<$h-E<gt>err> and C<RaiseError>, C<PrintError>, or C<HandleError> etc. set then the set_err() method will honour them. This means that if C<RaiseError> is set then set_err() won't return in the normal way but will 'throw an exception' that can be caught with an C<eval> block. You can stash private data into DBI handles via C<$h-E<gt>{private_..._*}>. See the entry under L</ATTRIBUTES COMMON TO ALL HANDLES> for info and important caveats. =head1 TRACING The DBI has a powerful tracing mechanism built in. It enables you to see what's going on 'behind the scenes', both within the DBI and the drivers you're using. =head2 Trace Settings Which details are written to the trace output is controlled by a combination of a I<trace level>, an integer from 0 to 15, and a set of I<trace flags> that are either on or off. Together these are known as the I<trace settings> and are stored together in a single integer. For normal use you only need to set the trace level, and generally only to a value between 1 and 4. setings are restored when the called method returns. =head2 Trace Levels Trace I to 15 - As above but with more and more obscure information. Trace level 1 is best for a simple overview of what's happening. Trace level 2 is a good choice for general purpose tracing. Levels 3 and above are best reserved for investigating a specific problem, when you need to see "inside" the driver and DBI. The trace output is detailed and typically very useful. Much of the trace output is formatted using the L</neat> function, so strings in the trace output may be edited and truncated by that function. =head2 Trace Flags Trace I L</parse_trace_flags> and L</parse_trace_flag> methods are used to convert trace flag names into the coresponding integer bit flags. =head2 Enabling Trace The C<$h-E<gt>trace> method sets the trace settings for a handle and C<DBI-E<gt>trace> does the same for the DBI. In addition to the L</trace> method, you can enable the same trace information, and direct the output to a file, by setting the C<DBI_TRACE> environment variable before starting Perl. See L</DBI_TRACE> for more information. Finally, you can set, or get, the trace settings for a handle using the C<TraceLevel> attribute. All of those methods use parse_trace_flags() and so allow you set both the trace level and multiple trace flags by using a string containing the trace level and/or flag names separated by vertical bar ("C<|>") or comma ("C<,>") characters. For example: local $h->{TraceLevel} = "3|SQL|foo"; =head2 Trace Output Initially trace output is written to C<STDERR>. Both the C<$h-E<gt>trace> and C<DBI-E<gt I C<STDERR> and, if the prior trace was openned with $trace_file as a filename, the previous trace file is closed; if $trace_file was a filehandle, the filehandle is B<not> closed. B<NOTE>: If $trace_file is specified as a filehandle, the filehandle should not be closed until all DBI operations are completed, or the application has reset the trace file via another call to C<trace()> that changes the trace file. =head2 Tracing to Layered Filehandles B<NOTE>: =over 4 =item * Tied filehandles are not currently supported, as tie operations are not available to the PerlIO methods used by the DBI. =item * PerlIO layer support requires Perl version 5.8 or higher. =back As of version 5.8, Perl provides the ability to layer various "disciplines" on an open filehandle via the (I<Refer to >L<Perlio::via> Iing #. =head2 Trace Content Many of the values embeded in trace output are formatted using the neat() utility function. This means they may be quoted, sanitized, and possibly truncated if longer than C<$DBI::neat_maxlen>. See L</neat> for more details. =head2 Tracing Tips You can add tracing to your own application code using the L</trace_msg> method. It can sometimes be handy to compare trace files from two different runs of the same script. However using a tool like C L<dbilogstrip> for more information. =head1. =head2 DBI_DSN The DBI_DSN environment variable is used by DBI->connect if you do not specify a data source when you issue the connect. It should have a format such as "dbi:Driver:databasename". =head2. =head2 DBI_AUTOPROXY The DBI_AUTOPROXY environment variable takes a string value that starts "dbi:Proxy:" and is typically followed by "hostname=...;port=...". It is used to alter the behaviour of DBI->connect. For full details, see DBI::Proxy documentation. =head2 DBI_USER The DBI_USER environment variable takes a string value that is used as the user name if the DBI->connect call is given undef (as distinct from an empty string) as the username argument. Be wary of the security implications of using this. =head2 DBI_PASS The DBI_PASS environment variable takes a string value that is used as the password if the DBI->connect call is given undef (as distinct from an empty string) as the password argument. Be extra wary of the security implications of using this. =head2 DBI_DBNAME (obsolete) The DBI_DBNAME environment variable takes a string value that is used only when the obsolescent style of DBI->connect (with driver name as fourth parameter) is used, and when no value is provided for the first (database name) argument. =head2 C<DBI_TRACE> contains an "C<=>" character then what follows it is used as the name of the file to append the trace to. output appended to that file. If the name begins with a number followed by an equal sign (C<=>), L</TRACING> for more information. =head2 PERL_DBI_DEBUG (obsolete) An old variable that should no longer be used; equivalent to DBI_TRACE. =head2 DBI_PROFILE The DBI_PROFILE environment variable can be used to enable profiling of DBI method calls. See L<DBI::Profile> for more information. =head2 DBI_PUREPERL The DBI_PUREPERL environment variable can be used to enable the use of DBI::PurePerl. See L<DBI::PurePerl> for more information. =head1 WARNING AND ERROR MESSAGES =head2 Fatal Errors =over 4 =item Can't call method "prepare" without a package or object reference The C<$dbh> handle you're using to call C<prepare> is probably undefined because the preceding C<connect> failed. You should always check the return status of DBI methods, or use the L</RaiseError> attribute. =item Can't call method "execute" without a package or object reference The C<$sth> handle you're using to call C<execute> is probably undefined because the preceeding C<prepare> failed. You should always check the return status of DBI methods, or use the L</RaiseError> attribute. =item.) =item DBD driver has not implemented the AutoCommit attribute The DBD driver implementation is incomplete. Consult the author. =item Can't [sg]et %s->{%s}: unrecognised attribute You attempted to set or get an unknown attribute of a handle. Make sure you have spelled the attribute name correctly; case is significant (e.g., "Autocommit" is not the same as "AutoCommit"). =back =head1 Pure-Perl DBI A pure-perl emulation of the DBI is included in the distribution for people using pure-perl drivers who, for whatever reason, can't install the compiled DBI. See L<DBI::PurePerl>. =head1 SEE ALSO =head2 Driver and Database Documentation Refer to the documentation for the DBD driver that you are using. Refer to the SQL Language Reference Manual for the database engine that you are using. =head2 For example, for ODBC information on SQLColumns you'd visit: If that URL ceases to work then use the MSDN search facility at: and search for C<SQLColumns returns> using the exact phrase option. The link you want will probably just be called C<SQLColumns> and will be part of the Data Access SDK. And for SQL/CLI standard information on SQLColumns you'd read page 124 of the (very large) SQL/CLI Working Draft available from: =head2 Standards Reference Information. =head2 Books and Articles Programming the Perl DBI, by Alligator Descartes and Tim Bunce. L<> Programming Perl 3rd Ed. by Larry Wall, Tom Christiansen & Jon Orwant. L<> Learning Perl by Randal Schwartz. L<> Details of many other books related to perl can be found at L<> =head2 Perl Modules: =head2 Mailing List The I: =head2 Assorted Related WWW Links The DBI "Home Page": Other DBI related links: Other database related links: Security, especially the "SQL Injection" attack: Commercial and Data Warehouse Links Recommended Perl Programming Links =head2 FAQ See L<> =head1 AUTHORS DBI by Tim Bunce, L<> This pod text by Tim Bunce, J. Douglas Dunlop, Jonathan Leffler and others. Perl by Larry Wall and the C<perl5-porters>. =head1 COPYRIGHT The DBI module is Copyright (c) 1994-2004 Tim Bunce. Ireland. All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. =head1 SUPPORT / WARRANTY The DBI is free Open Source software. IT COMES WITHOUT WARRANTY OF ANY KIND. =head2 Support My consulting company, Data Plan Services, offers annual and multi-annual support contracts for the DBI. These provide sustained support for DBI development, and sustained value for you in return. Contact me for details. =head2 Sponsor Enhancements The DBI Roadmap is available at L<>. =head1 Ingeneering in the UK (L<>)  (L<>) The development of DBD::Gofer and related modules was sponsored by Shopzilla.com (L<>), where I currently work. =head1 CONTRIBUTING As you can see above, many people have contributed to the DBI and drivers in many ways over many years. If you'd like to help then see L<> and L<> If you'd like the DBI to do something new or different then a good way to make that happen is to do it yourself and send me a patch to the source code that shows the changes. (But read "Speak before you patch" below.) =head2 Browsing the source code repository Use (basic) or (more useful) =head2 How to create a patch using Subversion The DBI source code is maintained using Subversion (a replacement for CVS, see L<>). C<trunk>. To keep informed about changes to the source you can send an empty email to svn-commit-modules-dbi C<trunk> directory using: svn diff > foo.patch Read the patch file, as a sanity check, and then email it to dbi-dev@perl.org. =head2 How to create a patch without Subversion Unpack a fresh copy of the distribution: tar xfz DBI-1.40.tar.gz Rename the newly created top level directory: mv DBI-1.40 DBI-1.40.your_foo Edit the contents of DBI-1.40.your_foo/* till it does what you want. Test your changes and then remove all temporary files: make test && make distclean Go back to the directory you originally unpacked the distribution: cd .. Unpack I<another> copy of the original distribution you started with: tar xfz DBI-1.40.tar.gz Then create a patch file by performing a recursive C<diff> on the two top level directories: diff -r -u DBI-1.40 DBI-1.40.your_foo > DBI-1.40.your_foo.patch =head2. =head1 TRANSLATIONS A German translation of this manual (possibly slightly out of date) is available, thanks to O'Reilly, at: Some other translations: - Spanish - Japanese =head1 TRAINING References to DBI related training resources. No recommendation implied. (If you offer professional DBI related training services, please send me your details so I can add them here.) =head1 OTHER RELATED WORK AND PERL MODULES =over 4 =item Apache::DBI by E.Mergl@bawue.de To be used with the Apache daemon together with an embedded Perl interpreter like C<mod_perl>. Establishes a database connection which remains open for the lifetime of the HTTP daemon. This way the CGI connect and disconnect for every database access becomes superfluous. =item SQL Parser See also the L<SQL::Statement> module, SQL parser and engine. =back =cut