<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># $Id: DBI.pm,v 11.13 2002/06/05 22:39:41 timbo Exp $
#
# Copyright (c) 1994-2002  Tim Bunce  Ireland
#
# See COPYRIGHT section in pod text below for usage and distribution rights.
#

require 5.005_03;

BEGIN {
$DBI::VERSION = 1.25; # ==&gt; ALSO update the version in the pod text below!
}

=head1 NAME

DBI - Database independent interface for Perl

=head1 SYNOPSIS

  use DBI;

  @driver_names = DBI-&gt;available_drivers;
  @data_sources = DBI-&gt;data_sources($driver_name, \%attr);

  $dbh = DBI-&gt;connect($data_source, $username, $auth, \%attr);

  $rv  = $dbh-&gt;do($statement);
  $rv  = $dbh-&gt;do($statement, \%attr);
  $rv  = $dbh-&gt;do($statement, \%attr, @bind_values);

  $ary_ref  = $dbh-&gt;selectall_arrayref($statement);
  $hash_ref = $dbh-&gt;selectall_hashref($statement, $key_field);

  $ary_ref = $dbh-&gt;selectcol_arrayref($statement);
  $ary_ref = $dbh-&gt;selectcol_arrayref($statement, \%attr);

  $ary_ref  = $dbh-&gt;selectrow_arrayref($statement);
  @row_ary  = $dbh-&gt;selectrow_array($statement);
  $hash_ref = $dbh-&gt;selectrow_hashref($statement);

  $sth = $dbh-&gt;prepare($statement);
  $sth = $dbh-&gt;prepare_cached($statement);

  $rc = $sth-&gt;bind_param($p_num, $bind_value);
  $rc = $sth-&gt;bind_param($p_num, $bind_value, $bind_type);
  $rc = $sth-&gt;bind_param($p_num, $bind_value, \%attr);

  $rv = $sth-&gt;execute;
  $rv = $sth-&gt;execute(@bind_values);

  $rc = $sth-&gt;bind_param_array($p_num, $bind_values, \%attr);
  $rv = $sth-&gt;execute_array(\%attr);
  $rv = $sth-&gt;execute_array(\%attr, @bind_values);

  $rc = $sth-&gt;bind_col($col_num, \$col_variable);
  $rc = $sth-&gt;bind_columns(@list_of_refs_to_vars_to_bind);

  @row_ary  = $sth-&gt;fetchrow_array;
  $ary_ref  = $sth-&gt;fetchrow_arrayref;
  $hash_ref = $sth-&gt;fetchrow_hashref;

  $ary_ref  = $sth-&gt;fetchall_arrayref;
  $ary_ref  = $sth-&gt;fetchall_arrayref( { ... } );
  $ary_ref  = $sth-&gt;fetchall_arrayref( [ ... ] );

  $hash_ref = $sth-&gt;fetchall_hashref( $key_field );

  $rv  = $sth-&gt;rows;

  $rc  = $dbh-&gt;begin_work;
  $rc  = $dbh-&gt;commit;
  $rc  = $dbh-&gt;rollback;

  $quoted_string = $dbh-&gt;quote($string);

  $rc  = $h-&gt;err;
  $str = $h-&gt;errstr;
  $rv  = $h-&gt;state;

  $rc  = $dbh-&gt;disconnect;

I&lt;This synopsis above only lists the major methods.&gt;


=head2 GETTING HELP

If you have questions about DBI, you can get help from
the I&lt;dbi-users@perl.org&gt; mailing list.
You can subscribe to the list by emailing:

  dbi-users-help@perl.org

Also worth a visit is the DBI home page at:

  http://dbi.perl.org/

Before asking any questions, reread this document, consult the
archives and read the DBI FAQ. The archives are listed
at the end of this document and on the DBI home page.
The FAQ is installed as a L&lt;DBI::FAQ&gt; module so
you can read it by executing C&lt;perldoc DBI::FAQ&gt;.

Please note that Tim Bunce does not maintain the mailing lists or the
web page (generous volunteers do that).  So please don't send mail
directly to him; he just doesn't have the time to answer questions
personally. The I&lt;dbi-users&gt; mailing list has lots of experienced
people who should be able to help you if you need it.

=head2 NOTE

This is the DBI specification that corresponds to the DBI version 1.25
(C&lt;$Date: 2002/06/05 22:39:41 $&gt;).

The DBI specification is evolving at a steady pace, so it's
important to check that you have the latest copy.

The significant user-visible changes in each release are documented
in the L&lt;DBI::Changes&gt; module so you can read them by executing
C&lt;perldoc DBI::Changes&gt;.

Note also that whenever the DBI changes, the drivers take some time to
catch up. Recent versions of the DBI have added new features
(generally marked I&lt;NEW&gt; in the text) that may not yet be supported by the drivers
you use. Talk to the authors of those drivers if you need the new features.

Extensions to the DBI often use the C&lt;DBIx::*&gt; namespace.
See L&lt;/Naming Conventions and Name Space&gt; and:

  http://search.cpan.org/search?mode=module&amp;query=DBIx%3A%3A

=cut

# The POD text continues at the end of the file.


{
package DBI;

my $Revision = substr(q$Revision: 11.13 $, 10);

use Carp;
use DynaLoader ();
use Exporter ();

BEGIN {
@ISA = qw(Exporter DynaLoader);

# Make some utility functions available if asked for
@EXPORT    = ();		    # we export nothing by default
@EXPORT_OK = qw(%DBI %DBI_methods hash); # also populated by export_ok_tags:
%EXPORT_TAGS = (
   sql_types =&gt; [ qw(
	SQL_GUID
	SQL_WLONGVARCHAR
	SQL_WVARCHAR
	SQL_WCHAR
	SQL_BIT
	SQL_TINYINT
	SQL_LONGVARBINARY
	SQL_VARBINARY
	SQL_BINARY
	SQL_LONGVARCHAR
	SQL_UNKNOWN_TYPE
	SQL_ALL_TYPES
	SQL_CHAR
	SQL_NUMERIC
	SQL_DECIMAL
	SQL_INTEGER
	SQL_SMALLINT
	SQL_FLOAT
	SQL_REAL
	SQL_DOUBLE
	SQL_DATETIME
	SQL_DATE
	SQL_INTERVAL
	SQL_TIME
	SQL_TIMESTAMP
	SQL_VARCHAR
	SQL_BOOLEAN
	SQL_UDT
	SQL_UDT_LOCATOR
	SQL_ROW
	SQL_REF
	SQL_BLOB
	SQL_BLOB_LOCATOR
	SQL_CLOB
	SQL_CLOB_LOCATOR
	SQL_ARRAY
	SQL_ARRAY_LOCATOR
	SQL_MULTISET
	SQL_MULTISET_LOCATOR
	SQL_TYPE_DATE
	SQL_TYPE_TIME
	SQL_TYPE_TIMESTAMP
	SQL_TYPE_TIME_WITH_TIMEZONE
	SQL_TYPE_TIMESTAMP_WITH_TIMEZONE
	SQL_INTERVAL_YEAR
	SQL_INTERVAL_MONTH
	SQL_INTERVAL_DAY
	SQL_INTERVAL_HOUR
	SQL_INTERVAL_MINUTE
	SQL_INTERVAL_SECOND
	SQL_INTERVAL_YEAR_TO_MONTH
	SQL_INTERVAL_DAY_TO_HOUR
	SQL_INTERVAL_DAY_TO_MINUTE
	SQL_INTERVAL_DAY_TO_SECOND
	SQL_INTERVAL_HOUR_TO_MINUTE
	SQL_INTERVAL_HOUR_TO_SECOND
	SQL_INTERVAL_MINUTE_TO_SECOND
   ) ],
   utils     =&gt; [ qw(
	neat neat_list dump_results looks_like_number
   ) ],
   profile   =&gt; [ qw(
	dbi_profile dbi_profile_merge
   ) ],
);

$DBI::dbi_debug = $ENV{DBI_TRACE} || $ENV{PERL_DBI_DEBUG} || 0;

# If you get an error here like "Can't find loadable object ..."
# then you haven't installed the DBI correctly. Read the README
# then install it again.
if ( $ENV{DBI_PUREPERL} ) {
    eval { bootstrap DBI } if       $ENV{DBI_PUREPERL} == 1;
    require DBI::PurePerl  if $@ or $ENV{DBI_PUREPERL} &gt;= 2;
    $DBI::PurePerl ||= 0; # just to silence "only used once" warnings
}
else {
    bootstrap DBI;
}

$EXPORT_TAGS{preparse_flags} = [ grep { /^DBIpp_\w\w_/ } keys %{__PACKAGE__."::"} ];

Exporter::export_ok_tags(keys %EXPORT_TAGS);

}

*trace_msg = \&amp;DBD::_::common::trace_msg;
*set_err   = \&amp;DBD::_::common::set_err;

use strict;

my $connect_via = "connect";

# check if user wants a persistent database connection ( Apache + mod_perl )
if ($INC{'Apache/DBI.pm'} &amp;&amp; substr($ENV{GATEWAY_INTERFACE}||'',0,8) eq 'CGI-Perl') {
    $connect_via = "Apache::DBI::connect";
    DBI-&gt;trace_msg("DBI connect via $INC{'Apache/DBI.pm'}\n");
}


if ($DBI::dbi_debug) {
    @DBI::dbi_debug = ($DBI::dbi_debug);

    if ($DBI::dbi_debug !~ m/^\d$/) {
	# dbi_debug is a file name to write trace log to.
	# Default level is 2 but if file starts with "digits=" then the
	# digits (and equals) are stripped off and used as the level
	unshift @DBI::dbi_debug, 2;
	@DBI::dbi_debug = ($1,$2) if $DBI::dbi_debug =~ m/^(\d+)=(.*)/;
	$DBI::dbi_debug = $DBI::dbi_debug[0];
    }
    DBI-&gt;trace(@DBI::dbi_debug);
}

%DBI::installed_drh = ();  # maps driver names to installed driver handles


# Setup special DBI dynamic variables. See DBI::var::FETCH for details.
# These are dynamically associated with the last handle used.
tie $DBI::err,    'DBI::var', '*err';    # special case: referenced via IHA list
tie $DBI::state,  'DBI::var', '"state';  # special case: referenced via IHA list
tie $DBI::lasth,  'DBI::var', '!lasth';  # special case: return boolean
tie $DBI::errstr, 'DBI::var', '&amp;errstr'; # call &amp;errstr in last used pkg
tie $DBI::rows,   'DBI::var', '&amp;rows';   # call &amp;rows   in last used pkg
sub DBI::var::TIESCALAR{ my $var = $_[1]; bless \$var, 'DBI::var'; }
sub DBI::var::STORE    { Carp::croak("Can't modify \$DBI::${$_[0]} special variable") }
sub DBI::var::DESTROY  { }

{   package DBI::DBI_tie;	# used to catch DBI-&gt;{Attrib} mistake
    sub TIEHASH { bless {} }
    sub STORE   { Carp::carp("DBI-&gt;{$_[1]} is invalid syntax (you probably want \$h-&gt;{$_[1]})");}
    *FETCH = \&amp;STORE;
}
tie %DBI::DBI =&gt; 'DBI::DBI_tie';


# --- Dynamically create the DBI Standard Interface

my $std = undef;
my $keeperr = { O=&gt;0x04 };

my @TieHash_IF = (	# Generic Tied Hash Interface
	'STORE'   =&gt; { O=&gt;0x10 },
	'FETCH'   =&gt; $keeperr,
	'FIRSTKEY'=&gt; $keeperr,
	'NEXTKEY' =&gt; $keeperr,
	'EXISTS'  =&gt; $keeperr,
	'CLEAR'   =&gt; $keeperr,
	'DESTROY' =&gt; undef,	# hardwired internally
);
my @Common_IF = (	# Interface functions common to all DBI classes
	func    =&gt;	{				O=&gt;0x06	},
	event   =&gt;	{ U =&gt;[2,0,'$type, @args'],	O=&gt;0x04 },
	'trace' =&gt;	{ U =&gt;[1,3,'[$trace_level, [$filename]]'],	O=&gt;0x04 },
	trace_msg =&gt;	{ U =&gt;[2,3,'$message_text [, $min_level ]' ],	O=&gt;0x04, T=&gt;8 },
	debug   =&gt;	{ U =&gt;[1,2,'[$debug_level]'],	O=&gt;0x04 }, # old name for trace
	private_data =&gt;	{ U =&gt;[1,1],			O=&gt;0x04 },
	err     =&gt;	$keeperr,
	errstr  =&gt;	$keeperr,
	state   =&gt;	{ U =&gt;[1,1], O=&gt;0x04 },
	set_err =&gt;	{ },
	_not_impl =&gt; $std,
);

%DBI::DBI_methods = ( # Define the DBI interface methods per class:

    dr =&gt; {		# Database Driver Interface
	@Common_IF,
	@TieHash_IF,
	'connect'  =&gt;	{ U =&gt;[1,5,'[$db [,$user [,$passwd [,\%attr]]]]'], H=&gt;3 },
	'connect_cached'=&gt;{U=&gt;[1,5,'[$db [,$user [,$passwd [,\%attr]]]]'], H=&gt;3 },
	'disconnect_all'=&gt;{ U =&gt;[1,1] },
	data_sources =&gt; { U =&gt;[1,2,'[\%attr]' ] },
	default_user =&gt; { U =&gt;[3,4,'$user, $pass [, \%attr]' ] },
    },
    db =&gt; {		# Database Session Class Interface
	@Common_IF,
	@TieHash_IF,
	connected   	=&gt; { O=&gt;0x0100 },
	begin_work   	=&gt; { U =&gt;[1,2,'[ \%attr ]'] },
	commit     	=&gt; { U =&gt;[1,1], O=&gt;0x0080 },
	rollback   	=&gt; { U =&gt;[1,1], O=&gt;0x0080 },
	'do'       	=&gt; { U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	preparse    	=&gt; {  }, # XXX
	prepare    	=&gt; { U =&gt;[2,3,'$statement [, \%attr]'] },
	prepare_cached	=&gt; { U =&gt;[2,4,'$statement [, \%attr [, $allow_active ] ]'] },
	selectrow_array	=&gt; { U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	selectrow_arrayref=&gt;{U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	selectrow_hashref=&gt;{ U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	selectall_arrayref=&gt;{U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	selectall_hashref=&gt;{ U =&gt;[3,0,'$statement, $keyfield [, \%attr [, @bind_params ] ]'] },
	selectcol_arrayref=&gt;{U =&gt;[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
	handler    	=&gt; { U =&gt;[2,2,'\&amp;handler'] },
	ping       	=&gt; { U =&gt;[1,1], O=&gt;0x04 },
	disconnect 	=&gt; { U =&gt;[1,1] },
	quote      	=&gt; { U =&gt;[2,3, '$string [, $data_type ]' ], O=&gt;0x30 },
	quote_identifier=&gt; { U =&gt;[2,5, '$name [, ...]' ],	    O=&gt;0x30 },
	rows       	=&gt; $keeperr,

	tables          =&gt; { U =&gt;[1,6,'$catalog, $schema, $table, $type [, \%attr ]' ] },
	table_info      =&gt; { U =&gt;[1,6,'$catalog, $schema, $table, $type [, \%attr ]' ] },
	column_info     =&gt; { U =&gt;[1,6,'$catalog, $schema, $table, $column [, \%attr ]' ] },
	primary_key_info=&gt; { U =&gt;[4,5,'$catalog, $schema, $table [, \%attr ]' ] },
	primary_key     =&gt; { U =&gt;[4,5,'$catalog, $schema, $table [, \%attr ]' ] },
	foreign_key_info=&gt; { U =&gt;[1,7,'$pk_catalog, $pk_schema, $pk_table, $fk_catalog, $fk_schema, $fk_table' ] },
	type_info_all	=&gt; { U =&gt;[1,1] },
	type_info	=&gt; { U =&gt;[1,2,'$data_type'] },
	get_info	=&gt; { U =&gt;[2,2,'$info_type'] },
    },
    st =&gt; {		# Statement Class Interface
	@Common_IF,
	@TieHash_IF,
	bind_col	=&gt; { U =&gt;[3,4,'$column, \\$var [, \%attr]'] },
	bind_columns	=&gt; { U =&gt;[2,0,'\\$var1 [, \\$var2, ...]'] },
	bind_param	=&gt; { U =&gt;[3,4,'$parameter, $var [, \%attr]'] },
	bind_param_inout=&gt; { U =&gt;[4,5,'$parameter, \\$var, $maxlen, [, \%attr]'] },
	execute		=&gt; { U =&gt;[1,0,'[@args]'], O=&gt;0x40 },

	bind_param_array  =&gt; { U =&gt;[3,4,'$parameter, $var [, \%attr]'] },
	bind_param_inout_array =&gt; { U =&gt;[4,5,'$parameter, \\@var, $maxlen, [, \%attr]'] },
	execute_array     =&gt; { U =&gt;[2,0,'\\%attribs [, @args]'] },

	fetch    	  =&gt; undef, # alias for fetchrow_arrayref
	fetchrow_arrayref =&gt; undef,
	fetchrow_hashref  =&gt; undef,
	fetchrow_array    =&gt; undef,
	fetchrow   	  =&gt; undef, # old alias for fetchrow_array

	fetchall_arrayref =&gt; { U =&gt;[1,2] },
	fetchall_hashref  =&gt; { U =&gt;[2,2] },

	blob_read  =&gt;	{ U =&gt;[4,5,'$field, $offset, $len [, \\$buf [, $bufoffset]]'] },
	blob_copy_to_file =&gt; { U =&gt;[3,3,'$field, $filename_or_handleref'] },
	dump_results =&gt; { U =&gt;[1,5,'$maxfieldlen, $linesep, $fieldsep, $filehandle'] },
	more_results =&gt; { U =&gt;[1,1] },
	finish     =&gt; 	{ U =&gt;[1,1] },
	cancel     =&gt; 	{ U =&gt;[1,1] },
	rows       =&gt;	$keeperr,

	_get_fbav	=&gt; undef,
	_set_fbav	=&gt; { T=&gt;6 },
    },
);

my($class, $method);
foreach $class (keys %DBI::DBI_methods){
    my %pkgif = %{ $DBI::DBI_methods{$class} };
    foreach $method (keys %pkgif){
	DBI-&gt;_install_method("DBI::${class}::$method", 'DBI.pm',
			$pkgif{$method});
    }
}

# End of init code


END {
    return unless defined &amp;DBI::trace_msg; # return unless bootstrap'd ok
    local ($!,$?);
    DBI-&gt;trace_msg("    -- DBI::END\n", 2);
    # Let drivers know why we are calling disconnect_all:
    $DBI::PERL_ENDING = $DBI::PERL_ENDING = 1;	# avoid typo warning
    DBI-&gt;disconnect_all() if %DBI::installed_drh;
}



# --- The DBI-&gt;connect Front Door methods

sub connect_cached {
    # XXX we expect Apache::DBI users to still call connect()
    my ($class, $dsn, $user, $pass, $attr) = @_;
    ($attr ||= {})-&gt;{dbi_connect_method} = 'connect_cached';
    return $class-&gt;connect($dsn, $user, $pass, $attr);
}

sub connect {
    my $class = shift;
    my($dsn, $user, $pass, $attr, $old_driver) = @_;
    my $driver;
    my $dbh;

    # switch $old_driver&lt;-&gt;$attr if called in old style
    ($old_driver, $attr) = ($attr, $old_driver) if $attr and !ref($attr);

    my $connect_meth = (ref $attr) ? $attr-&gt;{dbi_connect_method} : undef;
    $connect_meth ||= $connect_via;	# fallback to default

    $dsn ||= $ENV{DBI_DSN} || $ENV{DBI_DBNAME} || '' unless $old_driver;

    if ($DBI::dbi_debug) {
	local $^W = 0;
	pop @_ if $connect_meth ne 'connect';
	my @args = @_; $args[2] = '****'; # hide password
	DBI-&gt;trace_msg("    -&gt; $class-&gt;$connect_meth(".join(", ",@args).")\n");
    }
    Carp::croak('Usage: $class-&gt;connect([$dsn [,$user [,$passwd [,\%attr]]]])')
	if (ref $old_driver or ($attr and not ref $attr) or ref $pass);

    # extract dbi:driver prefix from $dsn into $1
    $dsn =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i
			or '' =~ /()/; # ensure $1 etc are empty if match fails
    my $driver_attrib_spec = $2;

    # Set $driver. Old style driver, if specified, overrides new dsn style.
    $driver = $old_driver || $1 || $ENV{DBI_DRIVER}
	or Carp::croak("Can't connect(@_), no database driver specified "
		."and DBI_DSN env var not set");

    if ($ENV{DBI_AUTOPROXY} &amp;&amp; $driver ne 'Proxy' &amp;&amp; $driver ne 'Switch') {
	$dsn = "$ENV{DBI_AUTOPROXY};dsn=dbi:$driver:$dsn";
	$driver = 'Proxy';
	DBI-&gt;trace_msg("       DBI_AUTOPROXY: dbi:$driver:$dsn\n");
    }

    my %attr;	# take a copy we can delete from
    if ($old_driver) {
	%attr = %$attr if $attr;
    }
    else {		# new-style connect so new default semantics
	%attr = (
	    PrintError =&gt; 1,
	    AutoCommit =&gt; 1,
	    ref $attr           ? %$attr : (),
	    $driver_attrib_spec ? (split /\s*=&gt;?\s*|\s*,\s*/, $driver_attrib_spec) : (),
	);
	# XXX to be enabled for DBI v2.0?
	#Carp::carp("AutoCommit attribute not specified in $class-&gt;connect")
	#    if $^W &amp;&amp; !defined($attr-&gt;{AutoCommit});
    }
    $attr = \%attr;	# now set $attr at our local copy

    my $drh = $DBI::installed_drh{$driver} || $class-&gt;install_driver($driver)
	or die "panic: $class-&gt;install_driver($driver) failed";

    ($user, $pass) = $drh-&gt;default_user($user, $pass, $attr)
	if !(defined $user &amp;&amp; defined $pass);

    unless ($dbh = $drh-&gt;$connect_meth($dsn, $user, $pass, $attr)) {
	my $msg = "$class-&gt;connect($dsn) failed: ".$drh-&gt;errstr;
	if (%attr) {
	    # XXX add $attr{HandleError} logic here?
	    Carp::croak($msg) if $attr-&gt;{RaiseError};
	    Carp::carp ($msg) if $attr-&gt;{PrintError};
	}
	DBI-&gt;trace_msg("       $msg\n");
	$! = 0; # for the daft people who do DBI-&gt;connect(...) || die "$!";
	return undef;
    }


    # handle basic RootClass subclassing:
    my $rebless_class = $attr-&gt;{RootClass} || ($class ne 'DBI' ? $class : '');
    if ($rebless_class) {
	if ($attr-&gt;{RootClass}) {	# explicit attribute (rather than static call)
	    delete $attr-&gt;{RootClass};
	    DBI::_load_module($rebless_class);
	}
        no strict 'refs';
        unless (@{"$rebless_class\::db::ISA"}) {
            Carp::carp("DBI subclass '$rebless_class\::db' isn't setup, ignored");
            $rebless_class = undef;
            $class = 'DBI';
        }
        else {
            $dbh-&gt;{RootClass} = $rebless_class; # $dbh-&gt;STORE called via plain DBI::db
            DBI::_set_isa([$rebless_class], 'DBI');     # sets up both '::db' and '::st'
            DBI::_rebless($dbh, $rebless_class);        # appends '::db'
        }
    }


    if (%$attr) {

	DBI::_rebless_dbtype_subclass($dbh, $rebless_class||$class, delete $attr-&gt;{DbTypeSubclass}, $attr)
	    if $attr-&gt;{DbTypeSubclass};

	my $a;
	foreach $a (qw(RaiseError PrintError AutoCommit)) { # do these first
	    next unless  exists $attr-&gt;{$a};
	    $dbh-&gt;{$a} = delete $attr-&gt;{$a};
	}
	foreach $a (keys %$attr) {
	    $dbh-&gt;{$a} = $attr-&gt;{$a};
	}
    }

    # if we've been subclassed then let the subclass know that we're connected
    $dbh-&gt;connected($dsn, $user, $pass, \%attr) if ref $dbh ne 'DBI::db';

    DBI-&gt;trace_msg("    &lt;- connect= $dbh\n") if $DBI::dbi_debug;

    return $dbh;
}


sub disconnect_all {
    foreach(keys %DBI::installed_drh){
	my $drh = $DBI::installed_drh{$_};
	next unless ref $drh;	# avoid problems on premature death
	$drh-&gt;disconnect_all();
    }
}


sub disconnect {	# a regular beginners bug
    Carp::croak("DBI-&gt;disconnect is not a DBI method. Read the DBI manual.");
}


sub install_driver {		# croaks on failure
    my $class = shift;
    my($driver, $attr) = @_;
    my $drh;

    $driver ||= $ENV{DBI_DRIVER} || '';

    # allow driver to be specified as a 'dbi:driver:' string
    $driver = $1 if $driver =~ s/^DBI:(.*?)://i;

    Carp::croak("usage: $class-&gt;install_driver(\$driver [, \%attr])")
		unless ($driver and @_&lt;=3);

    # already installed
    return $drh if $drh = $DBI::installed_drh{$driver};

    DBI-&gt;trace_msg("    -&gt; $class-&gt;install_driver($driver"
			.") for $^O perl=$] pid=$$ ruid=$&lt; euid=$&gt;\n")
	if $DBI::dbi_debug;

    # --- load the code
    my $driver_class = "DBD::$driver";
    eval "package DBI::_firesafe; require $driver_class";
    if ($@) {
	my $err = $@;
	my $advice = "";
	if ($err =~ /Can't find loadable object/) {
	    $advice = "Perhaps DBD::$driver was statically linked into a new perl binary."
		 ."\nIn which case you need to use that new perl binary."
		 ."\nOr perhaps only the .pm file was installed but not the shared object file."
	}
	elsif ($err =~ /Can't locate.*?DBD\/$driver\.pm in \@INC/) {
	    my @drv = DBI-&gt;available_drivers(1);
	    $advice = "Perhaps the DBD::$driver perl module hasn't been fully installed,\n"
		     ."or perhaps the capitalisation of '$driver' isn't right.\n"
		     ."Available drivers: ".join(", ", @drv).".";
	}
	elsif ($err =~ /Can't load .*? for module DBD::/) {
	    $advice = "Perhaps a required shared library or dll isn't installed where expected";
	}
	elsif ($err =~ /Can't locate .*? in \@INC/) {
	    $advice = "Perhaps a module that DBD::$driver requires hasn't been fully installed";
	}
	Carp::croak("install_driver($driver) failed: $err$advice\n");
    }
    if ($DBI::dbi_debug) {
	no strict 'refs';
	(my $driver_file = $driver_class) =~ s/::/\//g;
	my $dbd_ver = ${"$driver_class\::VERSION"} || "undef";
	DBI-&gt;trace_msg("       install_driver: $driver_class version $dbd_ver"
		." loaded from $INC{qq($driver_file.pm)}\n");
    }

    # --- do some behind-the-scenes checks and setups on the driver
    _setup_driver($driver_class);

    # --- run the driver function
    $drh = eval { $driver_class-&gt;driver($attr || {}) };
    unless ($drh &amp;&amp; ref $drh &amp;&amp; !$@) {
	my $advice = "";
	# catch people on case in-sensitive systems using the wrong case
	$advice = "\nPerhaps the capitalisation of DBD '$driver' isn't right."
		if $@ =~ /locate object method/;
	croak("$driver_class initialisation failed: $@$advice");
    }

    $DBI::installed_drh{$driver} = $drh;
    DBI-&gt;trace_msg("    &lt;- install_driver= $drh\n") if $DBI::dbi_debug;
    $drh;
}

*driver = \&amp;install_driver;	# currently an alias, may change


sub _setup_driver {
    my $driver_class = shift;
    my $type;
    foreach $type (qw(dr db st)){
	my $class = $driver_class."::$type";
	no strict 'refs';
	push @{"${class}::ISA"},     "DBD::_::$type";
	push @{"${class}_mem::ISA"}, "DBD::_mem::$type";
    }
}


sub _rebless {
    my $dbh = shift;
    my ($outer, $inner) = DBI::_handles($dbh);
    my $class = shift(@_).'::db';
    bless $inner =&gt; $class;
    bless $outer =&gt; $class; # outer last for return
}


sub _set_isa {
    my ($classes, $topclass) = @_;
    my $trace = DBI-&gt;trace_msg("       _set_isa([@$classes])\n");
    foreach my $suffix ('::db','::st') {
	my $previous = $topclass || 'DBI'; # trees are rooted here
	foreach my $class (@$classes) {
	    my $base_class = $previous.$suffix;
	    my $sub_class  = $class.$suffix;
	    my $sub_class_isa  = "${sub_class}::ISA";
	    no strict 'refs';
	    if (@$sub_class_isa) {
		DBI-&gt;trace_msg("       $sub_class_isa skipped (already set to @$sub_class_isa)\n")
		    if $trace;
	    }
	    else {
		@$sub_class_isa = ($base_class) unless @$sub_class_isa;
		DBI-&gt;trace_msg("       $sub_class_isa = $base_class\n")
		    if $trace;
	    }
	    $previous = $class;
	}
    }
}


sub _rebless_dbtype_subclass {
    my ($dbh, $rootclass, $DbTypeSubclass, $attr) = @_;
    # determine the db type names for class hierarchy
    my @hierarchy = DBI::_dbtype_names($dbh, $DbTypeSubclass, $attr);
    # add the rootclass prefix to each ('DBI::' or 'MyDBI::' etc)
    $_ = $rootclass.'::'.$_ foreach (@hierarchy);
    # load the modules from the 'top down'
    DBI::_load_module($_) foreach (reverse @hierarchy);
    # setup class hierarchy if needed, does both '::db' and '::st'
    DBI::_set_isa(\@hierarchy, $rootclass);
    # finally bless the handle into the subclass
    DBI::_rebless($dbh, $hierarchy[0]);
}


sub _dbtype_names { # list dbtypes for hierarchy, ie Informix=&gt;ADO=&gt;ODBC
    my ($dbh, $DbTypeSubclass, $attr) = @_;

    if ($DbTypeSubclass &amp;&amp; $DbTypeSubclass ne '1' &amp;&amp; ref $DbTypeSubclass ne 'CODE') {
	# treat $DbTypeSubclass as a comma separated list of names
	my @dbtypes = split /\s*,\s*/, $DbTypeSubclass;
	$dbh-&gt;trace_msg("    DbTypeSubclass($DbTypeSubclass)=@dbtypes (explicit)\n");
	return @dbtypes;
    }

    # XXX will call $dbh-&gt;get_info(17) (=SQL_DBMS_NAME) in future?

    my $driver = $dbh-&gt;{Driver}-&gt;{Name};
    if ( $driver eq 'Proxy' ) {
        # XXX Looking into the internals of DBD::Proxy is questionable!
        ($driver) = $dbh-&gt;{proxy_client}-&gt;{application} =~ /^DBI:(.+?):/i
		or die "Can't determine driver name from proxy";
    }

    my @dbtypes = (ucfirst($driver));
    if ($driver eq 'ODBC' || $driver eq 'ADO') {
	# XXX will move these out and make extensible later:
	my $_dbtype_name_regexp = 'Oracle'; # eg 'Oracle|Foo|Bar'
	my %_dbtype_name_map = (
	     'Microsoft SQL Server'	=&gt; 'MSSQL',
	     'SQL Server'		=&gt; 'Sybase',
	     'Adaptive Server Anywhere'	=&gt; 'ASAny',
	     'ADABAS D'			=&gt; 'AdabasD',
	);

        my $name;
	$name = $dbh-&gt;func(17, 'GetInfo') # SQL_DBMS_NAME
		if $driver eq 'ODBC';
	$name = $dbh-&gt;{ado_conn}-&gt;Properties-&gt;Item('DBMS Name')-&gt;Value
		if $driver eq 'ADO';
	die "Can't determine driver name! ($DBI::errstr)\n"
		unless $name;

	my $dbtype;
        if ($_dbtype_name_map{$name}) {
            $dbtype = $_dbtype_name_map{$name};
        }
	else {
	    if ($name =~ /($_dbtype_name_regexp)/) {
		$dbtype = lc($1);
	    }
	    else { # generic mangling for other names:
		$dbtype = lc($name);
	    }
	    $dbtype =~ s/\b(\w)/\U$1/g;
	    $dbtype =~ s/\W+/_/g;
	}
	# add ODBC 'behind' ADO
	push    @dbtypes, 'ODBC' if $driver eq 'ADO';
	# add discovered dbtype in front of ADO/ODBC
	unshift @dbtypes, $dbtype;
    }
    @dbtypes = &amp;$DbTypeSubclass($dbh, \@dbtypes)
	if (ref $DbTypeSubclass eq 'CODE');
    $dbh-&gt;trace_msg("    DbTypeSubclass($DbTypeSubclass)=@dbtypes\n");
    return @dbtypes;
}

sub _load_module {
    (my $module = shift) =~ s!::!/!g;
    eval {
        require $module.'.pm';
    };
    return 1 unless $@;
    return 0 if $@ =~ /^\b\@INC\b/;
    die; # propagate $@;
}


sub init_rootclass {	# deprecated
    return 1;
}


*internal = \&amp;DBD::Switch::dr::driver;


sub available_drivers {
    my($quiet) = @_;
    my(@drivers, $d, $f);
    local(*DBI::DIR, $@);
    my(%seen_dir, %seen_dbd);
    my $haveFileSpec = eval { require File::Spec };
    foreach $d (@INC){
	chomp($d); # Perl 5 beta 3 bug in #!./perl -Ilib from Test::Harness
	my $dbd_dir =
	    ($haveFileSpec ? File::Spec-&gt;catdir($d, 'DBD') : "$d/DBD");
	next unless -d $dbd_dir;
	next if $seen_dir{$d};
	$seen_dir{$d} = 1;
	# XXX we have a problem here with case insensitive file systems
	# XXX since we can't tell what case must be used when loading.
	opendir(DBI::DIR, $dbd_dir) || Carp::carp "opendir $dbd_dir: $!\n";
	foreach $f (readdir(DBI::DIR)){
	    next unless $f =~ s/\.pm$//;
	    next if $f eq 'NullP' || $f eq 'Sponge';
	    if ($seen_dbd{$f}){
		Carp::carp "DBD::$f in $d is hidden by DBD::$f in $seen_dbd{$f}\n"
		    unless $quiet;
            } else {
		push(@drivers, $f);
	    }
	    $seen_dbd{$f} = $d;
	}
	closedir(DBI::DIR);
    }
    return sort @drivers;
}

sub data_sources {
    my ($class, $driver, @attr) = @_;
    my $drh = $class-&gt;install_driver($driver);
    my @ds = $drh-&gt;data_sources(@attr);
    return @ds;
}

sub neat_list {
    my ($listref, $maxlen, $sep) = @_;
    $maxlen = 0 unless defined $maxlen;	# 0 == use internal default
    $sep = ", " unless defined $sep;
    join($sep, map { neat($_,$maxlen) } @$listref);
}


sub dump_results {	# also aliased as a method in DBD::_::st
    my ($sth, $maxlen, $lsep, $fsep, $fh) = @_;
    return 0 unless $sth;
    $maxlen ||= 35;
    $lsep   ||= "\n";
    $fh ||= \*STDOUT;
    my $rows = 0;
    my $ref;
    while($ref = $sth-&gt;fetch) {
	print $fh $lsep if $rows++ and $lsep;
	my $str = neat_list($ref,$maxlen,$fsep);
	print $fh $str;	# done on two lines to avoid 5.003 errors
    }
    print $fh "\n$rows rows".($DBI::err ? " ($DBI::err: $DBI::errstr)" : "")."\n";
    $rows;
}



sub connect_test_perf {
    my($class, $dsn,$dbuser,$dbpass, $attr) = @_;
	croak("connect_test_perf needs hash ref as fourth arg") unless ref $attr;
    # these are non standard attributes just for this special method
    my $loops ||= $attr-&gt;{dbi_loops} || 5;
    my $par   ||= $attr-&gt;{dbi_par}   || 1;	# parallelism
    my $verb  ||= $attr-&gt;{dbi_verb}  || 1;
    print "$dsn: testing $loops sets of $par connections:\n";
    require Benchmark;
    require "FileHandle.pm";	# don't let toke.c create empty FileHandle package
    $| = 1;
    my $t0 = new Benchmark;		# not currently used
    my $drh = $class-&gt;install_driver($dsn) or Carp::croak("Can't install $dsn driver\n");
    my $t1 = new Benchmark;
    my $loop;
    for $loop (1..$loops) {
	my @cons;
	print "Connecting... " if $verb;
	for (1..$par) {
	    print "$_ ";
	    push @cons, ($drh-&gt;connect($dsn,$dbuser,$dbpass)
		    or Carp::croak("Can't connect # $_: $DBI::errstr\n"));
	}
	print "\nDisconnecting...\n" if $verb;
	for (@cons) {
	    $_-&gt;disconnect or warn "bad disconnect $DBI::errstr"
	}
    }
    my $t2 = new Benchmark;
    my $td = Benchmark::timediff($t2, $t1);
    printf "Made %2d connections in %s\n", $loops*$par, Benchmark::timestr($td);
	print "\n";
    return $td;
}


# Help people doing DBI-&gt;errstr, might even document it one day
# XXX probably best moved to cheaper XS code
sub err    { $DBI::err    }
sub errstr { $DBI::errstr }


# --- Private Internal Function for Creating New DBI Handles

sub _new_handle {
    my ($class, $parent, $attr, $imp_data, $imp_class) = @_;

    Carp::croak('Usage: DBI::_new_handle'
	    .'($class_name, parent_handle, \%attr, $imp_data)'."\n"
	    .'got: ('.join(", ",$class, $parent, $attr, $imp_data).")\n")
	unless (@_ == 5	and (!$parent or ref $parent)
			and ref $attr eq 'HASH'
			and $imp_class);

    $attr-&gt;{ImplementorClass} = $imp_class
	or Carp::croak("_new_handle($class): 'ImplementorClass' attribute not given");

    DBI-&gt;trace_msg("    New $class (for $imp_class, parent=$parent, id=".($imp_data||'').")\n")
	if $DBI::dbi_debug &gt;= 3;

    # This is how we create a DBI style Object:
    my (%hash, $i, $h);
    $i = tie    %hash, $class, $attr;  # ref to inner hash (for driver)
    $h = bless \%hash, $class;         # ref to outer hash (for application)
    # The above tie and bless may migrate down into _setup_handle()...
    # Now add magic so DBI method dispatch works
    DBI::_setup_handle($h, $imp_class, $parent, $imp_data);

    return $h unless wantarray;
    ($h, $i);
}
# XXX minimum constructors for the tie's (alias to XS version)
sub DBI::st::TIEHASH { bless $_[1] =&gt; $_[0] };
*DBI::dr::TIEHASH = \&amp;DBI::st::TIEHASH;
*DBI::db::TIEHASH = \&amp;DBI::st::TIEHASH;


# These three special constructors are called by the drivers
# The way they are called is likely to change.

my $profile;

sub _new_drh {	# called by DBD::&lt;drivername&gt;::driver()
    my ($class, $initial_attr, $imp_data) = @_;
    # Provide default storage for State,Err and Errstr.
    # Note that these are shared by all child handles by default! XXX
    # State must be undef to get automatic faking in DBI::var::FETCH
    my ($h_state_store, $h_err_store, $h_errstr_store) = (undef, 0, '');
    my $attr = {
	# these attributes get copied down to child handles by default
	'Handlers'	=&gt; [],
	'State'		=&gt; \$h_state_store,  # Holder for DBI::state
	'Err'		=&gt; \$h_err_store,    # Holder for DBI::err
	'Errstr'	=&gt; \$h_errstr_store, # Holder for DBI::errstr
	'Debug' 	=&gt; 0,
	FetchHashKeyName=&gt; 'NAME',
	%$initial_attr,
    };
    my ($h, $i) = _new_handle('DBI::dr', '', $attr, $imp_data, $class);

    # XXX DBI_PROFILE unless DBI::PurePerl because for some reason
    # it kills the t/zz_*_pp.t tests (they silently exit early)
    if ($ENV{DBI_PROFILE} &amp;&amp; !$DBI::PurePerl) {
	# The profile object created here when the first driver is loaded
	# is shared by all drivers so we end up with just one set of profile
	# data and thus the 'total time in DBI' is really the true total.
	if (!$profile) {	# first time
	    $h-&gt;{Profile} = $ENV{DBI_PROFILE};
	    $profile = $h-&gt;{Profile};
	}
	else {
	    $h-&gt;{Profile} = $profile;
	}
    }
    return $h unless wantarray;
    ($h, $i);
}

sub _new_dbh {	# called by DBD::&lt;drivername&gt;::dr::connect()
    my ($drh, $attr, $imp_data) = @_;
    my $imp_class = $drh-&gt;{ImplementorClass}
	or Carp::croak("DBI _new_dbh: $drh has no ImplementorClass");
    substr($imp_class,-4,4) = '::db';
    my $app_class = ref $drh;
    substr($app_class,-4,4) = '::db';
    _new_handle($app_class, $drh, $attr||{}, $imp_data, $imp_class);
}

sub _new_sth {	# called by DBD::&lt;drivername&gt;::db::prepare)
    my ($dbh, $attr, $imp_data) = @_;
    my $imp_class = $dbh-&gt;{ImplementorClass}
	or Carp::croak("DBI _new_sth: $dbh has no ImplementorClass");
    substr($imp_class,-4,4) = '::st';
    my $app_class = ref $dbh;
    substr($app_class,-4,4) = '::st';
    _new_handle($app_class, $dbh, $attr, $imp_data, $imp_class);
}


} # end of DBI package scope



# --------------------------------------------------------------------
# === The internal DBI Switch pseudo 'driver' class ===

{   package DBD::Switch::dr;
    DBI::_setup_driver('DBD::Switch');	# sets up @ISA
    require Carp;

    $imp_data_size = 0;
    $imp_data_size = 0;	# avoid typo warning
    $err = 0;

    sub driver {
	return $drh if $drh;	# a package global

	my $inner;
	($drh, $inner) = DBI::_new_drh('DBD::Switch::dr', {
		'Name'    =&gt; 'Switch',
		'Version' =&gt; $DBI::VERSION,
		'Attribution' =&gt; "DBI $DBI::VERSION by Tim Bunce",
	    }, \$err);
	Carp::croak("DBD::Switch init failed!") unless ($drh &amp;&amp; $inner);
	return $drh;
    }

    sub FETCH {
	my($drh, $key) = @_;
	return DBI-&gt;trace if $key eq 'DebugDispatch';
	return undef if $key eq 'DebugLog';	# not worth fetching, sorry
	return $drh-&gt;DBD::_::dr::FETCH($key);
	undef;
    }
    sub STORE {
	my($drh, $key, $value) = @_;
	if ($key eq 'DebugDispatch') {
	    DBI-&gt;trace($value);
	} elsif ($key eq 'DebugLog') {
	    DBI-&gt;trace(-1, $value);
	} else {
	    $drh-&gt;DBD::_::dr::STORE($key, $value);
	}
    }
}


# --------------------------------------------------------------------
# === OPTIONAL MINIMAL BASE CLASSES FOR DBI SUBCLASSES ===

# We only define default methods for harmless functions.
# We don't, for example, define a DBD::_::st::prepare()

{   package DBD::_::common; # ====== Common base class methods ======
    use strict;

    # methods common to all handle types:

    sub _not_impl {
	my ($h, $method) = @_;
	$h-&gt;trace_msg("Driver does not implement the $method method.\n");
	return;	# empty list / undef
    }

    # generic TIEHASH default methods:
    sub FIRSTKEY { }
    sub NEXTKEY  { }
    sub EXISTS   { defined($_[0]-&gt;FETCH($_[1])) } # XXX undef?
    sub CLEAR    { Carp::carp "Can't CLEAR $_[0] (DBI)" }

    *dump_handle = \&amp;DBI::dump_handle;
}


{   package DBD::_::dr;  # ====== DRIVER ======
    @ISA = qw(DBD::_::common);
    use strict;

    sub default_user {
	my ($drh, $user, $pass) = @_;
	unless (defined $user) {
	    $user = $ENV{DBI_USER};
	    carp("DBI connect: user not defined and DBI_USER env var not set")
		if 0 &amp;&amp; !defined $user &amp;&amp; $drh-&gt;{Warn};	# XXX enable later
	}
	unless (defined $pass) {
	    $pass = $ENV{DBI_PASS};
	    carp("DBI connect: password not defined and DBI_PASS env var not set")
		if 0 &amp;&amp; !defined $pass &amp;&amp; $drh-&gt;{Warn};	# XXX enable later
	}
	return ($user, $pass);
    }

    sub connect { # normally overridden, but a handy default
	my ($drh, $dsn, $user, $auth) = @_;
	my ($this) = DBI::_new_dbh($drh, {
	    'Name' =&gt; $dsn,
	    'User' =&gt; $user,
	});
	$this;
    }


    sub connect_cached {
	my $drh = shift;
	my ($dsn, $user, $auth, $attr)= @_;

	# Needs support at dbh level to clear cache before complaining about
	# active children. The XS template code does this. Drivers not using
	# the template must handle clearing the cache themselves.
	my $cache = $drh-&gt;FETCH('CachedKids');
	$drh-&gt;STORE('CachedKids', $cache = {}) unless $cache;

	my @attr_keys = $attr ? sort keys %$attr : ();
	my $key = join "~~", $dsn, $user||'', $auth||'',
		$attr ? (@attr_keys,@{$attr}{@attr_keys}) : ();
	my $dbh = $cache-&gt;{$key};
	return $dbh if $dbh &amp;&amp; $dbh-&gt;FETCH('Active') &amp;&amp; eval { $dbh-&gt;ping };
	$dbh = $drh-&gt;connect(@_);
	$cache-&gt;{$key} = $dbh;	# replace prev entry, even if connect failed
	return $dbh;
    }


    sub disconnect_all {	# Driver must take responsibility for this
	# XXX Umm, may change later.
	Carp::croak("Driver has not implemented the disconnect_all method.");
    }

    sub data_sources {
	shift-&gt;_not_impl('data_sources');
    }

}


{   package DBD::_::db;  # ====== DATABASE ======
    @ISA = qw(DBD::_::common);
    use strict;

    sub disconnect  {
	shift-&gt;_not_impl('disconnect');
    }

    # Drivers are required to implement *::db::DESTROY to encourage tidy-up
    sub DESTROY  { Carp::croak("Driver has not implemented DESTROY for @_") }

    sub quote_identifier {
	my ($dbh, @id) = @_;
	my $attr = (@id &gt; 3) ? pop @id : undef;

	my $info = $dbh-&gt;{dbi_quote_identifier_cache} ||= [
	    $dbh-&gt;get_info(29)  || '"',	# SQL_IDENTIFIER_QUOTE_CHAR
	    $dbh-&gt;get_info(41)  || '.',	# SQL_CATALOG_NAME_SEPARATOR
	    $dbh-&gt;get_info(114) ||   1,	# SQL_CATALOG_LOCATION
	];

	my $quote = $info-&gt;[0];
	foreach (@id) {			# quote the elements
	    next unless defined;
	    s/$quote/$quote$quote/g;	# escape embedded quotes
	    $_ = qq{$quote$_$quote};
	}

	# strip out catalog if present for special handling
	my $catalog = (@id &gt;= 3) ? shift @id : undef;

	# join the dots, ignoring any null/undef elements (ie schema)
	my $quoted_id = join '.', grep { defined } @id;

	if ($catalog) {			# add catalog correctly
	    $quoted_id = ($info-&gt;[2] == 2)	# SQL_CL_END
		    ? $quoted_id . $info-&gt;[1] . $catalog
		    : $catalog   . $info-&gt;[1] . $quoted_id;
	}
	return $quoted_id;
    }

    sub quote {
	my ($dbh, $str, $data_type) = @_;

	return "NULL" unless defined $str;
	unless ($data_type) {
	    $str =~ s/'/''/g;		# ISO SQL2
	    return "'$str'";
	}

	my $dbi_literal_quote_cache = $dbh-&gt;{'dbi_literal_quote_cache'} ||= [ {} , {} ];
	my ($prefixes, $suffixes) = @$dbi_literal_quote_cache;

	my $lp = $prefixes-&gt;{$data_type};
	my $ls = $suffixes-&gt;{$data_type};

	if ( ! defined $lp || ! defined $ls ) {
	    my $ti = $dbh-&gt;type_info($data_type);
	    $lp = $prefixes-&gt;{$data_type} = $ti ? $ti-&gt;{LITERAL_PREFIX} || "" : "'";
	    $ls = $suffixes-&gt;{$data_type} = $ti ? $ti-&gt;{LITERAL_SUFFIX} || "" : "'";
	}
	return $str unless $lp || $ls; # no quoting required

	# XXX don't know what the standard says about escaping
	# in the 'general case' (where $lp != "'").
	# So we just do this and hope:
	$str =~ s/$lp/$lp$lp/g
		if $lp &amp;&amp; $lp eq $ls &amp;&amp; ($lp eq "'" || $lp eq '"');
	return "$lp$str$ls";
    }

    sub rows { -1 }	# here so $DBI::rows 'works' after using $dbh

    sub do {
	my($dbh, $statement, $attr, @params) = @_;
	my $sth = $dbh-&gt;prepare($statement, $attr) or return undef;
	$sth-&gt;execute(@params) or return undef;
	my $rows = $sth-&gt;rows;
	($rows == 0) ? "0E0" : $rows;
    }

    sub _do_selectrow {
	my ($method, $dbh, $stmt, $attr, @bind) = @_;
	my $sth = (ref $stmt) ? $stmt
			      : $dbh-&gt;prepare($stmt, $attr);
	return unless $sth;
	$sth-&gt;execute(@bind) || return;
	my $row = $sth-&gt;$method();
	$sth-&gt;finish if $row;
	return $row;
    }

    sub selectrow_arrayref { return _do_selectrow('fetchrow_arrayref', @_); }
    sub selectrow_hashref {  return _do_selectrow('fetchrow_hashref',  @_); }

    sub selectrow_array {
	my ($dbh, $stmt, $attr, @bind) = @_;
	my $sth = (ref $stmt) ? $stmt
			      : $dbh-&gt;prepare($stmt, $attr);
	return unless $sth;
	$sth-&gt;execute(@bind) || return;
	my @row = $sth-&gt;fetchrow_array;
	$sth-&gt;finish if @row;
	return $row[0] unless wantarray;
	return @row;
    }

    sub selectall_arrayref {
	my ($dbh, $stmt, $attr, @bind) = @_;
	my $sth = (ref $stmt) ? $stmt : $dbh-&gt;prepare($stmt, $attr);
	return unless $sth;
	$sth-&gt;execute(@bind) || return;
	my $slice = $attr-&gt;{Slice}; # typically undef, else hash or array ref
	if (!$slice and $slice=$attr-&gt;{Columns}) {
	    if (ref $slice eq 'ARRAY') { # map col idx to perl array idx
		$slice = [ @{$attr-&gt;{Columns}} ];	# take a copy
		for (@$slice) { $_-- }
	    }
	}
	return $sth-&gt;fetchall_arrayref($slice);
    }

    sub selectall_hashref {
	my ($dbh, $stmt, $key_field, $attr, @bind) = @_;
	my $sth = (ref $stmt) ? $stmt : $dbh-&gt;prepare($stmt, $attr);
	return unless $sth;
	$sth-&gt;execute(@bind) || return;
	return $sth-&gt;fetchall_hashref($key_field);
    }

    sub selectcol_arrayref {
	my ($dbh, $stmt, $attr, @bind) = @_;
	my $sth = (ref $stmt) ? $stmt : $dbh-&gt;prepare($stmt, $attr);
	return unless $sth;
	$sth-&gt;execute(@bind) || return;
	my @columns = ($attr-&gt;{Columns}) ? @{$attr-&gt;{Columns}} : (1);
	my @values  = (undef) x @columns;
	my $idx = 0;
	for (@columns) {
	    $sth-&gt;bind_col($_, \$values[$idx++]) || return;
	}
	my @col;
	push @col, @values while $sth-&gt;fetch;
	return \@col;
    }

    sub prepare_cached {
	my ($dbh, $statement, $attr, $allow_active) = @_;
	# Needs support at dbh level to clear cache before complaining about
	# active children. The XS template code does this. Drivers not using
	# the template must handle clearing the cache themselves.
	my $cache = $dbh-&gt;FETCH('CachedKids');
	$dbh-&gt;STORE('CachedKids', $cache = {}) unless $cache;
	my @attr_keys = ($attr) ? sort keys %$attr : ();
	my $key = ($attr) ? join("~~", $statement, @attr_keys, @{$attr}{@attr_keys}) : $statement;
	my $sth = $cache-&gt;{$key};
	if ($sth) {
	    if ($sth-&gt;FETCH('Active') &amp;&amp; ($allow_active||0) != 2) {
		Carp::carp("prepare_cached($statement) statement handle $sth was still active")
		    if !$allow_active;
		$sth-&gt;finish;
	    }
	    return $sth;
	}
	$sth = $dbh-&gt;prepare($statement, $attr);
	$cache-&gt;{$key} = $sth if $sth;
	return $sth;
    }

    sub ping {
	shift-&gt;_not_impl('ping');
	"0 but true";	# special kind of true 0
    }

    sub begin_work {
	my $dbh = shift;
	return $dbh-&gt;DBI::set_err(1, "Already in a transaction")
		unless $dbh-&gt;FETCH('AutoCommit');
	$dbh-&gt;STORE('AutoCommit', 0); # will croak if driver doesn't support it
	$dbh-&gt;STORE('BegunWork',  1); # trigger post commit/rollback action
    }
    sub commit {
	shift-&gt;_not_impl('commit');
    }
    sub rollback {
	shift-&gt;_not_impl('rollback');
    }

    sub get_info {
	shift-&gt;_not_impl("get_info @_");
    }

    sub table_info {
	shift-&gt;_not_impl('table_info');
    }

    sub column_info {
	shift-&gt;_not_impl('column_info');
    }

    sub primary_key_info {
	shift-&gt;_not_impl('primary_key_info');
    }

    sub primary_key {
	my ($dbh, @args) = @_;
	my $sth = $dbh-&gt;primary_key_info(@args) or return;
	my ($row, @col);
	push @col, $row-&gt;[3] while ($row = $sth-&gt;fetch);
	croak("primary_key method not called in list context")
		unless wantarray; # leave us some elbow room
	return @col;
    }

    sub foreign_key_info {
	shift-&gt;_not_impl('foreign_key_info');
    }

    sub tables {
	my ($dbh, @args) = @_;
	my $sth    = $dbh-&gt;table_info(@args) or return;
	my $tables = $sth-&gt;fetchall_arrayref or return;
	my @tables;
	if ($dbh-&gt;get_info(29)) { # SQL_IDENTIFIER_QUOTE_CHAR
	    @tables = map { $dbh-&gt;quote_identifier( @{$_}[0,1,2] ) } @$tables;
	}
	else {		# temporary old style hack (yeach)
	    @tables = map {
		my $name = $_-&gt;[2];
		if ($_-&gt;[1]) {
		    my $schema = $_-&gt;[1];
		    # a sad hack (mostly for Informix I recall)
		    my $quote = ($schema eq uc($schema)) ? '' : '"';
		    $name = "$quote$schema$quote.$name"
		}
		$name;
	    } @$tables;
	}
	return @tables;
    }

    sub type_info_all {
	my ($dbh) = @_;
	$dbh-&gt;_not_impl('type_info_all');
	my $ti = [ {} ];
	return $ti;
    }

    sub type_info {
	my ($dbh, $data_type) = @_;
	my $idx_hash;
	my $tia = $dbh-&gt;{dbi_type_info_row_cache};
	if ($tia) {
	    $idx_hash = $dbh-&gt;{dbi_type_info_idx_cache};
	}
	else {
	    my $temp = $dbh-&gt;type_info_all;
	    return unless $temp &amp;&amp; @$temp;
	    $tia      = $dbh-&gt;{dbi_type_info_row_cache} = $temp;
	    $idx_hash = $dbh-&gt;{dbi_type_info_idx_cache} = shift @$tia;
	}

	my $dt_idx   = $idx_hash-&gt;{DATA_TYPE} || $idx_hash-&gt;{data_type};
	Carp::croak("type_info_all returned non-standard DATA_TYPE index value ($dt_idx != 1)")
	    if $dt_idx &amp;&amp; $dt_idx != 1;

	# --- simple DATA_TYPE match filter
	my @ti;
	my @data_type_list = (ref $data_type) ? @$data_type : ($data_type);
	foreach $data_type (@data_type_list) {
	    if (defined($data_type) &amp;&amp; $data_type != DBI::SQL_ALL_TYPES()) {
		push @ti, grep { $_-&gt;[$dt_idx] == $data_type } @$tia;
	    }
	    else {	# SQL_ALL_TYPES
		push @ti, @$tia;
	    }
	    last if @ti;	# found at least one match
	}

	# --- format results into list of hash refs
	my $idx_fields = keys %$idx_hash;
	my @idx_names  = map { uc($_) } keys %$idx_hash;
	my @idx_values = values %$idx_hash;
	Carp::croak "type_info_all result has $idx_fields keys but ".(@{$ti[0]})." fields"
		if @ti &amp;&amp; @{$ti[0]} != $idx_fields;
	my @out = map {
	    my %h; @h{@idx_names} = @{$_}[ @idx_values ]; \%h;
	} @ti;
	return $out[0] unless wantarray;
	return @out;
    }
}


{   package DBD::_::st;  # ====== STATEMENT ======
    @ISA = qw(DBD::_::common);
    use strict;

    sub cancel  { undef }
    sub bind_param { Carp::croak("Can't bind_param, not implement by driver") }

#
# ********************************************************
#
#	BEGIN ARRAY BINDING
#
#	Array binding support for drivers which don't support
#	array binding, but have sufficient interfaces to fake it.
#	NOTE: mixing scalars and arrayrefs requires using bind_param_array
#	for *all* params...unless we modify bind_param for the default
#	case...
#
#	2002-Apr-10	D. Arnold

    sub bind_param_array {
	my $sth = shift;
	my ($p_id, $value_array, $attr) = @_;

	return $sth-&gt;DBI::set_err(1, "Value for parameter $p_id must be a scalar or an arrayref, not a ".ref($value_array))
	    if defined $value_array and ref $value_array and ref $value_array ne 'ARRAY';

	return $sth-&gt;DBI::set_err(1, "Can't use named placeholders for non-driver supported bind_param_array")
	    unless DBI::looks_like_number($p_id); # because we rely on execute(@ary) here

	# get/create arrayref to hold params
	my $hash_of_arrays = $sth-&gt;{ParamArrays} ||= { };

	if (ref $value_array eq 'ARRAY') {
	    # check that input has same length as existing
	    # find first arrayref entry (if any)
	    foreach (keys %$hash_of_arrays) {
		my $v = $$hash_of_arrays{$_};
		next unless ref $v eq 'ARRAY';
		return $sth-&gt;DBI::set_err(1,
			"Arrayref for parameter $p_id has ".@$value_array." elements"
			." but parameter $_ has ".@$v)
		    if @$value_array != @$v;
	    }
	}

	# If the bind has attribs then we rely on the driver conforming to
	# the DBI spec in that a single bind_param() call with those attribs
	# makes them 'sticky' and apply to all later execute(@values) calls.
	# Since we only call bind_param() if we're given attribs then
	# applications using drivers that don't support bind_param can still
	# use bind_param_array() so long as they don't pass any attribs.

	$$hash_of_arrays{$p_id} = $value_array;
	return $sth-&gt;bind_param($p_id, undef, $attr) 
		if $attr;
	1;
    }

    sub bind_param_inout_array { 
	my $sth = shift;
	# XXX not supported so we just call bind_param_array instead
	# and then return an error
	my ($p_num, $value_array, $attr) = @_;
	$sth-&gt;bind_param_array($p_num, $value_array, $attr);
	return $sth-&gt;DBI::set_err(1, "bind_param_inout_array not supported");
    }

    sub execute_array {
	my $sth = shift;
	my ($attribs, @array_of_arrays) = @_;

	# get tuple status array or hash attribute (if any)
	my $tuple_sts = $attribs-&gt;{ArrayTupleStatus};
	return $sth-&gt;DBI::set_err(1, "ArrayTupleStatus attribute must be an arrayref")
		if $tuple_sts and ref $tuple_sts ne 'ARRAY';

	# bind all supplied arrays
	if (@array_of_arrays) {
	    $sth-&gt;{ParamArrays} = { };	# clear out old params
	    my $NUM_OF_PARAMS = $sth-&gt;FETCH('NUM_OF_PARAMS');
	    return $sth-&gt;DBI::set_err(1, @array_of_arrays." bind values supplied but $NUM_OF_PARAMS expected")
		    if @array_of_arrays != $NUM_OF_PARAMS;
	    $sth-&gt;bind_param_array($_, $array_of_arrays[$_-1]) or return
		    foreach (1..@array_of_arrays);
	}

	# no binds, no args, why did they call us ? just toss it to execute()
	return $sth-&gt;execute
		unless $sth-&gt;{ParamArrays};

	# get the length of a bound array
	my $len = 1; # in case all are scalars
	my %hash_of_arrays = %{$sth-&gt;{ParamArrays}};
	foreach (keys(%hash_of_arrays)) {
	    my $ary = $hash_of_arrays{$_};
	    $len = @$ary if ref $ary eq 'ARRAY';
	}
	my @bind_ids = 1..keys(%hash_of_arrays);

	my ($errcount, $rowcount);
	my %errstr_cache;
	@$tuple_sts = () if $tuple_sts; # reset the status array
	$tuple_sts-&gt;[$len-1] = undef;	# presize array
use Data::Dumper;
#warn Dumper([ \@bind_ids, \%hash_of_arrays]);
	for (my $i=0; $i &lt; $len; ++$i) {	# for each tuple

	    my @tuple = map {
		my $a = $hash_of_arrays{$_};
#warn "$_=$a";
		ref($a) ? $a-&gt;[$i] : $a
	    } @bind_ids;
#warn Dumper(\@tuple);
	    my $rc = $sth-&gt;execute(@tuple);
	    if ($rc) {
		$rowcount += $tuple_sts-&gt;[$i] = $rc;
		next;
	    }

	    return unless $tuple_sts;	# return error if no status provided
	    $errcount++;
	    my $err = $sth-&gt;err;
	    $tuple_sts-&gt;[$i] = [ $err, $errstr_cache{$err} ||= $sth-&gt;errstr ];
	}
	return ($errcount) ? undef : $rowcount;
    }


    sub fetchall_arrayref {
	my $sth = shift;
	my $slice= shift || [];
	my $mode = ref $slice;
	my @rows;
	my $row;
	if ($mode eq 'ARRAY') {
	    # we copy the array here because fetch (currently) always
	    # returns the same array ref. XXX
	    if (@$slice) {
		push @rows, [ @{$row}[ @$slice] ] while($row = $sth-&gt;fetch);
	    }
	    else {
		# return $sth-&gt;_fetchall_arrayref;
		push @rows, [ @$row ] while($row = $sth-&gt;fetch);
	    }
	}
	elsif ($mode eq 'HASH') {
	    if (keys %$slice) {
		my @o_keys = keys %$slice;
		my @i_keys = map { lc } keys %$slice;
		while ($row = $sth-&gt;fetchrow_hashref('NAME_lc')) {
		    my %hash;
		    @hash{@o_keys} = @{$row}{@i_keys};
		    push @rows, \%hash;
		}
	    }
	    else {
		# XXX assumes new ref each fetchhash
		push @rows, $row while ($row = $sth-&gt;fetchrow_hashref());
	    }
	}
	else { Carp::croak("fetchall_arrayref($mode) invalid") }
	return \@rows;
    }

    sub fetchall_hashref {
	my ($sth, $key_field) = @_;

	my $hash_key_name = $sth-&gt;{FetchHashKeyName};
	my $names_hash = $sth-&gt;FETCH("${hash_key_name}_hash");
	my $index = $names_hash-&gt;{$key_field};	# perl index not column number
	++$index if defined $index;		# convert to column number
	$index ||= $key_field if DBI::looks_like_number($key_field) &amp;&amp; $key_field&gt;=1;
	return $sth-&gt;DBI::set_err(1, "Field '$key_field' does not exist (not one of @{[keys %$names_hash]})")
		unless defined $index;
	my $key_value;
	$sth-&gt;bind_col($index, \$key_value) or return;
	my %rows;
	while (my $row = $sth-&gt;fetchrow_hashref($hash_key_name)) {
	    $rows{ $key_value } = $row;
	}
	return \%rows;
    }

    *dump_results = \&amp;DBI::dump_results;

    sub blob_copy_to_file {	# returns length or undef on error
	my($self, $field, $filename_or_handleref, $blocksize) = @_;
	my $fh = $filename_or_handleref;
	my($len, $buf) = (0, "");
	$blocksize ||= 512;	# not too ambitious
	local(*FH);
	unless(ref $fh) {
	    open(FH, "&gt;$fh") || return undef;
	    $fh = \*FH;
	}
	while(defined($self-&gt;blob_read($field, $len, $blocksize, \$buf))) {
	    print $fh $buf;
	    $len += length $buf;
	}
	close(FH);
	$len;
    }

    sub more_results {
	shift-&gt;{syb_more_results};	# handy grandfathering
    }

    # Drivers are required to implement *::st::DESTROY to encourage tidy-up
    sub DESTROY  { Carp::croak("Driver has not implemented DESTROY for @_") }
}

{   # See install_driver
    { package DBD::_mem::dr; @ISA = qw(DBD::_mem::common);	}
    { package DBD::_mem::db; @ISA = qw(DBD::_mem::common);	}
    { package DBD::_mem::st; @ISA = qw(DBD::_mem::common);	}
    # DBD::_mem::common::DESTROY is implemented in DBI.xs
}

1;
__END__

=head1 DESCRIPTION

The DBI is a database access module for the Perl programming language.  It defines
a set of methods, variables, and conventions that provide a consistent
database interface, independent of the actual database being used.

It is important to remember that the DBI is just an interface.
The DBI is a layer
of "glue" between an application and one or more database I&lt;driver&gt;
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 Architecture of a DBI Application

             |&lt;- Scope of DBI -&gt;|
                  .-.   .--------------.   .-------------.
  .-------.       | |---| XYZ Driver   |---| XYZ Engine  |
  | Perl  |       | |   `--------------'   `-------------'
  | script|  |A|  |D|   .--------------.   .-------------.
  | using |--|P|--|B|---|Oracle Driver |---|Oracle Engine|
  | DBI   |  |I|  |I|   `--------------'   `-------------'
  | API   |       | |...
  |methods|       | |... Other drivers
  `-------'       | |...
                  `-'

The API, or Application Programming Interface, defines the
call interface and variables for Perl scripts to use. The API
is implemented by the Perl DBI extension.

The DBI "dispatches" the method calls to the appropriate driver for
actual execution.  The DBI is also responsible for the dynamic loading
of drivers, error checking and handling, providing default
implementations for methods, and many other non-database specific duties.

Each driver
contains implementations of the DBI methods using the
private interface functions of the corresponding database engine.  Only authors
of sophisticated/multi-database applications or generic library
functions need be concerned with drivers.

=head2 Notation and Conventions

The following conventions are used in this document:

  $dbh    Database handle object
  $sth    Statement handle object
  $drh    Driver handle object (rarely seen or used in applications)
  $h      Any of the handle types above ($dbh, $sth, or $drh)
  $rc     General Return Code  (boolean: true=ok, false=error)
  $rv     General Return Value (typically an integer)
  @ary    List of values returned from the database, typically a row of data
  $rows   Number of rows processed (if available, else -1)
  $fh     A filehandle
  undef   NULL values are represented by undefined values in Perl
  \%attr  Reference to a hash of attribute values passed to methods

Note that Perl will automatically destroy database and statement handle objects
if all references to them are deleted.


=head2 Outline Usage

To use DBI,
first you need to load the DBI module:

  use DBI;
  use strict;

(The C&lt;use strict;&gt; isn't required but is strongly recommended.)

Then you need to L&lt;/connect&gt; to your data source and get a I&lt;handle&gt; for that
connection:

  $dbh = DBI-&gt;connect($dsn, $user, $password,
                      { RaiseError =&gt; 1, AutoCommit =&gt; 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&lt;AutoCommit&gt; behavior is strongly
recommended and may become mandatory in a later version.  This
determines whether changes are automatically committed to the
database when executed, or need to be explicitly committed later.

The DBI allows an application to "prepare" statements for later
execution.  A prepared statement is identified by a statement handle
held in a Perl variable.
We'll call the Perl variable C&lt;$sth&gt; in our examples.

The typical method call sequence for a C&lt;SELECT&gt; statement is:

  prepare,
    execute, fetch, fetch, ...
    execute, fetch, fetch, ...
    execute, fetch, fetch, ...

for example:

  $sth = $dbh-&gt;prepare("SELECT foo, bar FROM table WHERE baz=?");

  $sth-&gt;execute( $baz );

  while ( @row = $sth-&gt;fetchrow_array ) {
    print "@row\n";
  }

The typical method call sequence for a I&lt;non&gt;-C&lt;SELECT&gt; statement is:

  prepare,
    execute,
    execute,
    execute.

for example:

  $sth = $dbh-&gt;prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)");

  while(&lt;CSV&gt;) {
    chomp;
    my ($foo,$bar,$baz) = split /,/;
	$sth-&gt;execute( $foo, $bar, $baz );
  }

The C&lt;do()&gt; method can be used for non repeated I&lt;non&gt;-C&lt;SELECT&gt; statement
(or with drivers that don't support placeholders):

  $rows_affected = $dbh-&gt;do("UPDATE your_table SET foo = foo + 1");

To commit your changes to the database (when L&lt;/AutoCommit&gt; is off):

  $dbh-&gt;commit;  # or call $dbh-&gt;rollback; to undo changes

Finally, when you have finished working with the data source, you should
L&lt;/disconnect&gt; from it:

  $dbh-&gt;disconnect;


=head2 General Interface Rules &amp; Caveats

The DBI does not have a concept of a "current session". Every session
has a handle object (i.e., a C&lt;$dbh&gt;) returned from the C&lt;connect&gt; 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&lt;undef&gt;.)  This allows arbitrary precision numeric data to be
handled without loss of accuracy.  Beware that Perl may not preserve
the same accuracy when the string is used as a number.

Dates and times are returned as character strings in the current
default format of the corresponding database engine.  Time zone effects
are database/driver dependent.

Perl supports binary data in Perl strings, and the DBI will pass binary
data to and from the driver without change. It is up to the driver
implementors to decide how they wish to handle such binary data.

Most databases that understand multiple character sets have a
default global charset. Text stored in the database is, or should
be, stored in that charset; if not, then that's the fault of either
the database or the application that inserted the data. When text is
fetched it should be automatically converted to the charset of the
client, presumably based on the locale. If a driver needs to set a
flag to get that behavior, then it should do so; it should not require
the application to do that.

Multiple SQL statements may not be combined in a single statement
handle (C&lt;$sth&gt;), although some databases and drivers do support this
(notably Sybase and SQL Server).

Non-sequential record reads are not supported in this version of the DBI.
In other words, records can only be fetched in the order that the
database returned them, and once fetched they are forgotten.

Positioned updates and deletes are not directly supported by the DBI.
See the description of the C&lt;CursorName&gt; 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&lt;func()&gt; method.
Private driver attributes are accessed just like standard attributes.

Many methods have an optional C&lt;\%attr&gt; parameter which can be used to
pass information to the driver implementing the method. Except where
specifically documented, the C&lt;\%attr&gt; parameter can only be used to pass
driver specific hints. In general, you can ignore C&lt;\%attr&gt; parameters
or pass it as C&lt;undef&gt;.


=head2 Naming Conventions and Name Space

The DBI package and all packages below it (C&lt;DBI::*&gt;) are reserved for
use by the DBI. Extensions and related modules use the C&lt;DBIx::&gt;
namespace (see C&lt;http://www.perl.com/CPAN/modules/by-module/DBIx/&gt;).
Package names beginning with C&lt;DBD::&gt; are reserved for use
by DBI database drivers.  All environment variables used by the DBI
or by individual DBDs begin with "C&lt;DBI_&gt;" or "C&lt;DBD_&gt;".

The letter case used for attribute names is significant and plays an
important part in the portability of DBI scripts.  The case of the
attribute name is used to signify who defined the meaning of that name
and its values.

  Case of name  Has a meaning defined by
  ------------  ------------------------
  UPPER_CASE    Standards, e.g.,  X/Open, ISO SQL92 etc (portable)
  MixedCase     DBI API (portable), underscores are not used.
  lower_case    Driver or database engine specific (non-portable)

It is of the utmost importance that Driver developers only use
lowercase attribute names when defining private attributes. Private
attribute names must be prefixed with the driver name or suitable
abbreviation (e.g., "C&lt;ora_&gt;" for Oracle, "C&lt;ing_&gt;" for Ingres, etc).

Driver Specific Prefix Registry:

  ad_      DBD::AnyData
  ado_     DBD::ADO
  best_    DBD::BestWins
  csv_     DBD::CSV
  db2_     DBD::DB2
  f_       DBD::File
  file_    DBD::TextFile
  ib_      DBD::InterBase
  ing_     DBD::Ingres
  ix_      DBD::Informix
  msql_    DBD::mSQL
  mysql_   DBD::mysql
  odbc_    DBD::ODBC
  ora_     DBD::Oracle
  pg_      DBD::Pg
  proxy_   DBD::Proxy
  rdb_     DBD::RDB
  sapdb_   DBD::SAP_DB
  solid_   DBD::Solid
  syb_     DBD::Sybase
  tdat_    DBD::Teradata
  tuber_   DBD::Tuber
  uni_     DBD::Unify
  xbase_   DBD::XBase


=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 following links provide useful information and further links about
SQL:

  http://www.altavista.com/query?q=sql+tutorial
  http://www.jcc.com/sql_stnd.html
  http://www.contrib.andrew.cmu.edu/~shadow/sql.html

The DBI itself does not mandate or require any particular language to
be used; it is language independent. In ODBC terms, the DBI is in
"pass-thru" mode, although individual drivers might not be. The only requirement
is that queries and other statements must be expressed as a single
string of characters passed as the first argument to the L&lt;/prepare&gt; or
L&lt;/do&gt; methods.

For an interesting diversion on the I&lt;real&gt; history of RDBMS and SQL,
from the people who made it happen, see:

  http://ftp.digital.com/pub/DEC/SRC/technical-notes/SRC-1997-018-html/sqlr95.html

Follow the "And the rest" and "Intergalactic dataspeak" links for the
SQL history.

=head2 Placeholders and Bind Values

Some drivers support placeholders and bind values.
I&lt;Placeholders&gt;, also called parameter markers, are used to indicate
values in a database statement that will be supplied later,
before the prepared statement is executed.  For example, an application
might use the following to insert a row of data into the SALES table:

  INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)

or the following, to select the description for a product:

  SELECT description FROM products WHERE product_code = ?

The C&lt;?&gt; characters are the placeholders.  The association of actual
values with placeholders is known as I&lt;binding&gt;, and the values are
referred to as I&lt;bind values&gt;.

When using placeholders with the SQL C&lt;LIKE&gt; qualifier, you must
remember that the placeholder substitutes for the whole string.
So you should use "C&lt;... LIKE ? ...&gt;" and include any wildcard
characters in the value that you bind to the placeholder.

B&lt;Null Values&gt;

Undefined values, or C&lt;undef&gt;, can be used to indicate null values.
However, care must be taken in the particular case of trying to use
null values to qualify a C&lt;SELECT&gt; statement. Consider:

  SELECT description FROM products WHERE product_code = ?

Binding an C&lt;undef&gt; (NULL) to the placeholder will I&lt;not&gt; select rows
which have a NULL C&lt;product_code&gt;! 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&lt;WHERE product_code IS NULL&gt;" and to make that
general you have to say:

  ... WHERE (product_code = ? OR (? IS NULL AND product_code IS NULL))

and bind the same value to both placeholders.

B&lt;Performance&gt;

Without using placeholders, the insert statement shown previously would have to
contain the literal values to be inserted and would have to be
re-prepared and re-executed for each row. With placeholders, the insert
statement only needs to be prepared once. The bind values for each row
can be given to the C&lt;execute&gt; method each time it's called. By avoiding
the need to re-prepare the statement for each row, the application
typically runs many times faster. Here's an example:

  my $sth = $dbh-&gt;prepare(q{
    INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
  }) or die $dbh-&gt;errstr;
  while (&lt;&gt;) {
      chomp;
      my ($product_code, $qty, $price) = split /,/;
      $sth-&gt;execute($product_code, $qty, $price) or die $dbh-&gt;errstr;
  }
  $dbh-&gt;commit or die $dbh-&gt;errstr;

See L&lt;/execute&gt; and L&lt;/bind_param&gt; for more details.

The C&lt;q{...}&gt; style quoting used in this example avoids clashing with
quotes that may be used in the SQL statement. Use the double-quote like
C&lt;qq{...}&gt; operator if you want to interpolate variables into the string.
See L&lt;perlop/"Quote and Quote-like Operators"&gt; for more details.

See also the L&lt;/bind_column&gt; method, which is used to associate Perl
variables with the output columns of a C&lt;SELECT&gt; 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&lt;:sql_types&gt; 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", $_, &amp;{"DBI::$_"};
  }

These constants are defined by SQL/CLI, ODBC or both.
C&lt;SQL_BIGINT&gt; is (currently) omitted, because SQL/CLI and ODBC provide
conflicting codes.

See the L&lt;/type_info&gt;, L&lt;/type_info_all&gt;, and L&lt;/bind_param&gt; 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:

=over 4

=item C&lt;connect&gt;

  $dbh = DBI-&gt;connect($data_source, $username, $password)
            or die $DBI::errstr;
  $dbh = DBI-&gt;connect($data_source, $username, $password, \%attr)
            or die $DBI::errstr;

Establishes a database connection, or session, to the requested C&lt;$data_source&gt;.
Returns a database handle object if the connection succeeds. Use
C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;disconnect&gt; to terminate the connection.

If the connect fails (see below), it returns C&lt;undef&gt; and sets both C&lt;$DBI::err&gt;
and C&lt;$DBI::errstr&gt;. (It does I&lt;not&gt; set C&lt;$!&gt;, etc.) You should generally
test the return status of C&lt;connect&gt; and C&lt;print $DBI::errstr&gt; if it has failed.

Multiple simultaneous connections to multiple databases through multiple
drivers can be made via the DBI. Simply make one C&lt;connect&gt; call for each
database and keep a copy of each returned database handle.

The C&lt;$data_source&gt; value should begin with "C&lt;dbi:&gt;I&lt;driver_name&gt;C&lt;:&gt;". The
I&lt;driver_name&gt; specifies the driver that will be used to make the
connection. (Letter case is significant.)

As a convenience, if the C&lt;$data_source&gt; parameter is undefined or empty, the
DBI will substitute the value of the environment variable C&lt;DBI_DSN&gt;.
If just the I&lt;driver_name&gt; part is empty (i.e., the C&lt;$data_source&gt; prefix is "C&lt;dbi::&gt;"),
the environment variable C&lt;DBI_DRIVER&gt; is used. If neither variable is set,
then C&lt;connect&gt; dies.

Examples of C&lt;$data_source&gt; values are:

  dbi:DriverName:database_name
  dbi:DriverName:database_name@hostname:port
  dbi:DriverName:database=database_name;host=hostname;port=port

There is I&lt;no standard&gt; for the text following the driver name. Each
driver is free to use whatever syntax it wants. The only requirement the
DBI makes is that all the information is supplied in a single string.
You must consult the documentation for the drivers you are using for a
description of the syntax they require. (Where a driver author needs
to define a syntax for the C&lt;$data_source&gt;, it is recommended that
they follow the ODBC style, shown in the last example above.)

If the environment variable C&lt;DBI_AUTOPROXY&gt; is defined (and the driver in
C&lt;$data_source&gt; is not "C&lt;Proxy&gt;") then the connect request will
automatically be changed to:

  dbi:Proxy:$ENV{DBI_AUTOPROXY};dsn=$data_source

and passed to the DBD::Proxy module. C&lt;DBI_AUTOPROXY&gt; is typically set as
"C&lt;hostname=...;port=...&gt;". See the DBD::Proxy documentation for more details.

If C&lt;$username&gt; or C&lt;$password&gt; are undefined (rather than just empty),
then the DBI will substitute the values of the C&lt;DBI_USER&gt; and C&lt;DBI_PASS&gt;
environment variables, respectively.  The DBI will warn if the
environment variables are not defined.  However, the everyday use of
these environment
variables is not recommended for security reasons. The mechanism is
primarily intended to simplify testing.

C&lt;DBI-&gt;E&lt;gt&gt;C&lt;connect&gt; automatically installs the driver if it has not been
installed yet. Driver installation either returns a valid driver
handle, or it I&lt;dies&gt; with an error message that includes the string
"C&lt;install_driver&gt;" and the underlying problem. So C&lt;DBI-&gt;E&lt;gt&gt;C&lt;connect&gt;
will die
on a driver installation failure and will only return C&lt;undef&gt; on a
connect failure, in which case C&lt;$DBI::errstr&gt; will hold the error message.

The C&lt;$data_source&gt; argument (with the "C&lt;dbi:...:&gt;" prefix removed) and the
C&lt;$username&gt; and C&lt;$password&gt; 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&lt;$data_source&gt;, C&lt;$username&gt;, and C&lt;$password&gt; 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&lt;$data_source&gt; is specified.)

The C&lt;AutoCommit&gt; and C&lt;PrintError&gt; attributes for each connection default to
"on". (See L&lt;/AutoCommit&gt; and L&lt;/PrintError&gt; for more information.)
However, it is strongly recommended that you explicitly define C&lt;AutoCommit&gt;
rather than rely on the default. Future versions of
the DBI may issue a warning if C&lt;AutoCommit&gt; is not explicitly defined.

The C&lt;\%attr&gt; parameter can be used to alter the default settings of
C&lt;PrintError&gt;, C&lt;RaiseError&gt;, C&lt;AutoCommit&gt;, and other attributes. For example:

  $dbh = DBI-&gt;connect($data_source, $user, $pass, {
	PrintError =&gt; 0,
	AutoCommit =&gt; 0
  });

You can also define connection attribute values within the C&lt;$data_source&gt;
parameter. For example:

  dbi:DriverName(PrintError=&gt;0,Taint=&gt;1):...

Individual attributes values specified in this way take precedence over
any conflicting values specified via the C&lt;\%attr&gt; parameter to C&lt;connect&gt;.

The C&lt;dbi_connect_method&gt; attribute can be used to specify which driver
method should be called to establish the connection. The only useful
values are 'connect', 'connect_cached', or some specialized case like
'Apache::DBI::connect' (which is automatically the default when running
within Apache).

Where possible, each session (C&lt;$dbh&gt;) is independent from the transactions
in other sessions. This is useful when you need to hold cursors open
across transactions--for example, if you use one session for your long lifespan
cursors (typically read-only) and another for your short update
transactions.

For compatibility with old DBI scripts, the driver can be specified by
passing its name as the fourth argument to C&lt;connect&gt; (instead of C&lt;\%attr&gt;):

  $dbh = DBI-&gt;connect($data_source, $user, $pass, $driver);

In this "old-style" form of C&lt;connect&gt;, the C&lt;$data_source&gt; should not start
with "C&lt;dbi:driver_name:&gt;". (If it does, the embedded driver_name
will be ignored). Also note that in this older form of C&lt;connect&gt;,
the C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;{AutoCommit}&gt; attribute is I&lt;undefined&gt;, the
C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;{PrintError}&gt; attribute is off, and the old C&lt;DBI_DBNAME&gt;
environment variable is
checked if C&lt;DBI_DSN&gt; is not defined. Beware that this "old-style"
C&lt;connect&gt; will be withdrawn in a future version of DBI.

=item C&lt;connect_cached&gt; I&lt;NEW&gt;

  $dbh = DBI-&gt;connect_cached($data_source, $username, $password)
            or die $DBI::errstr;
  $dbh = DBI-&gt;connect_cached($data_source, $username, $password, \%attr)
            or die $DBI::errstr;

C&lt;connect_cached&gt; is like L&lt;/connect&gt;, except that the database handle
returned is also
stored in a hash associated with the given parameters. If another call
is made to C&lt;connect_cached&gt; with the same parameter values, then the
corresponding cached C&lt;$dbh&gt; 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&lt;ping&gt; method fails.

Note that the behavior of this method differs in several respects from the
behavior of presistent connections implemented by Apache::DBI.

Caching can be useful in some applications, but it can also cause
problems and should be used with care. The exact behavior of this
method is liable to change, so if you intend to use it in any production
applications you should discuss your needs on the I&lt;dbi-users&gt; mailing list.

The cache can be accessed (and cleared) via the L&lt;/CachedKids&gt; attribute.


=item C&lt;available_drivers&gt;

  @ary = DBI-&gt;available_drivers;
  @ary = DBI-&gt;available_drivers($quiet);

Returns a list of all available drivers by searching for C&lt;DBD::*&gt; modules
through the directories in C&lt;@INC&gt;. 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&lt;$quiet&gt; will inhibit the warning.


=item C&lt;data_sources&gt;

  @ary = DBI-&gt;data_sources($driver);
  @ary = DBI-&gt;data_sources($driver, \%attr);

Returns a list of all data sources (databases) available via the named
driver.  If C&lt;$driver&gt; is empty or C&lt;undef&gt;, then the value of the
C&lt;DBI_DRIVER&gt; environment variable is used.

The driver will be loaded if it hasn't been already. Note that if the
driver loading fails then it I&lt;dies&gt; with an error message that
includes the string "C&lt;install_driver&gt;" and the underlying problem.

Data sources are returned in a form suitable for passing to the
L&lt;/connect&gt; method (that is, they will include the "C&lt;dbi:$driver:&gt;" 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, such as a connected database
handle, to be supplied.


=item C&lt;trace&gt;

  DBI-&gt;trace($trace_level)
  DBI-&gt;trace($trace_level, $trace_filename)

DBI trace information can be enabled for all handles using the C&lt;trace&gt;
DBI class method. To enable trace information for a specific handle, use
the similar C&lt;$h-&gt;E&lt;gt&gt;C&lt;trace&gt; method described elsewhere.

Trace levels are as follows:

  0 - Trace disabled.
  1 - Trace DBI method calls returning with results or errors.
  2 - Trace method entry with parameters and returning with results.
  3 - As above, adding some high-level information from the driver
      and some internal information from the DBI.
  4 - As above, adding more detailed information from the driver.
      Also includes DBI mutex information when using threaded Perl.
  5 and above - 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 (up to 9) 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&lt;/neat&gt; function, so strings
in the trace output may be edited and truncated.

Initially trace output is written to C&lt;STDERR&gt;.  If C&lt;$trace_filename&gt; is
specified and can be opened in append mode then all trace
output (including that from other handles) is redirected to that file.
A warning is generated is the file can't be opened.
Further calls to C&lt;trace&gt; without a C&lt;$trace_filename&gt; do not alter where
the trace output is sent. If C&lt;$trace_filename&gt; is undefined, then
trace output is sent to C&lt;STDERR&gt; and the previous trace file is closed.
The C&lt;trace&gt; method returns the I&lt;previous&gt; tracelevel.

See also the C&lt;$h-&gt;E&lt;gt&gt;C&lt;trace&gt; and C&lt;$h-&gt;E&lt;gt&gt;C&lt;trace_msg&gt; methods and the
L&lt;/DEBUGGING&gt; section
for information about the C&lt;DBI_TRACE&gt; environment variable.


=back


=head2 DBI Utility Functions

In addition to the methods listed in the previous section,
the DBI package also provides these utility functions:

=over 4

=item C&lt;neat&gt;

  $str = DBI::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&lt;not&gt; be escaped.
Values known to be numeric will be unquoted. Undefined (NULL) values
will be shown as C&lt;undef&gt; (without quotes). Unprintable characters will
be replaced by dot (.).

For result strings longer than C&lt;$maxlen&gt; the result string will be
truncated to C&lt;$maxlen-4&gt; and "C&lt;...'&gt;" will be appended.  If C&lt;$maxlen&gt; is 0
or C&lt;undef&gt;, it defaults to C&lt;$DBI::neat_maxlen&gt; 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&lt;/trace&gt; output. It should
typically I&lt;not&gt; be used for formatting values for database use.
(See also L&lt;/quote&gt;.)

=item C&lt;neat_list&gt;

  $str = DBI::neat_list(\@listref, $maxlen, $field_sep);

Calls C&lt;DBI::neat&gt; on each element of the list and returns a string
containing the results joined with C&lt;$field_sep&gt;. C&lt;$field_sep&gt; defaults
to C&lt;", "&gt;.

=item C&lt;looks_like_number&gt;

  @bool = DBI::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&lt;undef&gt; for each element that is undefined or empty.

=item C&lt;hash&gt;

  $hash_value = DBI::hash($buffer, $type);

Return a 32-bit integer 'hash' value corresponding to the contents of $buffer.
The $type parameter selects which kind of hash algorithm should be used.

For the technically curious, type 0 (which is the default if $type
isn't specified) is based on the Perl 5.1 hash except that the value
is forced to be negative (for obscure historical reasons).
Type 1 is the better "Fowler / Noll / Vo" (FNV) hash. See
http://www.isthe.com/chongo/tech/comp/fnv/ 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.

=back


=head2 DBI Dynamic Attributes

Dynamic attributes are always associated with the I&lt;last handle used&gt;
(that handle is represented by C&lt;$h&gt; in the descriptions below).

Where an attribute is equivalent to a method call, then refer to
the method call for all related documentation.

Warning: these attributes are provided as a convenience but they
do have limitations. Specifically, they have a short lifespan:
because they are associated with
the last handle used, they should only be used I&lt;immediately&gt; after
calling the method that "sets" them.
If in any doubt, use the corresponding method call.

=over 4

=item C&lt;$DBI::err&gt;

Equivalent to C&lt;$h-&gt;E&lt;gt&gt;C&lt;err&gt;.

=item C&lt;$DBI::errstr&gt;

Equivalent to C&lt;$h-&gt;E&lt;gt&gt;C&lt;errstr&gt;.

=item C&lt;$DBI::state&gt;

Equivalent to C&lt;$h-&gt;E&lt;gt&gt;C&lt;state&gt;.

=item C&lt;$DBI::rows&gt;

Equivalent to C&lt;$h-&gt;E&lt;gt&gt;C&lt;rows&gt;. Please refer to the documentation
for the L&lt;/rows&gt; method.

=item C&lt;$DBI::lasth&gt;

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.

=back


=head1 METHODS COMMON TO ALL HANDLES

The following methods can be used by all types of DBI handles.

=over 4

=item C&lt;err&gt;

  $rv = $h-&gt;err;

Returns the I&lt;native&gt; database engine error code from the last driver
method called. The code is typically an integer but you should not
assume that.

The DBI resets $h-&gt;err to undef before most DBI method calls, so the
value only has a short lifespan. Also, most drivers share the same
error variables across all their handles, so calling a method on
one handle will typically reset the error on all the other handles
that are children of that driver.

If you need to test for individual errors I&lt;and&gt; 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.

=item C&lt;errstr&gt;

  $str = $h-&gt;errstr;

Returns the native database engine error message from the last driver
method called. This has the same lifespan issues as the L&lt;/err&gt; method
described above.

=item C&lt;state&gt;

  $str = $h-&gt;state;

Returns an error code in the standard SQLSTATE five character format.
Note that the specific success code C&lt;00000&gt; is translated to 'C&lt;&gt;'
(false). If the driver does not support SQLSTATE (and most don't),
then state will return C&lt;S1000&gt; (General Error) for all errors.

The driver is free to return any value via C&lt;state&gt;, e.g., warning
codes, even if it has not declared an error by returning a true value
via the L&lt;/err&gt; method described above.

=item C&lt;set_err&gt; I&lt;NEW&gt;

  $rv = $h-&gt;set_err($err, $errstr);
  $rv = $h-&gt;set_err($err, $errstr, $state, $method);
  $rv = $h-&gt;set_err($err, $errstr, $state, $method, $rv);

Set the C&lt;err&gt;, C&lt;errstr&gt;, and C&lt;state&gt; values for the handle.
This will trigger the normal DBI error handling mechanisms,
such as C&lt;RaiseError&gt; and C&lt;HandleError&gt;, if they are enabled.
This method is typically only used by DBI drivers and DBI subclasses.

The $method parameter provides an alternate method name, instead
of the fairly unhelpful 'C&lt;set_err&gt;', for the
C&lt;RaiseError&gt;/C&lt;PrintError&gt; error string.

The C&lt;set_err&gt; method normally returns undef.  The $rv parameter
provides an alternate return value. The C&lt;HandleError&gt; subroutine
can access and alter this value.


=item C&lt;trace&gt;

  $h-&gt;trace($trace_level);
  $h-&gt;trace($trace_level, $trace_filename);

DBI trace information can be enabled for a specific handle (and any
future children of that handle) by setting the trace level using the
C&lt;trace&gt; method.

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 (up to 9) are best reserved for investigating a
specific problem, when you need to see "inside" the driver and DBI.
Set C&lt;$trace_level&gt; to 0 to disable the trace.

The trace output is detailed and typically very useful. Much of the
trace output is formatted using the L&lt;/neat&gt; function, so strings
in the trace output may be edited and truncated.

Initially, trace output is written to C&lt;STDERR&gt;.  If C&lt;$trace_filename&gt; is
specified, then the file is opened in append mode and I&lt;all&gt; trace
output (including that from other handles) is redirected to that file.
Further calls to trace without a C&lt;$trace_filename&gt; do not alter where
the trace output is sent. If C&lt;$trace_filename&gt; is undefined, then
trace output is sent to C&lt;STDERR&gt; and the previous trace file is closed.

See also the C&lt;DBI-&gt;E&lt;gt&gt;C&lt;trace&gt; method, the C&lt;$h-&gt;E&lt;gt&gt;C&lt;{TraceLevel}&gt; attribute,
and L&lt;/DEBUGGING&gt; for information about the C&lt;DBI_TRACE&gt; environment variable.


=item C&lt;trace_msg&gt;

  $h-&gt;trace_msg($message_text);
  $h-&gt;trace_msg($message_text, $min_level);

Writes C&lt;$message_text&gt; to the trace file if trace is enabled for C&lt;$h&gt; or
for the DBI as a whole. Can also be called as C&lt;DBI-&gt;E&lt;gt&gt;C&lt;trace_msg($msg)&gt;.
See L&lt;/trace&gt;.

If C&lt;$min_level&gt; is defined, then the message is output only if the trace
level is equal to or greater than that level. C&lt;$min_level&gt; defaults to 1.


=item C&lt;func&gt;

  $h-&gt;func(@func_arguments, $func_name);

The C&lt;func&gt; 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 last argument.

This method is not directly related to calling stored procedures.
Calling stored procedures is currently not defined by the DBI.
Some drivers, such as DBD::Oracle, support it in non-portable ways.
See driver documentation for more details.

=back


=head1 ATTRIBUTES COMMON TO ALL HANDLES

These attributes are common to all types of DBI handles.

Some attributes are inherited by child handles. That is, the value
of an inherited attribute in a newly created statement handle is the
same as the value in the parent database handle. Changes to attributes
in the new statement handle do not affect the parent database handle
and changes to the database handle do not affect existing statement
handles, only future ones.

Attempting to set or get the value of an unknown attribute is fatal,
except for private driver specific attributes (which all have names
starting with a lowercase letter).

Example:

  $h-&gt;{AttributeName} = ...;	# set/write
  ... = $h-&gt;{AttributeName};	# get/read

=over 4

=item C&lt;Warn&gt; (boolean, inherited)

Enables useful warnings for certain bad practices. Enabled by default. Some
emulation layers, especially those for Perl 4 interfaces, disable warnings.
Since warnings are generated using the Perl C&lt;warn&gt; function, they can be
intercepted using the Perl C&lt;$SIG{__WARN__}&gt; hook.

=item C&lt;Active&gt; (boolean, read-only)

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&lt;$dbh-&gt;E&lt;gt&gt;C&lt;disconnect&gt; sets C&lt;Active&gt; off).  For
a statement handle it typically means that the handle is a C&lt;SELECT&gt;
that may have more data to fetch. (Fetching all the data or calling C&lt;$sth-&gt;E&lt;gt&gt;C&lt;finish&gt;
sets C&lt;Active&gt; off.)

=item C&lt;Kids&gt; (integer, read-only)

For a driver handle, C&lt;Kids&gt; is the number of currently existing database
handles that were created from that driver handle.  For a database
handle, C&lt;Kids&gt; is the number of currently existing statement handles that
were created from that database handle.

=item C&lt;ActiveKids&gt; (integer, read-only)

Like C&lt;Kids&gt;, but only counting those that are C&lt;Active&gt; (as above).

=item C&lt;CachedKids&gt; (hash ref)

For a database handle, returns a reference to the cache (hash) of
statement handles created by the L&lt;/prepare_cached&gt; method.  For a
driver handle, returns a reference to the cache (hash) of
database handles created by the L&lt;/connect_cached&gt; method.

=item C&lt;CompatMode&gt; (boolean, inherited)

Used by emulation layers (such as Oraperl) to enable compatible behavior
in the underlying driver (e.g., DBD::Oracle) for this handle. Not normally
set by application code.

=item C&lt;InactiveDestroy&gt; (boolean)

This attribute can be used to disable the I&lt;database engine&gt; related
effect of DESTROYing a handle (which would normally close a prepared
statement or disconnect from the database etc).

For a database handle, this attribute does not disable an I&lt;explicit&gt;
call to the disconnect method, only the implicit call from DESTROY.

The default value, false, means that a handle will be automatically
destroyed when it passes out of scope.  A true value disables automatic
destruction. (Think of the name as meaning 'inactive the DESTROY method'.)

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&lt;InactiveDestroy&gt; on all their shared handles.
Note that some databases, including Oracle, don't support passing a
database connection across a fork.

=item C&lt;PrintError&gt; (boolean, inherited)

This attribute can be used to force errors to generate warnings (using
C&lt;warn&gt;) 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&lt;warn("$class $method failed: $DBI::errstr")&gt; where C&lt;$class&gt;
is the driver class and C&lt;$method&gt; is the name of the method which failed. E.g.,

  DBD::Oracle::db prepare failed: ... error text here ...

By default, C&lt;DBI-&gt;E&lt;gt&gt;C&lt;connect&gt; sets C&lt;PrintError&gt; "on".

If desired, the warnings can be caught and processed using a C&lt;$SIG{__WARN__}&gt;
handler or modules like CGI::Carp and CGI::ErrorWrap.

=item C&lt;RaiseError&gt; (boolean, inherited)

This 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&lt;die("$class $method failed: $DBI::errstr")&gt;,
where C&lt;$class&gt; is the driver class and C&lt;$method&gt; is the name of the method
that failed. E.g.,

  DBD::Oracle::db prepare failed: ... error text here ...

If you turn C&lt;RaiseError&gt; on then you'd normally turn C&lt;PrintError&gt; off.
If C&lt;PrintError&gt; is also on, then the C&lt;PrintError&gt; is done first (naturally).

Typically C&lt;RaiseError&gt; is used in conjunction with C&lt;eval { ... }&gt;
to catch the exception that's been thrown and followed by an
C&lt;if ($@) { ... }&gt; block to handle the caught exception. In that eval
block the $DBI::lasth variable can be useful for diagnosis and reporting.
For example, $DBI::lasth-&gt;{Type} and $DBI::lasth-&gt;{Statement}.

If you want to temporarily turn C&lt;RaiseError&gt; off (inside a library function
that is likely to fail, for example), the recommended way is like this:

  {
    local $h-&gt;{RaiseError};  # localize and turn off for this block
    ...
  }

The original value will automatically and reliably be restored by Perl,
regardless of how the block is exited.
The same logic applies to other attributes, including C&lt;PrintError&gt;.

Sadly, this doesn't work for Perl versions up to and including 5.004_04.
Even more sadly, for Perl 5.5 and 5.6.0 it does work but leaks memory!
For backwards compatibility, you could just use C&lt;eval { ... }&gt; instead.


=item C&lt;HandleError&gt; (code ref, inherited) I&lt;NEW&gt;

This 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&lt;RaiseError&gt; and C&lt;PrintError&gt; are handled).

The subroutine is called with three parameters: the error message
string that C&lt;RaiseError&gt; and C&lt;PrintError&gt; 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&lt;RaiseError&gt;
and/or C&lt;PrintError&gt; attributes are checked and acted upon as normal.

For example, to get a full stack trace for any error:

  use Carp;
  $h-&gt;{HandleError} = sub { confess(shift) };

Or to turn errors into exceptions:

  use Exception; # or your own favourite exception module
  $h-&gt;{HandleError} = sub { Exception-&gt;new('DBI')-&gt;raise($_[0]) };

It is possible to 'stack' multiple HandleError handlers by using
closures:

  sub your_subroutine {
    my $previous_handler = $h-&gt;{HandleError};
    $h-&gt;{HandleError} = sub {
      return 1 if $previous_handler and &amp;$previous_handler(@_);
      ... your code here ...
    }
  }

Using a C&lt;my&gt; inside a subroutine to store the previous C&lt;HandleError&gt;
value is important.  See L&lt;perlsub&gt; and L&lt;perlref&gt; for more information
about I&lt;closures&gt;.

It is possible for C&lt;HandleError&gt; to hide an error, to a limited
degree, by using L&lt;/set_err&gt; to reset $DBI::err and $DBI::errstr,
and altering the return value of the failed method. For example:

  $h-&gt;{HandleError} = sub {
    return 0 unless $_[0] =~ /^\S+ fetchrow_arrayref failed:/;
    return 0 unless $_[1]-&gt;err == 1234; # the error to 'hide'
    $h-&gt;set_err(0,"");	# turn off the error
    $_[2] = [ ... ];	# supply alternative return value
    return 1;
  };

This only works for methods which return a single value and is hard
to make reliable (avoiding infinite loops, for example) and so isn't
recommended for general use!  If you find a I&lt;good&gt; use for it then
please let me know.


=item C&lt;ShowErrorStatement&gt; (boolean, inherited) I&lt;NEW&gt;

This attribute can be used to cause the relevant Statement text to be
appended to the error messages generated by the C&lt;RaiseError&gt; and
C&lt;PrintError&gt; attributes. Only applies to errors on statement handles
plus the prepare() and do() database handle methods.
(The exact format of the appended text is subject to change.)


=item C&lt;TraceLevel&gt; (integer, inherited) I&lt;NEW&gt;

This attribute can be used as an alternative to the L&lt;/trace&gt; method
to set the DBI trace level for a specific handle.


=item C&lt;FetchHashKeyName&gt; (string, inherited)

This attribute is used to specify which attribute name the
fetchrow_hashref() method should use to get the field names for the
hash keys. For historical reasons it defaults to 'C&lt;NAME&gt;' but it
is recommended to set it to 'C&lt;NAME_lc&gt;' or 'C&lt;NAME_uc&gt;' according
to your preference. It can only be set for driver and database tables.
For statement handles the value is frozen when prepare() is called.


=item C&lt;ChopBlanks&gt; (boolean, inherited)

This attribute can be used to control the trimming of trailing space
characters from fixed width character (CHAR) fields. No other field
types are affected, even where field values have trailing spaces.

The default is false (although it is possible that the default may change).
Applications that need specific behavior should set the attribute as
needed. Emulation interfaces should set the attribute to match the
behavior of the interface they are emulating.

Drivers are not required to support this attribute, but any driver which
does not support it must arrange to return C&lt;undef&gt; as the attribute value.


=item C&lt;LongReadLen&gt; (unsigned integer, inherited)

This attribute may be used to control the maximum length of long fields
("blob", "memo", etc.) which the driver will read from the
database automatically when it fetches each row of data.  The
C&lt;LongReadLen&gt; 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. (C&lt;fetch&gt;
should return C&lt;undef&gt; for long fields when C&lt;LongReadLen&gt; is 0.)

The default is typically 0 (zero) bytes but may vary between drivers.
Applications fetching long fields should set this value to slightly
larger than the longest long field value to be fetched.

Some databases return some long types encoded as pairs of hex digits.
For these types, C&lt;LongReadLen&gt; relates to the underlying data length and not the
doubled-up length of the encoded string.

Changing the value of C&lt;LongReadLen&gt; for a statement handle after it
has been C&lt;prepare&gt;'d will typically have no effect, so it's common to
set C&lt;LongReadLen&gt; on the C&lt;$dbh&gt; before calling C&lt;prepare&gt;.

Note that the value used here has a direct effect on the memory used
by the application, so don't be too generous.

See L&lt;/LongTruncOk&gt; for more information on truncation behavior.

=item C&lt;LongTruncOk&gt; (boolean, inherited)

This 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&lt;LongReadLen&gt; attribute).

By default, C&lt;LongTruncOk&gt; is false and so fetching a long value that
needs to be truncated will cause the fetch to fail.
(Applications should always be sure to
check for errors after a fetch loop in case an error, such as a divide
by zero or long field truncation, caused the fetch to terminate
prematurely.)

If a fetch fails due to a long field truncation when C&lt;LongTruncOk&gt; is
false, many drivers will allow you to continue fetching further rows.

See also L&lt;/LongReadLen&gt;.

=item C&lt;Taint&gt; (boolean, inherited)

If this attribute is set to a true value I&lt;and&gt; Perl is running in
taint mode (e.g., started with the C&lt;-T&gt; option), then all data
fetched from the database is tainted, and the arguments to most DBI
method calls are checked for being tainted. I&lt;This may change.&gt;

The attribute defaults to off, even if Perl is in taint mode.
See L&lt;perlsec&gt; for more about taint mode.  If Perl is not
running in taint mode, this attribute has no effect.

When fetching data that you trust you can turn off the Taint attribute,
for that statement handle, for the duration of the fetch loop.

Currently only fetched data is tainted. It is possible that the results
of other DBI method calls, and the value of fetched attributes, may
also be tainted in future versions. That change may well break your
applications unless you take great care now. If you use DBI Taint mode,
please report your experience and any suggestions for changes.

=item C&lt;Profile&gt; (inherited)

Enable collection and reporting of method call timing statistics.
See the L&lt;DBI::Profile&gt; module documentation for I&lt;much&gt; more detail.

=item C&lt;private_your_module_name_*&gt;

The DBI provides a way to store extra information in a DBI handle as
"private" attributes. The DBI will allow you to store and retreive any
attribute which has a name starting with "C&lt;private_&gt;".

It is I&lt;strongly&gt; recommended that you use just I&lt;one&gt; private
attribute (e.g., use a hash ref) I&lt;and&gt; give it a long and unambiguous
name that includes the module or application name that the attribute
relates to (e.g., "C&lt;private_YourFullModuleName_thingy&gt;").

Because of the way the Perl tie mechanism works you cannot reliably
use the C&lt;||=&gt; operator directly to initialise the attribute, like this:

  my $foo = $dbh-&gt;{private_yourmodname_foo} ||= { ... }; # WRONG

you should use a two step approach like this:

  my $foo = $dbh-&gt;{private_yourmodname_foo};
  $foo ||= $dbh-&gt;{private_yourmodname_foo} = { ... };


=back


=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:

=over 4

=item C&lt;do&gt;

  $rows = $dbh-&gt;do($statement)           or die $dbh-&gt;errstr;
  $rows = $dbh-&gt;do($statement, \%attr)   or die $dbh-&gt;errstr;
  $rows = $dbh-&gt;do($statement, \%attr, @bind_values) or die ...

Prepare and execute a single statement. Returns the number of rows
affected or C&lt;undef&gt; on error. A return value of C&lt;-1&gt; means the
number of rows is not known, not applicable, or not available.

This method is typically most useful for I&lt;non&gt;-C&lt;SELECT&gt; 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&lt;SELECT&gt; statements because it does not return a statement
handle (so you can't fetch any data).

The default C&lt;do&gt; method is logically similar to:

  sub do {
      my($dbh, $statement, $attr, @bind_values) = @_;
      my $sth = $dbh-&gt;prepare($statement, $attr) or return undef;
      $sth-&gt;execute(@bind_values) or return undef;
      my $rows = $sth-&gt;rows;
      ($rows == 0) ? "0E0" : $rows; # always return true if no error
  }

For example:

  my $rows_deleted = $dbh-&gt;do(q{
      DELETE FROM table
      WHERE status = ?
  }, undef, 'DONE') or die $dbh-&gt;errstr;

Using placeholders and C&lt;@bind_values&gt; with the C&lt;do&gt; method can be
useful because it avoids the need to correctly quote any variables
in the C&lt;$statement&gt;. But if you'll be executing the statement many
times then it's more efficient to C&lt;prepare&gt; it once and call
C&lt;execute&gt; many times instead.

The C&lt;q{...}&gt; style quoting used in this example avoids clashing with
quotes that may be used in the SQL statement. Use the double-quote-like
C&lt;qq{...}&gt; operator if you want to interpolate variables into the string.
See L&lt;perlop/"Quote and Quote-like Operators"&gt; for more details.

=item C&lt;selectrow_array&gt;

  @row_ary = $dbh-&gt;selectrow_array($statement);
  @row_ary = $dbh-&gt;selectrow_array($statement, \%attr);
  @row_ary = $dbh-&gt;selectrow_array($statement, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt; and
L&lt;/fetchrow_array&gt; into a single call. If called in a list context, it
returns the first row of data from the statement. If called in a scalar
context, it returns the first field of the first row. The C&lt;$statement&gt;
parameter can be a previously prepared statement handle, in which case
the C&lt;prepare&gt; is skipped.

If any method fails, and L&lt;/RaiseError&gt; is not set, C&lt;selectrow_array&gt;
will return an empty list.

In a scalar context, C&lt;selectrow_array&gt; returns the value of the first
field. An C&lt;undef&gt; is returned if there are no matching rows or an error
occurred. Since that C&lt;undef&gt; can't be distinguished from an C&lt;undef&gt; returned
because the first field value was NULL, calling C&lt;selectrow_array&gt; in
a scalar context should be used with caution.


=item C&lt;selectrow_arrayref&gt;

  $ary_ref = $dbh-&gt;selectrow_array($statement);
  $ary_ref = $dbh-&gt;selectrow_array($statement, \%attr);
  $ary_ref = $dbh-&gt;selectrow_array($statement, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt; and
L&lt;/fetchrow_arrayref&gt; into a single call. It returns the first row of
data from the statement.  The C&lt;$statement&gt; parameter can be a previously
prepared statement handle, in which case the C&lt;prepare&gt; is skipped.

If any method fails, and L&lt;/RaiseError&gt; is not set, C&lt;selectrow_array&gt;
will return undef.


=item C&lt;selectrow_hashref&gt;

  $hash_ref = $dbh-&gt;selectrow_hashref($statement);
  $hash_ref = $dbh-&gt;selectrow_hashref($statement, \%attr);
  $hash_ref = $dbh-&gt;selectrow_hashref($statement, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt; and
L&lt;/fetchrow_hashref&gt; into a single call. It returns the first row of
data from the statement.  The C&lt;$statement&gt; parameter can be a previously
prepared statement handle, in which case the C&lt;prepare&gt; is skipped.

If any method fails, and L&lt;/RaiseError&gt; is not set, C&lt;selectrow_hashref&gt;
will return undef.


=item C&lt;selectall_arrayref&gt;

  $ary_ref = $dbh-&gt;selectall_arrayref($statement);
  $ary_ref = $dbh-&gt;selectall_arrayref($statement, \%attr);
  $ary_ref = $dbh-&gt;selectall_arrayref($statement, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt; and
L&lt;/fetchall_arrayref&gt; into a single call. It returns a reference to an
array containing a reference to an array for each row of data fetched.

The C&lt;$statement&gt; parameter can be a previously prepared statement handle,
in which case the C&lt;prepare&gt; is skipped. This is recommended if the
statement is going to be executed many times.

If L&lt;/RaiseError&gt; is not set and any method except C&lt;fetchall_arrayref&gt;
fails then C&lt;selectall_arrayref&gt; will return C&lt;undef&gt;; if
C&lt;fetchall_arrayref&gt; fails then it will return with whatever data
has been fetched thus far. You should check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt;
afterwards (or use the C&lt;RaiseError&gt; attribute) to discover if the data is
complete or was truncated due to an error.

The L&lt;/fetchall_arrayref&gt; method called by C&lt;selectall_arrayref&gt;
supports a $slice parameter. You can specify a value for $slice by
including a 'C&lt;Slice&gt;' or 'C&lt;Columns&gt;' attribute in \%attr. The only
difference between the two is that if C&lt;Slice&gt; is not defined and
C&lt;Columns&gt; 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&lt;/fetchall_arrayref&gt;.


=item C&lt;selectall_hashref&gt;

  $hash_ref = $dbh-&gt;selectall_hashref($statement, $key_field);
  $hash_ref = $dbh-&gt;selectall_hashref($statement, $key_field, \%attr);
  $hash_ref = $dbh-&gt;selectall_hashref($statement, $key_field, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt; and
L&lt;/fetchall_hashref&gt; into a single call. It returns a reference to a
hash containing one entry for each row. The key for each row entry is
specified by $key_field. The value is a reference to a hash returned by
C&lt;fetchrow_hashref&gt;.

The C&lt;$statement&gt; parameter can be a previously prepared statement handle,
in which case the C&lt;prepare&gt; is skipped. This is recommended if the
statement is going to be executed many times.

If any method except C&lt;fetchrow_hashref&gt; fails, and L&lt;/RaiseError&gt; is not set,
C&lt;selectall_hashref&gt; will return C&lt;undef&gt;.  If C&lt;fetchrow_hashref&gt; fails and
L&lt;/RaiseError&gt; is not set, then it will return with whatever data it
has fetched thus far. $DBI::err should be checked to catch that.


=item C&lt;selectcol_arrayref&gt;

  $ary_ref = $dbh-&gt;selectcol_arrayref($statement);
  $ary_ref = $dbh-&gt;selectcol_arrayref($statement, \%attr);
  $ary_ref = $dbh-&gt;selectcol_arrayref($statement, \%attr, @bind_values);

This utility method combines L&lt;/prepare&gt;, L&lt;/execute&gt;, 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&lt;$statement&gt; parameter can be a previously prepared statement handle,
in which case the C&lt;prepare&gt; is skipped. This is recommended if the
statement is going to be executed many times.

If any method except C&lt;fetch&gt; fails, and L&lt;/RaiseError&gt; is not set,
C&lt;selectcol_arrayref&gt; will return C&lt;undef&gt;.  If C&lt;fetch&gt; fails and
L&lt;/RaiseError&gt; 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&lt;selectcol_arrayref&gt; 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&lt;Columns&gt;'
attribute which must be a ref to an array containing the column number
or numbers to use. For example:

  # get array of id and name pairs:
  my $ary_ref = $dbh-&gt;selectcol_arrayref("select id, name from table", { Columns=&gt;[1,2] });
  my %hash = @$ary_ref; # build hash from key-value pairs so $hash{$id} =&gt; name


=item C&lt;prepare&gt;

  $sth = $dbh-&gt;prepare($statement)          or die $dbh-&gt;errstr;
  $sth = $dbh-&gt;prepare($statement, \%attr)  or die $dbh-&gt;errstr;

Prepares a single statement for later execution by the database
engine and returns a reference to a statement handle object.

The returned statement handle can be used to get attributes of the
statement and invoke the L&lt;/execute&gt; method. See L&lt;/Statement Handle Methods&gt;.

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&lt;$sth-&gt;E&lt;gt&gt;C&lt;execute&gt; is called. Such drivers are
unlikely to give much useful information about the
statement, such as C&lt;$sth-&gt;E&lt;gt&gt;C&lt;{NUM_OF_FIELDS}&gt;, until after C&lt;$sth-&gt;E&lt;gt&gt;C&lt;execute&gt;
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&lt;/Placeholders&gt;). The statement is
passed directly to the database engine, sometimes known as pass-thru
mode. This has advantages and disadvantages. On the plus side, you can
access all the functionality of the engine being used. On the downside,
you're limited if you're using a simple engine, and you need to take extra care if
writing applications intended to be portable between engines.

Portable applications should not assume that a new statement can be
prepared and/or executed while still fetching results from a previous
statement.

Some command-line SQL tools use statement terminators, like a semicolon,
to indicate the end of a statement. Such terminators should not normally
be used with the DBI.


=item C&lt;prepare_cached&gt;

  $sth = $dbh-&gt;prepare_cached($statement)
  $sth = $dbh-&gt;prepare_cached($statement, \%attr)
  $sth = $dbh-&gt;prepare_cached($statement, \%attr, $allow_active)

Like L&lt;/prepare&gt; except that the statement handle returned will be
stored in a hash associated with the C&lt;$dbh&gt;. If another call is made to
C&lt;prepare_cached&gt; with the same C&lt;$statement&gt; and C&lt;%attr&gt; values, then the
corresponding cached C&lt;$sth&gt; will be returned without contacting the
database server.

Here are some examples of C&lt;prepare_cached&gt;:

  sub insert_hash {
    my ($table, $field_values) = @_;
    my @fields = sort keys %$field_values; # sort required
    my @values = @{$field_values}{@fields};
    my $sql = sprintf "insert into %s (%s) values (%s)",
	$table, join(",", @fields), join(",", ("?")x@fields);
    my $sth = $dbh-&gt;prepare_cached($sql);
    return $sth-&gt;execute(@values);
  }

  sub search_hash {
    my ($table, $field_values) = @_;
    my @fields = sort keys %$field_values; # sort required
    my @values = @{$field_values}{@fields};
    my $qualifier = "";
    $qualifier = "where ".join(" and ", map { "$_=?" } @fields) if @fields;
    $sth = $dbh-&gt;prepare_cached("SELECT * FROM $table $qualifier");
    return $dbh-&gt;selectall_arrayref($sth, {}, @values);
  }

I&lt;Caveat emptor:&gt; This caching can be useful in some applications,
but it can also cause problems and should be used with care. Here
is a contrived case where caching would cause a significant problem:

  my $sth = $dbh-&gt;prepare_cached('SELECT * FROM foo WHERE bar=?');
  $sth-&gt;execute($bar);
  while (my $data = $sth-&gt;fetchrow_hashref) {
    my $sth2 = $dbh-&gt;prepare_cached('SELECT * FROM foo WHERE bar=?');
    $sth2-&gt;execute($data-&gt;{bar});
    while (my $data2 = $sth2-&gt;fetchrow_arrayref) {
      do_stuff(...);
    }
  }

In this example, since both handles are preparing the exact same statement,
C&lt;$sth2&gt; will not be its own statement handle, but a duplicate of C&lt;$sth&gt;
returned from the cache. The results will certainly not be what you expect.
Typically the the inner fetch loop will work normally, fetching all
the records and terminating when there are no more, but now $sth
is the same as $sth2 the outer fetch loop will also terminate.

The C&lt;$allow_active&gt; parameter lets you adjust DBI's behavior when
prepare_cached is returning a statement handle that is still active.
There are three settings:

=over 4

B&lt;0&gt;: A warning will be generated, and C&lt;finish&gt; will be called on
the statement handle before it is returned.  This is the default
behavior if C&lt;$allow_active&gt; is not passed.

B&lt;1&gt;: C&lt;finish&gt; will be called on the statement handle, but the
warning is suppressed.

B&lt;2&gt;: DBI will not touch the statement handle before returning it.
You will need to check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;{Active}&gt; on the returned
statement handle and deal with it in your own code.

=back

Because the cache used by prepare_cached() is keyed by all the
parameters, including any attributes passed, you can also avoid
this issue by doing something like:

  my $sth = $dbh-&gt;prepare_cached("...", { dbi_dummy =&gt; __FILE__.__LINE__ });

which will ensure that prepare_cached only returns statements cached
by that line of code in that source file. 


=item C&lt;commit&gt;

  $rc  = $dbh-&gt;commit     or die $dbh-&gt;errstr;

Commit (make permanent) the most recent series of database changes
if the database supports transactions and AutoCommit is off.

If C&lt;AutoCommit&gt; is on, then calling
C&lt;commit&gt; will issue a "commit ineffective with AutoCommit" warning.

See also L&lt;/Transactions&gt; in the L&lt;/FURTHER INFORMATION&gt; section below.

=item C&lt;rollback&gt;

  $rc  = $dbh-&gt;rollback   or die $dbh-&gt;errstr;

Rollback (undo) the most recent series of uncommitted database
changes if the database supports transactions and AutoCommit is off.

If C&lt;AutoCommit&gt; is on, then calling
C&lt;rollback&gt; will issue a "rollback ineffective with AutoCommit" warning.

See also L&lt;/Transactions&gt; in the L&lt;/FURTHER INFORMATION&gt; section below.

=item C&lt;begin_work&gt;

  $rc  = $dbh-&gt;begin_work   or die $dbh-&gt;errstr;

Enable transactions (by turning C&lt;AutoCommit&gt; off) until the next call
to C&lt;commit&gt; or C&lt;rollback&gt;. After the next C&lt;commit&gt; or C&lt;rollback&gt;,
C&lt;AutoCommit&gt; will automatically be turned on again.

If C&lt;AutoCommit&gt; is already off when C&lt;begin_work&gt; is called then
it does nothing except return an error. If the driver does not support
transactions then when C&lt;begin_work&gt; attempts to set C&lt;AutoCommit&gt; off
the driver will trigger a fatal error.

See also L&lt;/Transactions&gt; in the L&lt;/FURTHER INFORMATION&gt; section below.


=item C&lt;disconnect&gt;

  $rc = $dbh-&gt;disconnect  or warn $dbh-&gt;errstr;

Disconnects the database from the database handle. C&lt;disconnect&gt; is typically only used
before exiting the program. The handle is of little use after disconnecting.

The transaction behavior of the C&lt;disconnect&gt; 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&lt;AutoCommit&gt; should explicitly call C&lt;commit&gt; or C&lt;rollback&gt; before
calling C&lt;disconnect&gt;.

The database is automatically disconnected by the C&lt;DESTROY&gt; method if
still connected when there are no longer any references to the handle.
The C&lt;DESTROY&gt; method for each driver should implicitly call C&lt;rollback&gt; to
undo any uncommitted changes. This is vital behavior to ensure that
incomplete transactions don't get committed simply because Perl calls
C&lt;DESTROY&gt; 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&lt;/commit&gt; or L&lt;/rollback&gt;
before disconnecting.

If you disconnect from a database while you still have active
statement handles (e.g., SELECT statement handles that may have
more data to fetch), you will get a warning. The warning may indicate
that a fetch loop terminated early, perhaps due to an uncaught error.
To avoid the warning call the C&lt;finish&gt; method on the active handles.


=item C&lt;ping&gt;

  $rc = $dbh-&gt;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&lt;default&gt; implementation always returns true without
actually doing anything. Actually, it returns "C&lt;0 but true&gt;" which is
true but zero. That way you can tell if the return value is genuine or
just the default. Drivers should override this method with one that
does the right thing for their type of database.

Few applications would have direct use for this method. See the specialized
Apache::DBI module for one example usage.


=item C&lt;get_info&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $value = $dbh-&gt;get_info( $info_type );

Returns information about the implementation, i.e. driver and data
source capabilities, restrictions etc. It returns C&lt;undef&gt; for
unknown or unimplemented information types. For example:

  $database_version  = $dbh-&gt;get_info(  18 ); # SQL_DBMS_VER
  $max_select_tables = $dbh-&gt;get_info( 106 ); # SQL_MAXIMUM_TABLES_IN_SELECT

See L&lt;/"Standards Reference Information"&gt; for more detailed information
about the information types and their meanings and possible return values.

The DBI curently doesn't provide a name to number mapping for the
information type codes or the results. Applications are expected to use
the integer values directly, with the name in a comment, or define
their own named values using something like the L&lt;constant&gt; pragma.

Because some DBI methods make use of get_info(), drivers are strongly
encouraged to support I&lt;at least&gt; the following very minimal set
of information types to ensure the DBI itself works properly:

 Type  Name                        Example A     Example B
 ----  --------------------------  ------------  ------------
   17  SQL_DBMS_NAME               'ACCESS'      'Oracle'
   18  SQL_DBMS_VER                '03.50.0000'  '08.01.0721'
   29  SQL_IDENTIFIER_QUOTE_CHAR   '`'           '"'
   41  SQL_CATALOG_NAME_SEPARATOR  '.'           '@'
  114  SQL_CATALOG_LOCATION        1             2


=item C&lt;table_info&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $sth = $dbh-&gt;table_info( $catalog, $schema, $table, $type );
  $sth = $dbh-&gt;table_info( $catalog, $schema, $table, $type, \%attr );
  $sth = $dbh-&gt;table_info( \%attr ); # old style

Returns an active statement handle that can be used to fetch
information about tables and views that exist in the database.

The old style interface passes all the parameters as a reference
to an attribute hash with some or all of the following attributes:

  %attr = (
       TABLE_CAT   =&gt; $catalog  # String value of the catalog name
     , TABLE_SCHEM =&gt; $schema   # String value of the schema name
     , TABLE_NAME  =&gt; $table    # String value of the table name
     , TABLE_TYPE  =&gt; $type     # String value of the table type(s)
  );

The old style interface is deprecated and will be removed in a future version.

The support for the selection criteria is driver specific. If the
driver doesn't support one or more of them then you may get back more
than you asked for and can do the filtering yourself.

The arguments $catalog, $schema and $table may accept search patterns
according to the database/driver, for example: $table = '%FOO%';
Remember that the underscore character ('C&lt;_&gt;') is a search pattern
that means match any character, so 'FOO_%' is the same as 'FOO%'
and 'FOO_BAR%' will match names like 'FOO1BAR'.

The value of $type is a comma-separated list of one or more types of
tables to be returned in the result set. Each value may optionally be
quoted, e.g.:

  $type = "TABLE";
  $type = "'TABLE','VIEW'";

In addition the following special cases may also be supported by some drivers:

=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-&gt;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

The statement handle returned has at least the following fields in the
order show below. Other fields, after these, may also be present.

B&lt;TABLE_CAT&gt;: Table catalog identifier. This field is NULL (C&lt;undef&gt;) if not
applicable to the data source, which is usually the case. This field
is empty if not applicable to the table.

B&lt;TABLE_SCHEM&gt;: The name of the schema containing the TABLE_NAME value.
This field is NULL (C&lt;undef&gt;) if not applicable to data source, and
empty if not applicable to the table.

B&lt;TABLE_NAME&gt;: Name of the table (or view, synonym, etc).

B&lt;TABLE_TYPE&gt;: 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&lt;REMARKS&gt;: A description of the table. May be NULL (C&lt;undef&gt;).

Note that C&lt;table_info&gt; might not return records for all tables.
Applications can use any valid table regardless of whether it's
returned by C&lt;table_info&gt;.

See also L&lt;/tables&gt;, L&lt;/"Catalog Methods"&gt; and
L&lt;/"Standards Reference Information"&gt;.

=item C&lt;column_info&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $sth = $dbh-&gt;column_info( $catalog, $schema, $table, $column );

Returns an active statement handle that can be used to fetch
information about columns in specified tables.

The arguments $schema, $table and $column may accept search patterns
according to the database/driver, for example: $table = '%FOO%';

Note: The support for the selection criteria is driver specific. If the
driver doesn't support one or more of them then you may get back more
than you asked for and can do the filtering yourself.

The statement handle returned has at least the following fields in the
order shown below. Other fields, after these, may also be present.

B&lt;TABLE_CAT&gt;: The catalog identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.

B&lt;TABLE_SCHEM&gt;: The schema identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
and empty if not applicable to the table.

B&lt;TABLE_NAME&gt;: The table identifier.
Note: A driver may provide column metadata not only for base tables, but
also for derived objects like SYNONYMS etc.

B&lt;COLUMN_NAME&gt;: The column identifier.

B&lt;DATA_TYPE&gt;: The concise data type code.

B&lt;TYPE_NAME&gt;: A data source dependent data type name.

B&lt;COLUMN_SIZE&gt;: 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&lt;BUFFER_LENGTH&gt;: The length in bytes of transferred data.

B&lt;DECIMAL_DIGITS&gt;: The total number of significant digits to the right of
the decimal point.

B&lt;NUM_PREC_RADIX&gt;: The radix for numeric precision.
The value is 10 or 2 for numeric data types and NULL (C&lt;undef&gt;) if not
applicable.

B&lt;NULLABLE&gt;: Indicates if a column can accept NULLs.
The following values are defined:

  SQL_NO_NULLS          0
  SQL_NULLABLE          1
  SQL_NULLABLE_UNKNOWN  2

B&lt;REMARKS&gt;: A description of the column.

B&lt;COLUMN_DEF&gt;: The default value of the column.

B&lt;SQL_DATA_TYPE&gt;: The SQL data type.

B&lt;SQL_DATETIME_SUB&gt;: The subtype code for datetime and interval data types.

B&lt;CHAR_OCTET_LENGTH&gt;: The maximum length in bytes of a character or binary
data type column.

B&lt;ORDINAL_POSITION&gt;: The column sequence number (starting with 1).

B&lt;IS_NULLABLE&gt;: Indicates if the column can accept NULLs.
Possible values are: 'NO', 'YES' and ''.

SQL/CLI defines the following additional columns:

  CHAR_SET_CAT
  CHAR_SET_SCHEM
  CHAR_SET_NAME
  COLLATION_CAT
  COLLATION_SCHEM
  COLLATION_NAME
  UDT_CAT
  UDT_SCHEM
  UDT_NAME
  DOMAIN_CAT
  DOMAIN_SCHEM
  DOMAIN_NAME
  SCOPE_CAT
  SCOPE_SCHEM
  SCOPE_NAME
  MAX_CARDINALITY
  DTD_IDENTIFIER
  IS_SELF_REF

Drivers capable of supplying any of those values should do so in
the corresponding column and supply undef values for the others.

Drivers wishing to provide extra database/driver specific information
should do so in extra columns beyond all those listed above, and
use lowercase field names with the driver-specific prefix (i.e.,
'ora_...'). Applications accessing such fields should do so by name
and not by column number.

The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME
and ORDINAL_POSITION.

Note: There is some overlap with statement attributes (in perl) and
SQLDescribeCol (in ODBC). However, SQLColumns provides more metadata.

See also L&lt;/"Catalog Methods"&gt; and L&lt;/"Standards Reference Information"&gt;.

=item C&lt;primary_key_info&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $sth = $dbh-&gt;primary_key_info( $catalog, $schema, $table );

Returns an active statement handle that can be used to fetch information
about columns that make up the primary key for a table.
The arguments don't accept search patterns (unlike table_info()).

For example:

  $sth = $dbh-&gt;primary_key_info( undef, $user, 'foo' );
  $data = $sth-&gt;fetchall_arrayref;

Note: The support for the selection criteria, such as $catalog, is
driver specific.  If the driver doesn't support catalogs and/or
schemas, it may ignore these criteria.

The statement handle returned has at least the following fields in the
order shown below. Other fields, after these, may also be present.

B&lt;TABLE_CAT&gt;: The catalog identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.

B&lt;TABLE_SCHEM&gt;: The schema identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
and empty if not applicable to the table.

B&lt;TABLE_NAME&gt;: The table identifier.

B&lt;COLUMN_NAME&gt;: The column identifier.

B&lt;KEY_SEQ&gt;: The column sequence number (starting with 1).
Note: This field is named B&lt;ORDINAL_POSITION&gt; in SQL/CLI.

B&lt;PK_NAME&gt;: The primary key constraint identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source.

See also L&lt;/"Catalog Methods"&gt; and L&lt;/"Standards Reference Information"&gt;.

=item C&lt;primary_key&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  @key_column_names = $dbh-&gt;primary_key( $catalog, $schema, $table );

Simple interface to the primary_key_info() method. Returns a list of
the column names that comprise the primary key of the specified table.
The list is in primary key column sequence order.


=item C&lt;foreign_key_info&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $sth = $dbh-&gt;foreign_key_info( $pk_catalog, $pk_schema, $pk_table
                               , $fk_catalog, $fk_schema, $fk_table );

Returns an active statement handle that can be used to fetch information
about foreign keys in and/or referencing the specified table(s).
The arguments don't accept search patterns (unlike table_info()).

C&lt;$pk_catalog&gt;, C&lt;$pk_schema&gt;, C&lt;$pk_table&gt;
identify the primary (unique) key table (B&lt;PKT&gt;).

C&lt;$fk_catalog&gt;, C&lt;$fk_schema&gt;, C&lt;$fk_table&gt;
identify the foreign key table (B&lt;FKT&gt;).

If both B&lt;PKT&gt; and B&lt;FKT&gt; are given, the function returns the foreign key, if
any, in table B&lt;FKT&gt; that refers to the primary (unique) key of table B&lt;PKT&gt;.
(Note: In SQL/CLI, the result is implementation-defined.)

If only B&lt;PKT&gt; is given, then the result set contains the primary key
of that table and all foreign keys that refer to it.

If only B&lt;FKT&gt; is given, then the result set contains all foreign keys
in that table and the primary keys to which they refer.
(Note: In SQL/CLI, the result includes unique keys too.)

For example:

  $sth = $dbh-&gt;foreign_key_info( undef, $user, 'master');
  $sth = $dbh-&gt;foreign_key_info( undef, undef,   undef , undef, $user, 'detail');
  $sth = $dbh-&gt;foreign_key_info( undef, $user, 'master', undef, $user, 'detail');

Note: The support for the selection criteria, such as C&lt;$catalog&gt;, is
driver specific.  If the driver doesn't support catalogs and/or
schemas, it may ignore these criteria.

The statement handle returned has the following fields in the order shown below.
Because ODBC never includes unique keys, they define different columns in the
result set than SQL/CLI. SQL/CLI column names are shown in parentheses.

B&lt;PKTABLE_CAT    ( UK_TABLE_CAT      )&gt;:
The primary (unique) key table catalog identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.

B&lt;PKTABLE_SCHEM  ( UK_TABLE_SCHEM    )&gt;:
The primary (unique) key table schema identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
and empty if not applicable to the table.

B&lt;PKTABLE_NAME   ( UK_TABLE_NAME     )&gt;:
The primary (unique) key table identifier.

B&lt;PKCOLUMN_NAME  (UK_COLUMN_NAME    )&gt;:
The primary (unique) key column identifier.

B&lt;FKTABLE_CAT    ( FK_TABLE_CAT      )&gt;:
The foreign key table catalog identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.

B&lt;FKTABLE_SCHEM  ( FK_TABLE_SCHEM    )&gt;:
The foreign key table schema identifier.
This field is NULL (C&lt;undef&gt;) if not applicable to the data source,
and empty if not applicable to the table.

B&lt;FKTABLE_NAME   ( FK_TABLE_NAME     )&gt;:
The foreign key table identifier.

B&lt;FKCOLUMN_NAME  ( FK_COLUMN_NAME    )&gt;:
The foreign key column identifier.

B&lt;KEY_SEQ        ( ORDINAL_POSITION  )&gt;:
The column sequence number (starting with 1).

B&lt;UPDATE_RULE    ( UPDATE_RULE       )&gt;:
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&lt;DELETE_RULE    ( DELETE_RULE       )&gt;:
The referential action for the DELETE rule.
The codes are the same as for UPDATE_RULE.

B&lt;FK_NAME        ( FK_NAME           )&gt;:
The foreign key name.

B&lt;PK_NAME        ( UK_NAME           )&gt;:
The primary (unique) key name.

B&lt;DEFERRABILITY  ( DEFERABILITY      )&gt;:
The deferrability of the foreign key constraint.
The following codes are defined:

  INITIALLY DEFERRED   5
  INITIALLY IMMEDIATE  6
  NOT DEFERRABLE       7

B&lt;               ( UNIQUE_OR_PRIMARY )&gt;:
This column is necessary if a driver includes all candidate (i.e. primary and
alternate) keys in the result set (as specified by SQL/CLI).
The value of this column is UNIQUE if the foreign key references an alternate
key and PRIMARY if the foreign key references a primary key, or it
may be undefined if the driver doesn't have access to the information.

See also L&lt;/"Catalog Methods"&gt; and L&lt;/"Standards Reference Information"&gt;.


=item C&lt;tables&gt; I&lt;NEW&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  @names = $dbh-&gt;tables( $catalog, $schema, $table, $type );
  @names = $dbh-&gt;tables;	# deprecated

Simple interface to table_info(). Returns a list of matching
table names, possibly including a catalog/schema prefix.

See L&lt;/table_info&gt; for a description of the parameters.

If C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;get_info(29)&gt; returns true (29 is SQL_IDENTIFIER_QUOTE_CHAR)
then the table names are constructed and quoted by L&lt;/quote_identifier&gt;
to ensure they are usable even if they contain whitespace or reserved
words etc.


=item C&lt;type_info_all&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  $type_info_all = $dbh-&gt;type_info_all;

Returns a reference to an array which holds information about each data
type variant supported by the database and driver. The array and its
contents should be treated as read-only.

The first item is a reference to an 'index' hash of C&lt;Name =&gt;E&lt;gt&gt; C&lt;Index&gt; pairs.
The items following that are references to arrays, one per supported data
type variant. The leading index hash defines the names and order of the
fields within the arrays that follow it.
For example:

  $type_info_all = [
    {   TYPE_NAME         =&gt; 0,
	DATA_TYPE         =&gt; 1,
	COLUMN_SIZE       =&gt; 2,     # was PRECISION originally
	LITERAL_PREFIX    =&gt; 3,
	LITERAL_SUFFIX    =&gt; 4,
	CREATE_PARAMS     =&gt; 5,
	NULLABLE          =&gt; 6,
	CASE_SENSITIVE    =&gt; 7,
	SEARCHABLE        =&gt; 8,
	UNSIGNED_ATTRIBUTE=&gt; 9,
	FIXED_PREC_SCALE  =&gt; 10,    # was MONEY originally
	AUTO_UNIQUE_VALUE =&gt; 11,    # was AUTO_INCREMENT originally
	LOCAL_TYPE_NAME   =&gt; 12,
	MINIMUM_SCALE     =&gt; 13,
	MAXIMUM_SCALE     =&gt; 14,
	NUM_PREC_RADIX    =&gt; 15,
    },
    [ 'VARCHAR', SQL_VARCHAR,
	undef, "'","'", undef,0, 1,1,0,0,0,undef,1,255, undef
    ],
    [ 'INTEGER', SQL_INTEGER,
	undef,  "", "", undef,0, 0,1,0,0,0,undef,0,  0, 10
    ],
  ];

Note that more than one row may have the same value in the C&lt;DATA_TYPE&gt;
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&lt;AUTO_UNIQUE_VALUE&gt; set, with and without C&lt;UNSIGNED_ATTRIBUTE&gt;, etc).

The rows are ordered by C&lt;DATA_TYPE&gt; 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&lt;/type_info&gt; method. The index values shown above (e.g.,
C&lt;NULLABLE =&gt;E&lt;gt&gt; C&lt;6&gt;) are for illustration only. Drivers may define the
fields with a different order.

This method is not normally used directly. The L&lt;/type_info&gt; method
provides a more useful interface to the data.

Even though an 'index' hash is provided, all the field names in the
index hash defined above will always have the index values defined
above.  This is defined behaviour so that you don't need to rely on the
index hash, which is handy because the lettercase of the keys is not
defined. It is usually uppercase, as show here, but drivers are free to
return names with any lettercase. Drivers are also free to return extra
driver-specific columns of information - though it's recommended that
they start at column index 50 to leave room for expansion of the
DBI/ODBC specification.


=item C&lt;type_info&gt;

B&lt;Warning:&gt; This method is experimental and may change.

  @type_info = $dbh-&gt;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&lt;DATA_TYPE&gt; 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&lt;SQL_ALL_TYPES&gt;, 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&lt;type_info&gt; returns the
information for the I&lt;first&gt; 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&lt;/Naming Conventions and Name Space&gt;). The
following items should exist:

=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 COLUMN_SIZE (integer)

For numeric types, this is either the total number of digits (if the
NUM_PREC_RADIX value is 10) or the total number of bits allowed in the
column (if NUM_PREC_RADIX is 2).

For string types, this is the maximum size of the string in bytes.

For date and interval types, this is the maximum number of characters
needed to display the value.

=item LITERAL_PREFIX (string)

Characters used to prefix a literal. A typical prefix is "C&lt;'&gt;" for characters,
or possibly "C&lt;0x&gt;" for binary values passed as hexadecimal.  NULL (C&lt;undef&gt;) is
returned for data types for which this is not applicable.


=item LITERAL_SUFFIX (string)

Characters used to suffix a literal. Typically "C&lt;'&gt;" for characters.
NULL (C&lt;undef&gt;) is returned for data types where this is not applicable.

=item CREATE_PARAMS (string)

Parameter names for data type definition. For example, C&lt;CREATE_PARAMS&gt; for a
C&lt;DECIMAL&gt; would be "C&lt;precision,scale&gt;" if the DECIMAL type should be
declared as C&lt;DECIMAL(&gt;I&lt;precision,scale&gt;C&lt;)&gt; where I&lt;precision&gt; and I&lt;scale&gt;
are integer values.  For a C&lt;VARCHAR&gt; it would be "C&lt;max length&gt;".
NULL (C&lt;undef&gt;) is returned for data types for which this is not applicable.

=item NULLABLE (integer)

Indicates whether the data type accepts a NULL value:
C&lt;0&gt; or an empty string = no, C&lt;1&gt; = yes, C&lt;2&gt; = 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&lt;undef&gt;) 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&lt;undef&gt;) 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&lt;undef&gt;) is returned
for data types for which this is not applicable.

=item LOCAL_TYPE_NAME (string)

Localized version of the C&lt;TYPE_NAME&gt; for use in dialog with users.
NULL (C&lt;undef&gt;) is returned if a localized name is not available (in which
case C&lt;TYPE_NAME&gt; should be used).

=item MINIMUM_SCALE (integer)

The minimum scale of the data type. If a data type has a fixed scale,
then C&lt;MAXIMUM_SCALE&gt; holds the same value.  NULL (C&lt;undef&gt;) 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&lt;MINIMUM_SCALE&gt; holds the same value.  NULL (C&lt;undef&gt;) is returned for
data types for which this is not applicable.

=item SQL_DATA_TYPE (integer)

This column is the same as the C&lt;DATA_TYPE&gt; column, except for interval
and datetime data types.  For interval and datetime data types, the
C&lt;SQL_DATA_TYPE&gt; field will return C&lt;SQL_INTERVAL&gt; or C&lt;SQL_DATETIME&gt;, and the
C&lt;SQL_DATETIME_SUB&gt; 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 date subtypes.

=item SQL_DATETIME_SUB (integer)

For interval or datetime data types, where the C&lt;SQL_DATA_TYPE&gt; field
above is C&lt;SQL_INTERVAL&gt; or C&lt;SQL_DATETIME&gt;, this field will hold the subcode
for the specific interval or datetime data type. Otherwise it will be
NULL (C&lt;undef&gt;).

=item NUM_PREC_RADIX (integer)

The radix value of the data type. For approximate numeric types,
C&lt;NUM_PREC_RADIX&gt;
contains the value 2 and C&lt;COLUMN_SIZE&gt; holds the number of bits. For
exact numeric types, C&lt;NUM_PREC_RADIX&gt; contains the value 10 and C&lt;COLUMN_SIZE&gt; holds
the number of decimal digits. NULL (C&lt;undef&gt;) 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

For example, to find the type name for the fields in a select statement
you can do:

  @names = map { scalar $dbh-&gt;type_info($_)-&gt;{TYPE_NAME} } @{ $sth-&gt;{TYPE} }

Since DBI and ODBC drivers vary in how they map their types into the
ISO standard types you may need to search for more than one type.
Here's an example looking for a usable type to store a date:

  $my_date_type = $dbh-&gt;type_info( [ SQL_DATE, SQL_TIMESTAMP ] );

Similarly, to more reliably find a type to store small integers, you could
use a list starting with C&lt;SQL_SMALLINT&gt;, C&lt;SQL_INTEGER&gt;, C&lt;SQL_DECIMAL&gt;, etc.

See also L&lt;/"Standards Reference Information"&gt;.


=item C&lt;quote&gt;

  $sql = $dbh-&gt;quote($value);
  $sql = $dbh-&gt;quote($value, $data_type);

Quote a string literal for use as a literal value in an SQL statement,
by escaping any special characters (such as quotation marks)
contained within the string and adding the required type of outer
quotation marks.

  $sql = sprintf "SELECT foo FROM bar WHERE baz = %s",
                $dbh-&gt;quote("Don't");

For most database types, quote would return C&lt;'Don''t'&gt; (including the
outer quotation marks).

An undefined C&lt;$value&gt; value will be returned as the string C&lt;NULL&gt; (without
single quotation marks) to match how NULLs are represented in SQL.

If C&lt;$data_type&gt; is supplied, it is used to try to determine the required
quoting behavior by using the information returned by L&lt;/type_info&gt;.
As a special case, the standard numeric types are optimized to return
C&lt;$value&gt; without calling C&lt;type_info&gt;.

Quote will probably I&lt;not&gt; be able to deal with all possible input
(such as binary data or data containing newlines), and is not related in
any way with escaping or quoting shell meta-characters. There is no
need to quote values being used with L&lt;/"Placeholders and Bind Values"&gt;.

=item C&lt;quote_identifier&gt;

  $sql = $dbh-&gt;quote_identifier( $name );
  $sql = $dbh-&gt;quote_identifier( $name1, $name2, $name3, \%attr );

Quote an identifier (table name etc.) for use in an SQL statement,
by escaping any special characters (such as double quotation marks)
it contains and adding the required type of outer quotation marks.

Undefined names are ignored and the remainder are quoted and then
joined together, typically with a dot (C&lt;.&gt;) character. For example:

  $id = $dbh-&gt;quote_identifier( undef, 'Her schema', 'My table' );

would, for most database types, return C&lt;"Her schema"."My table"&gt;
(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&lt;/get_info&gt;
returns for SQL_CATALOG_NAME_SEPARATOR (41) and SQL_CATALOG_LOCATION (114).
For example, for Oracle:

  $id = $dbh-&gt;quote_identifier( 'link', 'schema', 'table' );

would return C&lt;"schema"."table"@"link"&gt;.

=back


=head2 Database Handle Attributes

This section describes attributes specific to database handles.

Changes to these database handle attributes do not affect any other
existing or future database handles.

Attempting to set or get the value of an unknown attribute is fatal,
except for private driver-specific attributes (which all have names
starting with a lowercase letter).

Example:

  $h-&gt;{AutoCommit} = ...;	# set/write
  ... = $h-&gt;{AutoCommit};	# get/read

=over 4

=item C&lt;AutoCommit&gt;  (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&lt;commit&gt; or C&lt;rollback&gt;
methods.

Drivers should always default to C&lt;AutoCommit&gt; mode (an unfortunate
choice largely forced on the DBI by ODBC and JDBC conventions.)

Attempting to set C&lt;AutoCommit&gt; to an unsupported value is a fatal error.
This is an important feature of the DBI. Applications that need
full transaction behavior can set C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;{AutoCommit} = 0&gt; (or
set C&lt;AutoCommit&gt; to 0 via L&lt;/connect&gt;)
without having to check that the value was assigned successfully.

For the purposes of this description, we can divide databases into three
categories:

  Databases which don't support transactions at all.
  Databases in which a transaction is always active.
  Databases in which a transaction must be explicitly started (C&lt;'BEGIN WORK'&gt;).

B&lt;* Databases which don't support transactions at all&gt;

For these databases, attempting to turn C&lt;AutoCommit&gt; off is a fatal error.
C&lt;commit&gt; and C&lt;rollback&gt; both issue warnings about being ineffective while
C&lt;AutoCommit&gt; is in effect.

B&lt;* Databases in which a transaction is always active&gt;

These are typically mainstream commercial relational databases with
"ANSI standard" transaction behavior.
If C&lt;AutoCommit&gt; is off, then changes to the database won't have any
lasting effect unless L&lt;/commit&gt; is called (but see also
L&lt;/disconnect&gt;). If L&lt;/rollback&gt; is called then any changes since the
last commit are undone.

If C&lt;AutoCommit&gt; is on, then the effect is the same as if the DBI
called C&lt;commit&gt; automatically after every successful database
operation. So calling C&lt;commit&gt; or C&lt;rollback&gt; explicitly while
C&lt;AutoCommit&gt; is on would be ineffective because the changes would
have already been commited.

Changing C&lt;AutoCommit&gt; from off to on will trigger a L&lt;/commit&gt;.

For databases which don't support a specific auto-commit mode, the
driver has to commit each statement automatically using an explicit
C&lt;COMMIT&gt; after it completes successfully (and roll it back using an
explicit C&lt;ROLLBACK&gt; 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&lt;* Databases in which a transaction must be explicitly started&gt;

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&lt;AutoCommit&gt; is turned off, or after a L&lt;/commit&gt; or
L&lt;/rollback&gt; (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&lt;/commit&gt;, L&lt;/disconnect&gt; and L&lt;/Transactions&gt; for other important
notes about transactions.


=item C&lt;Driver&gt;  (handle)

Holds the handle of the parent driver. The only recommended use for this
is to find the name of the driver using:

  $dbh-&gt;{Driver}-&gt;{Name}


=item C&lt;Name&gt;  (string)

Holds the "name" of the database. Usually (and recommended to be) the
same as the "C&lt;dbi:DriverName:...&gt;" string used to connect to the database,
but with the leading "C&lt;dbi:DriverName:&gt;" removed.


=item C&lt;Statement&gt;  (string, read-only)

Returns the statement string passed to the most recent L&lt;/prepare&gt; method
called in this database handle, even if that method failed. This is especially
useful where C&lt;RaiseError&gt; is enabled and the exception handler checks $@
and sees that a 'prepare' method call failed.


=item C&lt;RowCacheSize&gt;  (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&lt;SELECT&gt; statements.
If a row cache is not implemented, then setting C&lt;RowCacheSize&gt; is ignored
and getting the value returns C&lt;undef&gt;.

Some C&lt;RowCacheSize&gt; values have special meaning, as follows:

  0 - Automatically determine a reasonable cache size for each C&lt;SELECT&gt;
  1 - Disable the local row cache
 &gt;1 - Cache this many rows
 &lt;0 - Cache as many rows that will fit into this much memory for each C&lt;SELECT&gt;.

Note that large cache sizes may require a very large amount of memory
(I&lt;cached rows * maximum size of row&gt;). 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&lt;/RowsInCache&gt; statement handle attribute.

=back


=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:

=over 4

=item C&lt;bind_param&gt;

  $rc = $sth-&gt;bind_param($p_num, $bind_value)  or die $sth-&gt;errstr;
  $rv = $sth-&gt;bind_param($p_num, $bind_value, \%attr)     or ...
  $rv = $sth-&gt;bind_param($p_num, $bind_value, $bind_type) or ...

The C&lt;bind_param&gt; method can be used to bind a value
with a placeholder embedded in the prepared statement. Placeholders
are indicated with question mark character (C&lt;?&gt;). For example:

  $dbh-&gt;{RaiseError} = 1;        # save having to check each method call
  $sth = $dbh-&gt;prepare("SELECT name, age FROM people WHERE name LIKE ?");
  $sth-&gt;bind_param(1, "John%");  # placeholders are numbered from 1
  $sth-&gt;execute;
  DBI::dump_results($sth);

Note that the C&lt;?&gt; is not enclosed in quotation marks, even when the
placeholder represents a string.  Some drivers also allow placeholders
like C&lt;:&gt;I&lt;name&gt; and C&lt;:&gt;I&lt;n&gt; (e.g., C&lt;:1&gt;, C&lt;:2&gt;, and so on)
in addition to C&lt;?&gt;, but their use
is not portable.  Undefined bind values or C&lt;undef&gt; can be used to
indicate null values.

Some drivers do not support placeholders.

With most drivers, placeholders can't be used for any element of a
statement that would prevent the database server from validating the
statement and creating a query execution plan for it. For example:

  "SELECT name, age FROM ?"         # wrong (will probably fail)
  "SELECT name, ?   FROM people"    # wrong (but may not 'fail')

Also, placeholders can only represent single scalar values.
For example, the following
statement won't work as expected for more than one value:

  "SELECT name, age FROM people WHERE name IN (?)"    # wrong

B&lt;Data Types for Placeholders&gt;

The C&lt;\%attr&gt; parameter can be used to hint at the data type the
placeholder should have. Typically, the driver is only interested in
knowing if the placeholder should be bound as a number or a string.

  $sth-&gt;bind_param(1, $value, { TYPE =&gt; SQL_INTEGER });

As a short-cut for this common case, the data type can be passed
directly, in place of the C&lt;\%attr&gt; hash reference. This example is
equivalent to the one above:

  $sth-&gt;bind_param(1, $value, SQL_INTEGER);

The C&lt;TYPE&gt; 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&lt;{ ora_type =&gt;E&lt;gt&gt;C&lt; 97 }&gt;.  The
data type for a placeholder cannot be changed after the first
C&lt;bind_param&gt; call. However, it can be left unspecified, in which case it
defaults to the previous value.

The SQL_INTEGER and other related constants can be imported using

  use DBI qw(:sql_types);

See L&lt;/"DBI Constants"&gt; for more information.

Perl only has string and number scalar data types. All database types
that aren't numbers are bound as strings and must be in a format the
database will understand.

As an alternative to specifying the data type in the C&lt;bind_param&gt; call,
you can let the driver pass the value as the default type (C&lt;VARCHAR&gt;).
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&lt;CONVERT&gt; function used here is just an example. The actual function
and syntax will vary between different databases and is non-portable.

See also L&lt;/"Placeholders and Bind Values"&gt; for more information.


=item C&lt;bind_param_inout&gt;

  $rc = $sth-&gt;bind_param_inout($p_num, \$bind_value, $max_len)  or die $sth-&gt;errstr;
  $rv = $sth-&gt;bind_param_inout($p_num, \$bind_value, $max_len, \%attr)     or ...
  $rv = $sth-&gt;bind_param_inout($p_num, \$bind_value, $max_len, $bind_type) or ...

This method acts like L&lt;/bind_param&gt;, but also enables values to be
updated by the statement. The statement is typically
a call to a stored procedure. The C&lt;$bind_value&gt; must be passed as a
reference to the actual value to be used.

Note that unlike L&lt;/bind_param&gt;, the C&lt;$bind_value&gt; variable is not
read when C&lt;bind_param_inout&gt; is called. Instead, the value in the
variable is read at the time L&lt;/execute&gt; is called.

The additional C&lt;$max_len&gt; parameter specifies the minimum amount of
memory to allocate to C&lt;$bind_value&gt; for the new value. If the value
returned from the database is too
big to fit, then the execution should fail. If unsure what value to use,
pick a generous length, i.e., a length larger than the longest value that would ever be
returned.  The only cost of using a larger value than needed is wasted memory.

It is expected that few drivers will support this method. The only
driver currently known to do so is DBD::Oracle (DBD::ODBC may support
it in a future release). Therefore it should not be used for database
independent applications.

Undefined values or C&lt;undef&gt; are used to indicate null values.
See also L&lt;/"Placeholders and Bind Values"&gt; for more information.


=item C&lt;bind_param_array&gt;

  $rc = $sth-&gt;bind_param_array($p_num, $array_ref_or_value)
  $rc = $sth-&gt;bind_param_array($p_num, $array_ref_or_value, \%attr)
  $rc = $sth-&gt;bind_param_array($p_num, $array_ref_or_value, $bind_type)

The C&lt;bind_param_array&gt; method is used to bind an array of values
to a placeholder embedded in the prepared statement which is to be executed
with L&lt;/execute_array&gt;. For example:

  $dbh-&gt;{RaiseError} = 1;        # save having to check each method call
  $sth = $dbh-&gt;prepare("INSERT INTO people(first_name, last_name) VALUES(?, ?)");
  $sth-&gt;bind_param_array(1, [ 'John', 'Mary', 'Tim' ]);
  $sth-&gt;bind_param_array(2, [ 'Booth', 'Todd', 'Robinson' ]);
  my @tuple_status;
  $sth-&gt;execute_array(\@tuple_status);

The C&lt;%attr&gt; argument is the same as defined for L&lt;/bind_param&gt;.
Refer to L&lt;/bind_param&gt; for general details on using placeholders.

Each array bound to the statement must have the same number of
elements.  Some drivers may define a method attribute to relax this
safety check.

Scalar values, including C&lt;undef&gt;, may also be bound by
C&lt;bind_param_array&gt;. In which case the same value will be used for each
L&lt;/execute&gt; call. Driver-specific implementations may behave
differently, e.g., when binding to a stored procedure call, some
databases permit mixing scalars and arrays as arguments.

The default implementation provided by DBI (for drivers that have
not implemented array binding) is to iteratively L&lt;/execute&gt; for
each parameter tuple provided in the bound arrays.  Drivers may
provide more optimized implementations using whatever bulk operation
support the database API provides. The default driver behaviour should 
match the default DBI behaviour, but always consult your driver
documentation as there may be driver specific issues to consider.

Note that the default implementation currently only supports non-data
returning statements. Also, C&lt;bind_param_array&gt; and L&lt;/bind_param&gt;
cannot be mixed in the same statement execution, and C&lt;bind_param_array&gt;
must be used with L&lt;/execute_array&gt;; using C&lt;bind_param_array&gt; will
have no effect for L&lt;/execute&gt;.


=item C&lt;execute&gt;

  $rv = $sth-&gt;execute                or die $sth-&gt;errstr;
  $rv = $sth-&gt;execute(@bind_values)  or die $sth-&gt;errstr;

Perform whatever processing is necessary to execute the prepared
statement.  An C&lt;undef&gt; is returned if an error occurs.  A successful
C&lt;execute&gt; 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&lt;execute&gt; (and most other DBI methods) for errors.

For a I&lt;non&gt;-C&lt;SELECT&gt; statement, C&lt;execute&gt; returns the number of rows
affected, if known. If no rows were affected, then C&lt;execute&gt; returns
"C&lt;0E0&gt;", which Perl will treat as 0 but will regard as true. Note that it
is I&lt;not&gt; an error for no rows to be affected by a statement. If the
number of rows affected is not known, then C&lt;execute&gt; returns -1.

For C&lt;SELECT&gt; statements, execute simply "starts" the query within the
database engine. Use one of the fetch methods to retreive the data after
calling C&lt;execute&gt;.  The C&lt;execute&gt; method does I&lt;not&gt; 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.

If any arguments are given, then C&lt;execute&gt; will effectively call
L&lt;/bind_param&gt; for each value before executing the statement.
Values bound in this way are usually treated as C&lt;SQL_VARCHAR&gt; types
unless the driver can determine the correct type (which is rare), or
unless
C&lt;bind_param&gt; (or C&lt;bind_param_inout&gt;) has already been used to specify the
type.


=item C&lt;execute_array&gt;

  $rv = $sth-&gt;execute_array(\%attr) or die $sth-&gt;errstr;
  $rv = $sth-&gt;execute_array(\%attr, @bind_values)  or die $sth-&gt;errstr;

Execute the prepared statement for each parameter tuple provided
either in the @bind_values, or by prior calls to L&lt;/bind_param_array&gt;.

An C&lt;undef&gt; is returned if an error occurs.  A successful
C&lt;execute_array&gt; 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&lt;execute_array&gt; (and most other DBI
methods) for errors.

Parameters may be supplied either by prior calls to L&lt;/bind_param_array&gt;,
or in the C&lt;@bind_values&gt; argument. The values supplied may be either
scalars, or arrayrefs. See L&lt;/bind_param_array&gt; for details.

The supplied C&lt;\%attr&gt; hashref currently supports only the C&lt;ArrayTupleStatus&gt;
attribute, which should specify an arrayref to receive the status of each
parameter tuple bound to the statement. For parameter tuples which
are successfully executed, the element at the same ordinal position in the 
status array will return the resulting rowcount.

If a parameter tuple causes an error, the associated status array
element will be set to an arrayref of [ $sth-&gt;err, $sth-&gt;errstr ]
returned by the failed execution.  If B&lt;any&gt; tuple returns an error,
C&lt;execute_array&gt; will return C&lt;undef&gt; B&lt;after&gt; it has executed all
the parameter tuples. In that case, the application should inspect
the status array to determine which parameter tuples failed.

If no C&lt;ArrayTupleStatus&gt; is provided, C&lt;execute_array&gt; will return
C&lt;undef&gt; on the first occurance of a parameter tuple causing an error.
[XXX This may change as it doesn't match the behaviour of drivers
which use bulk operation API to ship the data to the server.]

If all parameter tuples are successfully executed, C&lt;execute_array&gt; returns 
the sum of the number of rows affected by all the parameter tuples,
if known. If no rows were affected, then C&lt;execute&gt; returns
"C&lt;0E0&gt;", which Perl will treat as 0 but will regard as true. Note that it
is I&lt;not&gt; an error for no rows to be affected by a statement. If the
number of rows affected is not known, then C&lt;execute_array&gt; may return a 
negative number. Applications should not rely on the returned value to
indicate actual total rowcounts, but use the C&lt;ArrayTupleStatus&gt; and explicitly
inspect each returned element of the status array.

Support for data returning statements is driver-specific and subject
to change. At present, the default implementation provided by DBI
only supports non-data returning statements.

If any C&lt;@bind_values&gt; are given, then C&lt;execute_array&gt; will effectively call
L&lt;/bind_param_array&gt; for each value before executing the statement.
Values bound in this way are usually treated as C&lt;SQL_VARCHAR&gt; types
unless the driver can determine the correct type (which is rare), or
unless C&lt;bind_param&gt;, C&lt;bind_param_inout&gt;, C&lt;bind_param_array&gt;, 
or C&lt;bind_param_inout_array&gt; has already been used to specify the type.

Transaction semantics using array binding are driver and database specific.
If C&lt;AutoCommit&gt; 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&lt;AutoCommit&gt; is off, the application is responsible
for explicitly committing the entire set of bound parameter tuples.
Note that different drivers and databases may have different behaviors
when some parameter tuples cause failures. In some cases, the driver or
database may automatically rollback the effect of all prior parameter 
tuples that succeeded in the transaction; other drivers or databases may 
retain the effect of prior successfully executed parameter tuples. Be
sure to check your driver and database for its specific behavior.

Note that, in general, performance will usually be better with C&lt;AutoCommit&gt;
turned off, and using explicit C&lt;commit&gt; after each C&lt;execute_array&gt;
call.


=item C&lt;fetchrow_arrayref&gt;

  $ary_ref = $sth-&gt;fetchrow_arrayref;
  $ary_ref = $sth-&gt;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&lt;undef&gt;
values in the array.
This is the fastest way to fetch data, particularly if used with
C&lt;$sth-&gt;E&lt;gt&gt;C&lt;bind_columns&gt;.

If there are no more rows or if an error occurs, then C&lt;fetchrow_arrayref&gt;
returns an C&lt;undef&gt;. You should check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt; afterwards (or use the
C&lt;RaiseError&gt; attribute) to discover if the C&lt;undef&gt; returned was due to an
error.

Note that the same array reference is returned for each fetch, so don't
store the reference and then use it after a later fetch.  Also, the
elements of the array are also reused for each row, so take care if you
want to take a reference to an element. See also L&lt;/bind_columns&gt;.

=item C&lt;fetchrow_array&gt;

 @ary = $sth-&gt;fetchrow_array;

An alternative to C&lt;fetchrow_arrayref&gt;. Fetches the next row of data
and returns it as a list containing the field values.  Null fields
are returned as C&lt;undef&gt; values in the list.

If there are no more rows or if an error occurs, then C&lt;fetchrow_array&gt;
returns an empty list. You should check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt; afterwards (or use
the C&lt;RaiseError&gt; attribute) to discover if the empty list returned was
due to an error.

In a scalar context, C&lt;fetchrow_array&gt; returns the value of the first
field. An C&lt;undef&gt; is returned if there are no more rows or if an error
occurred. Since that C&lt;undef&gt; can't be distinguished from an C&lt;undef&gt; returned
because the first field value was NULL, you should exercise some
caution if you use C&lt;fetchrow_array&gt; in a scalar context.

=item C&lt;fetchrow_hashref&gt;

 $hash_ref = $sth-&gt;fetchrow_hashref;
 $hash_ref = $sth-&gt;fetchrow_hashref($name);

An alternative to C&lt;fetchrow_arrayref&gt;. 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&lt;undef&gt; values in the hash.

If there are no more rows or if an error occurs, then C&lt;fetchrow_hashref&gt;
returns an C&lt;undef&gt;. You should check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt; afterwards (or use the
C&lt;RaiseError&gt; attribute) to discover if the C&lt;undef&gt; returned was due to an
error.

The optional C&lt;$name&gt; parameter specifies the name of the statement handle
attribute. For historical reasons it defaults to "C&lt;NAME&gt;", however using either
"C&lt;NAME_lc&gt;" or "C&lt;NAME_uc&gt;" is recomended for portability.

The keys of the hash are the same names returned by C&lt;$sth-&gt;E&lt;gt&gt;C&lt;{$name}&gt;. 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&lt;fetchrow_hashref&gt; and Perl have to perform, it
is not as efficient as C&lt;fetchrow_arrayref&gt; or C&lt;fetchrow_array&gt;.

Currently, a new hash reference is returned for each row.  I&lt;This will
change&gt; in the future to return the same hash ref each time, so don't
rely on the current behaviour.


=item C&lt;fetchall_arrayref&gt;

  $tbl_ary_ref = $sth-&gt;fetchall_arrayref;
  $tbl_ary_ref = $sth-&gt;fetchall_arrayref( $columns_array_ref );
  $tbl_ary_ref = $sth-&gt;fetchall_arrayref( $columns_hash_ref  );

The C&lt;fetchall_arrayref&gt; 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&lt;fetchall_arrayref&gt; returns a reference
to an empty array. If an error occurs, C&lt;fetchall_arrayref&gt; returns the
data fetched thus far, which may be none.  You should check C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt;
afterwards (or use the C&lt;RaiseError&gt; attribute) to discover if the data is
complete or was truncated due to an error.

When passed an array reference, C&lt;fetchall_arrayref&gt; uses L&lt;/fetchrow_arrayref&gt;
to fetch each row as an array ref. If the parameter array is not empty
then it is used as a slice to select individual columns by perl array
index number (starting at 0, unlike column and parameter numbers which
start at 1).

With no parameters, C&lt;fetchall_arrayref&gt; acts as if passed an empty array ref.

When passed a hash reference, C&lt;fetchall_arrayref&gt; uses L&lt;/fetchrow_hashref&gt;
to fetch each row as a hash reference. If the parameter hash is empty then
fetchrow_hashref is simply called in a tight loop and the keys in the hashes
have whatever name lettercase is returned by default from fetchrow_hashref.
(See L&lt;/FetchHashKeyName&gt; attribute.)

If the parameter hash is not empty, then it is used as a slice to
select individual columns by name.  The values of the hash should be
set to 1.  The key names of the returned hashes match the letter case
of the names in the parameter hash, regardless of the
L&lt;/FetchHashKeyName&gt; attribute.

For example, to fetch just the first column of every row:

  $tbl_ary_ref = $sth-&gt;fetchall_arrayref([0]);

To fetch the second to last and last column of every row:

  $tbl_ary_ref = $sth-&gt;fetchall_arrayref([-2,-1]);

To fetch all fields of every row as a hash ref:

  $tbl_ary_ref = $sth-&gt;fetchall_arrayref({});

To fetch only the fields called "foo" and "bar" of every row as a hash ref
(with keys named "foo" and "BAR"):

  $tbl_ary_ref = $sth-&gt;fetchall_arrayref({ foo=&gt;1, BAR=&gt;1 });

The first two examples return a reference to an array of array refs.
The third and forth return a reference to an array of hash refs.


=item C&lt;fetchall_hashref&gt;

  $hash_ref = $dbh-&gt;fetchall_hashref($key_field);

The C&lt;fetchall_hashref&gt; method can be used to fetch all the data to be
returned from a prepared and executed statement handle. It returns a
reference to a hash that contains, at most, one entry per row.

If there are no rows to return, C&lt;fetchall_hashref&gt; returns a reference
to an empty hash. If an error occurs, C&lt;fetchall_hashref&gt; returns the
data fetched thus far, which may be none.  You should check
C&lt;$sth-&gt;E&lt;gt&gt;C&lt;err&gt; afterwards (or use the C&lt;RaiseError&gt; attribute) to
discover if the data is complete or was truncated due to an error.

The $key_field parameter provides the name of the field that holds the
value to be used for the key for the returned hash.  For example:

  $dbh-&gt;{FetchHashKeyName} = 'NAME_lc';
  $sth = $dbh-&gt;prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
  $hash_ref = $sth-&gt;fetchall_hashref('id');
  print "Name for id 42 is $hash_ref-&gt;{42}-&gt;{name}\n";

The $key_field parameter can also be specified as an integer column
number (counting from 1).  If $key_field doesn't match any column in
the statement, as a name first then as a number, then an error is
returned.

This method is normally used only where the key field value for each
row is unique.  If multiple rows are returned with the same value for
the key field then later rows overwrite earlier ones.


=item C&lt;finish&gt;

  $rc  = $sth-&gt;finish;

Indicates that no more data will be fetched from this statement handle
before it is either executed again or destroyed.  The C&lt;finish&gt; method
is rarely needed, but can sometimes be helpful in 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&lt;SELECT&gt; statement, the
driver should automatically call C&lt;finish&gt; for you. So you should
I&lt;not&gt; normally need to call it explicitly I&lt;except&gt; 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&lt;selectrow_*&gt; methods may be better anyway.
Adding calls to C&lt;finish&gt; after each fetch loop is a common mistake,
don't do it, it can mask genuine problems like uncaught fetch errors.

Consider a query like:

  SELECT foo FROM table WHERE bar=? ORDER BY foo

where you want to select just the first (smallest) "foo" value from a
very large table. When executed, the database server will have to use
temporary buffer space to store the sorted rows. If, after executing
the handle and selecting one row, the handle won't be re-executed for
some time and won't be destroyed, the C&lt;finish&gt; method can be used to tell
the server that the buffer space can be freed.

Calling C&lt;finish&gt; resets the L&lt;/Active&gt; attribute for the statement.  It
may also make some statement handle attributes (such as C&lt;NAME&gt; and C&lt;TYPE&gt;)
unavailable if they have not already been accessed (and thus cached).

The C&lt;finish&gt; 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&lt;/disconnect&gt; and the L&lt;/Active&gt; attribute.

The C&lt;finish&gt; method should have been called C&lt;cancel_select&gt;.


=item C&lt;rows&gt;

  $rv = $sth-&gt;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&lt;non&gt;-C&lt;SELECT&gt;
C&lt;execute&gt; (for some specific operations like C&lt;UPDATE&gt; and C&lt;DELETE&gt;), or
after fetching all the rows of a C&lt;SELECT&gt; statement.

For C&lt;SELECT&gt; statements, it is generally not possible to know how many
rows will be returned except by fetching them all.  Some drivers will
return the number of rows the application has fetched so far, but
others may return -1 until all rows have been fetched.  So use of the
C&lt;rows&gt; method or C&lt;$DBI::rows&gt; with C&lt;SELECT&gt; statements is not
recommended.

One alternative method to get a row count for a C&lt;SELECT&gt; is to execute a
"SELECT COUNT(*) FROM ..." SQL statement with the same "..." as your
query and then fetch the row count from that.


=item C&lt;bind_col&gt;

  $rc = $sth-&gt;bind_col($column_number, \$var_to_bind);

Binds an output column (field) of a C&lt;SELECT&gt; statement to a Perl variable.
See C&lt;bind_columns&gt; below for an example.  Note that column numbers count
up from 1.

Whenever a row is fetched from the database, the corresponding Perl
variable is automatically updated. There is no need to fetch and assign
the values manually.  The binding is performed at a very low level
using Perl aliasing so there is no extra copying taking place.  This
makes using bound variables very efficient.

For maximum portability between drivers, C&lt;bind_col&gt; should be called after
C&lt;execute&gt;. This restriction may be removed in a later version of the DBI.

You do not need to bind output columns in order to fetch data, but it
can be useful for some applications which need either maximum performance
or greater clarity of code.  The L&lt;/bind_param&gt; method
performs a similar but opposite function for input variables.

=item C&lt;bind_columns&gt;

  $rc = $sth-&gt;bind_columns(@list_of_refs_to_vars_to_bind);

Calls L&lt;/bind_col&gt; for each column of the C&lt;SELECT&gt; statement.
The C&lt;bind_columns&gt; method will die if the number of references does not
match the number of fields.

For maximum portability between drivers, C&lt;bind_columns&gt; should be called
after C&lt;execute&gt;.

For example:

  $dbh-&gt;{RaiseError} = 1; # do this, or check every call for errors
  $sth = $dbh-&gt;prepare(q{ SELECT region, sales FROM sales_by_region });
  $sth-&gt;execute;
  my ($region, $sales);

  # Bind Perl variables to columns:
  $rv = $sth-&gt;bind_columns(\$region, \$sales);

  # you can also use Perl's \(...) syntax (see perlref docs):
  #     $sth-&gt;bind_columns(\($region, $sales));

  # Column binding is the most efficient way to fetch data
  while ($sth-&gt;fetch) {
      print "$region: $sales\n";
  }

For compatibility with old scripts, the first parameter will be
ignored if it is C&lt;undef&gt; or a hash reference.

Here's a more fancy example that binds columns to the values I&lt;inside&gt;
a hash (thanks to H.Merijn Brand):

  $sth-&gt;execute;
  my %row;
  $sth-&gt;bind_columns( \( @row{ @{$sth-&gt;{NAME_lc} } } ));
  while ($sth-&gt;fetch) {
      print "$row{region}: $row{sales}\n";
  }


=item C&lt;dump_results&gt;

  $rows = $sth-&gt;dump_results($maxlen, $lsep, $fsep, $fh);

Fetches all the rows from C&lt;$sth&gt;, calls C&lt;DBI::neat_list&gt; for each row, and
prints the results to C&lt;$fh&gt; (defaults to C&lt;STDOUT&gt;) separated by C&lt;$lsep&gt;
(default C&lt;"\n"&gt;). C&lt;$fsep&gt; defaults to C&lt;", "&gt; and C&lt;$maxlen&gt; defaults to 35.

This method is designed as a handy utility for prototyping and
testing queries. Since it uses L&lt;/neat_list&gt; to
format and edit the string for reading by humans, it is not recomended
for data transfer applications.

=back


=head2 Statement Handle Attributes

This section describes attributes specific to statement handles. Most
of these attributes are read-only.

Changes to these statement handle attributes do not affect any other
existing or future statement handles.

Attempting to set or get the value of an unknown attribute is fatal,
except for private driver specific attributes (which all have names
starting with a lowercase letter).

Example:

  ... = $h-&gt;{NUM_OF_FIELDS};	# get/read

Note that some drivers cannot provide valid values for some or all of
these attributes until after C&lt;$sth-&gt;E&lt;gt&gt;C&lt;execute&gt; has been called.

See also L&lt;/finish&gt; to learn more about the effect it
may have on some attributes.

=over 4

=item C&lt;NUM_OF_FIELDS&gt;  (integer, read-only)

Number of fields (columns) the prepared statement will return. Non-C&lt;SELECT&gt;
statements will have C&lt;NUM_OF_FIELDS == 0&gt;.


=item C&lt;NUM_OF_PARAMS&gt;  (integer, read-only)

The number of parameters (placeholders) in the prepared statement.
See SUBSTITUTION VARIABLES below for more details.


=item C&lt;NAME&gt;  (array-ref, read-only)

Returns a reference to an array of field names for each column. The
names may contain spaces but should not be truncated or have any
trailing space. Note that the names have the letter case (upper, lower
or mixed) as returned by the driver being used. Portable applications
should use L&lt;/NAME_lc&gt; or L&lt;/NAME_uc&gt;.

  print "First column name: $sth-&gt;{NAME}-&gt;[0]\n";

=item C&lt;NAME_lc&gt;  (array-ref, read-only)

Like L&lt;/NAME&gt; but always returns lowercase names.

=item C&lt;NAME_uc&gt;  (array-ref, read-only)

Like L&lt;/NAME&gt; but always returns uppercase names.

=item C&lt;NAME_hash&gt;  (hash-ref, read-only)

=item C&lt;NAME_lc_hash&gt;  (hash-ref, read-only)

=item C&lt;NAME_uc_hash&gt;  (hash-ref, read-only)

The C&lt;NAME_hash&gt;, C&lt;NAME_lc_hash&gt;, and C&lt;NAME_uc_hash&gt; 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&lt;NAME&gt;,
C&lt;NAME_lc&gt;, and C&lt;NAME_uc&gt; attributes respectively (as described above).

The value of each hash entry is the perl index number of the
corresponding column (counting from 0). For example:

  $sth = $dbh-&gt;prepare("select Id, Name from table");
  $sth-&gt;execute;
  @row = $sth-&gt;fetchrow_array;
  print "Name $row[ $sth-&gt;{NAME_lc_hash}{name} ]\n";


=item C&lt;TYPE&gt;  (array-ref, read-only)

Returns a reference to an array of integer values for each
column. The value indicates the data type of the corresponding column.

The values correspond to the international standards (ANSI X3.135
and ISO/IEC 9075) which, in general terms, means ODBC. Driver-specific
types that don't exactly match standard types should generally return
the same values as an ODBC driver supplied by the makers of the
database. That might include private type numbers in ranges the vendor
has officially registered with the ISO working group:

  ftp://sqlstandards.org/SC32/SQL_Registry/

Where there's no vendor-supplied ODBC driver to be compatible with,
the DBI driver can use type numbers in the range that is now
officially reserved for use by the DBI: -9999 to -9000.

All possible values for C&lt;TYPE&gt; should have at least one entry in the
output of the C&lt;type_info_all&gt; method (see L&lt;/type_info_all&gt;).

=item C&lt;PRECISION&gt;  (array-ref, read-only)

Returns a reference to an array of integer values for each
column.  For non-numeric columns, the value generally refers to either
the maximum length or the defined length of the column.  For numeric
columns, the value refers to the maximum number of significant digits
used by the data type (without considering a sign character or decimal
point).  Note that for floating point types (REAL, FLOAT, DOUBLE), the
"display size" can be up to 7 characters greater than the precision.
(for the sign + decimal point + the letter E + a sign + 2 or 3 digits).

=item C&lt;SCALE&gt;  (array-ref, read-only)

Returns a reference to an array of integer values for each column.
NULL (C&lt;undef&gt;) values indicate columns where scale is not applicable.

=item C&lt;NULLABLE&gt;  (array-ref, read-only)

Returns a reference to an array indicating the possibility of each
column returning a null.  Possible values are C&lt;0&gt;
(or an empty string) = no, C&lt;1&gt; = yes, C&lt;2&gt; = unknown.

  print "First column may return NULL\n" if $sth-&gt;{NULLABLE}-&gt;[0];


=item C&lt;CursorName&gt;  (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&lt;"where current of ..."&gt; SQL syntax, then it returns C&lt;undef&gt;.


=item C&lt;Statement&gt;  (string, read-only)

Returns the statement string passed to the L&lt;/prepare&gt; method.


=item C&lt;RowsInCache&gt;  (integer, read-only)

If the driver supports a local row cache for C&lt;SELECT&gt; statements, then
this attribute holds the number of un-fetched rows in the cache. If the
driver doesn't, then it returns C&lt;undef&gt;. Note that some drivers pre-fetch
rows on execute, whereas others wait till the first fetch.

See also the L&lt;/RowCacheSize&gt; database handle attribute.

=back


=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&lt;INFORMATION_SCHEMA&gt; views are seldom supported by the DBMS.
Special methods (catalog methods) are available to return result sets
for a small but important portion of that metadata:

  column_info
  foreign_key_info
  primary_key_info
  table_info

All catalog methods accept arguments in order to restrict the result sets.
Passing C&lt;undef&gt; 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&lt;Note&gt;: 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&lt;ordinary values&gt;, e.g.
the arguments of C&lt;primary_key_info()&gt;.
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&lt;search patterns&gt; (strings
containing '_' and/or '%'), e.g. the C&lt;$table&gt; argument of C&lt;column_info()&gt;.
Passing '%' is equivalent to leaving the argument C&lt;undef&gt;.

B&lt;Caveat&gt;: The underscore ('_') is valid and often used in SQL identifiers.
Passing such a value to a search pattern argument may return more rows than
expected!
To include pattern characters as literals, they must be preceded by an
escape character which can be achieved with

  $esc = $dbh-&gt;get_info( 14 );  # SQL_SEARCH_PATTERN_ESCAPE
  $search_pattern =~ s/([_%])/$esc$1/g;

The ODBC and SQL/CLI specifications define a way to change the default
behavior described above: All arguments (except I&lt;list value arguments&gt;)
are treated as I&lt;identifier&gt; if the C&lt;SQL_ATTR_METADATA_ID&gt; attribute is
set to C&lt;SQL_TRUE&gt;.
I&lt;Quoted identifiers&gt; are very similar to I&lt;ordinary values&gt;, i.e. their
body (the string within the quotes) is interpreted literally.
I&lt;Unquoted identifiers&gt; are compared in UPPERCASE.

The DBI (currently) does not support the C&lt;SQL_ATTR_METADATA_ID&gt; attribute,
i.e. it behaves like an ODBC driver where C&lt;SQL_ATTR_METADATA_ID&gt; is set to
C&lt;SQL_FALSE&gt;.


=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&lt;AutoCommit&gt; is off.  See L&lt;/AutoCommit&gt; for details of using C&lt;AutoCommit&gt;
with various types of databases.

The recommended way to implement robust transactions in Perl
applications is to use C&lt;RaiseError&gt; and S&lt;C&lt;eval { ... }&gt;&gt;
(which is very fast, unlike S&lt;C&lt;eval "..."&gt;&gt;). For example:

  $dbh-&gt;{AutoCommit} = 0;  # enable transactions, if possible
  $dbh-&gt;{RaiseError} = 1;
  eval {
      foo(...)        # do lots of work here
      bar(...)        # including inserts
      baz(...)        # and updates
      $dbh-&gt;commit;   # commit the changes if we get this far
  };
  if ($@) {
      warn "Transaction aborted because $@";
      $dbh-&gt;rollback; # undo the incomplete changes
      # add other application on-error-clean-up code here
  }

If the C&lt;RaiseError&gt; attribute is not set, then DBI calls would need to be
manually checked for errors, typically like this:

  $h-&gt;method(@args) or die $h-&gt;errstr;

With C&lt;RaiseError&gt; set, the DBI will automatically C&lt;die&gt; 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&lt;/RaiseError&gt; for more
details.

A major advantage of the C&lt;eval&gt; approach is that the transaction will be
properly rolled back if I&lt;any&gt; code (not just DBI calls) in the inner
application dies for any reason. The major advantage of using the
C&lt;$h-&gt;E&lt;gt&gt;C&lt;{RaiseError}&gt; attribute is that all DBI calls will be checked
automatically. Both techniques are strongly recommended.

After calling C&lt;commit&gt; or C&lt;rollback&gt; many drivers will not let you
fetch from a previously active C&lt;SELECT&gt; 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&lt;SELECT&gt; statements.

See L&lt;/AutoCommit&gt; and L&lt;/disconnect&gt; for other important information
about transactions.


=head2 Handling BLOB / LONG / Memo Fields

Many databases support "blob" (binary large objects), "long", or similar
datatypes for holding very long strings or large amounts of binary
data in a single field. Some databases support variable length long
values over 2,000,000,000 bytes in length.

Since values of that size can't usually be held in memory, and because
databases can't usually know in advance the length of the longest long
that will be returned from a C&lt;SELECT&gt; statement (unlike other data
types), some special handling is required.

In this situation, the value of the C&lt;$h-&gt;E&lt;gt&gt;C&lt;{LongReadLen}&gt; attribute is used
to determine how much buffer space to allocate when fetching such
fields.  The C&lt;$h-&gt;E&lt;gt&gt;C&lt;{LongTruncOk}&gt; attribute is used to determine how to
behave if a fetched value can't fit into the buffer.

When trying to insert long or binary values, placeholders should be used
since there are often limits on the maximum size of an C&lt;INSERT&gt;
statement and the L&lt;/quote&gt; method generally can't cope with binary
data.  See L&lt;/Placeholders and Bind Values&gt;.


=head2 Simple Examples

Here's a complete example program to select and fetch some data:

  my $dbh = DBI-&gt;connect("dbi:DriverName:db_name", $user, $password)
      or die "Can't connect to $data_source: $DBI::errstr";

  my $sth = $dbh-&gt;prepare( q{
          SELECT name, phone
          FROM mytelbook
  }) or die "Can't prepare statement: $DBI::errstr";

  my $rc = $sth-&gt;execute
      or die "Can't execute statement: $DBI::errstr";

  print "Query will return $sth-&gt;{NUM_OF_FIELDS} fields.\n\n";
  print "Field names: @{ $sth-&gt;{NAME} }\n";

  while (($name, $phone) = $sth-&gt;fetchrow_array) {
      print "$name: $phone\n";
  }
  # check for problems which may have terminated the fetch early
  die $sth-&gt;errstr if $sth-&gt;err;

  $dbh-&gt;disconnect;

Here's a complete example program to insert some data from a file.
(This example uses C&lt;RaiseError&gt; to avoid needing to check each call).

  my $dbh = DBI-&gt;connect("dbi:DriverName:db_name", $user, $password, {
      RaiseError =&gt; 1, AutoCommit =&gt; 0
  });

  my $sth = $dbh-&gt;prepare( q{
      INSERT INTO table (name, phone) VALUES (?, ?)
  });

  open FH, "&lt;phone.csv" or die "Unable to open phone.csv: $!";
  while (&lt;FH&gt;) {
      chomp;
      my ($name, $phone) = split /,/;
      $sth-&gt;execute($name, $phone);
  }
  close FH;

  $dbh-&gt;commit;
  $dbh-&gt;disconnect;

Here's how to convert fetched NULLs (undefined values) into empty strings:

  while($row = $sth-&gt;fetchrow_arrayref) {
    # this is a fast and simple way to deal with nulls:
    foreach (@$row) { $_ = '' unless defined }
    print "@$row\n";
  }

The C&lt;q{...}&gt; style quoting used in these examples avoids clashing with
quotes that may be used in the SQL statement. Use the double-quote like
C&lt;qq{...}&gt; operator if you want to interpolate variables into the string.
See L&lt;perlop/"Quote and Quote-like Operators"&gt; for more details.


=head2 Threads and Thread Safety

If the DBI is built using a Perl that has perl 5.005 style threads
enabled then it will use a per-driver mutex to ensure that only one
thread is with a driver at any one time. However perl 5.005 style
threads are unstable and shoud not be used in production.

Perl 5.7 and later support a new threading model called iThreads
which is much more stable. However the DBI has not yet had any extra
code added or testing done to make sure it works properly with
iThreads. So at this time the DBI should not be used with iThreads
in situations where more than one thread may enter a cloned instance
of the DBI. It is I&lt;possibly&gt; safe to have multiple threads load
the DBI module I&lt;after&gt; they have been created, but the DBI probably
won't be providing any protection against multiple threads entering a
databases own library code. As many databases don't have thread
safe libraries that is likely to cause problems.

Summary: Using DBI with perl threads of any kind is not recommended
for production environments.


=head2 Signal Handling and Canceling Operations

The first thing to say is that signal handling in Perl is currently
I&lt;not&gt; safe. There is always a small risk of Perl crashing and/or
core dumping when, or after, handling a signal.  (The risk was reduced
with 5.004_04 but is still present.)

The two most common uses of signals in relation to the DBI are for
canceling operations when the user types Ctrl-C (interrupt), and for
implementing a timeout using C&lt;alarm()&gt; and C&lt;$SIG{ALRM}&gt;.

To assist in implementing these operations, the DBI provides a C&lt;cancel&gt;
method for statement handles. The C&lt;cancel&gt; method should abort the current
operation and is designed to be called from a signal handler.

However, it must be stressed that: a) few drivers implement this at
the moment (the DBI provides a default method that just returns C&lt;undef&gt;);
and b) even if implemented, there is still a possibility that the statement
handle, and possibly the parent database handle, will not be usable
afterwards.

If C&lt;cancel&gt; returns true, then it has successfully
invoked the database engine's own cancel function.  If it returns false,
then C&lt;cancel&gt; failed. If it returns C&lt;undef&gt;, then the database
engine does not have cancel implemented.


=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 how the DBI classes and how they work together.

By default C&lt;$dbh = DBI-&gt;E&lt;gt&gt;C&lt;connect(...)&gt; returns a $dbh blessed
into the C&lt;DBI::db&gt; class.  And the C&lt;$dbh-&gt;E&lt;gt&gt;C&lt;prepare&gt; method
returns an $sth blessed into the C&lt;DBI::st&gt; class (actually it
simply changes the last four characters of the calling handle class
to be C&lt;::st&gt;).

The leading 'C&lt;DBI&gt;' is known as the 'root class' and the extra
'C&lt;::db&gt;' or 'C&lt;::st&gt;' 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&lt;MySubDBI&gt; and override the do(), prepare() and execute() methods,
then your do() and prepare() methods should be in the C&lt;MySubDBI::db&gt;
class and the execute() method should be in the C&lt;MySubDBI::st&gt; class.

To setup the inheritance hierarchy the @ISA variable in C&lt;MySubDBI::db&gt;
should include C&lt;DBI::db&gt; and the @ISA variable in C&lt;MySubDBI::st&gt;
should include C&lt;DBI::st&gt;.  The C&lt;MySubDBI&gt; root class itself isn't
currently used for anything visible and so, apart from setting @ISA
to include C&lt;DBI&gt;, it should be left empty.

So, having put your overriding methods into the right classes, and
setup the inheritance hierarchy, how do you get the DBI to use them?
You have two choices, either a static method call using the name
of your subclass:

  $dbh = MySubDBI-&gt;connect(...);

or specifying a C&lt;RootClass&gt; attribute:

  $dbh = DBI-&gt;connect(..., { RootClass =&gt; 'MySubDBI' });

The only difference between the two is that using an explicit
RootClass attribute will make the DBI automatically attempt to load
a module by that name (and not complain if such a module can't be
found). If both forms are used then the attribute takes precedence.

Here's a brief example of a DBI subclass.  A more thorough example
can be found in t/subclass.t in the DBI distribution.

  package MySubDBI;

  use strict;

  use DBI;
  use vars qw(@ISA);
  @ISA = qw(DBI);

  package MySubDBI::db;
  use vars qw(@ISA);
  @ISA = qw(DBI::db);

  sub prepare {
    my ($dbh, @args) = @_;
    my $sth = $dbh-&gt;SUPER::prepare(@args)
        or return;
    $sth-&gt;{private_mysubdbi_info} = { foo =&gt; 'bar' };
    return $sth;
  }

  package MySubDBI::st;
  use vars qw(@ISA);
  @ISA = qw(DBI::st);

  sub fetch {
    my ($sth, @args) = @_;
    my $row = $sth-&gt;SUPER::fetch(@args)
        or return;
    do_something_magical_with_row_data($row)
        or return $sth-&gt;set_err(1234, "The magic failed", undef, "fetch");
    return $row;
  }

When calling a SUPER::method that returns a handle, be careful to
check the return value before trying to do other things with it in
your overridden method. This is especially important if you want
to set a hash attribute on the handle, as Perl's autovivification
will bite you by (in)conveniently creating an unblessed hashref,
which your method will then return with usually baffling results
later on.  It's best to check right after the call and return undef
immediately on error, just like DBI would and just like the example
above.

If your method needs to record an error it should call the set_err()
method with the error code and error string, as shown in the example
above. The error code and error string will be recorded in the
handle and available via C&lt;$h-&gt;E&lt;gt&gt;C&lt;err&gt; and C&lt;$DBI::errstr&gt; etc.
The set_err() method always returns an undef or empty list as
approriate. Since your method should nearly always return an undef
or empty list as soon as an error is detected it's handy to simply
return what set_err() returns, as shown in the example above.

If the handle has C&lt;RaiseError&gt;, C&lt;PrintError&gt;, or C&lt;HandleError&gt;
etc. set then the set_err() method will honour them. This means
that if C&lt;RaiseError&gt; is set then set_err() won't return in the
normal way but will 'throw an exception' that can be caught with
an C&lt;eval&gt; block.

You can stash private data into DBI handles
via C&lt;$h-&gt;E&lt;gt&gt;C&lt;{private_..._*}&gt;.  See the entry under L&lt;/ATTRIBUTES
COMMON TO ALL HANDLES&gt; for info and important caveats.


=head1 DEBUGGING

In addition to the L&lt;/trace&gt; method, you can enable the same trace
information by setting the C&lt;DBI_TRACE&gt; environment variable before
starting Perl.

On Unix-like systems using a Bourne-like shell, you can do this easily
on the command line:

  DBI_TRACE=2 perl your_test_script.pl

If C&lt;DBI_TRACE&gt; is set to a non-numeric value, then it is assumed to
be a file name and the trace level will be set to 2 with all trace
output appended to that file. If the name begins with a number
followed by an equal sign (C&lt;=&gt;), then the number and the equal sign are
stripped off from the name, and the number is used to set the trace
level. For example:

  DBI_TRACE=1=dbitrace.log perl your_test_script.pl

See also the L&lt;/trace&gt; method.

It can sometimes be handy to compare trace files from two different
runs of the same script. However using a tool like C&lt;diff&gt; doesn't work
well because the trace file is full of object addresses that may
differ each run. Here's a handy little command to strip those out:

 perl -pe 's/\b0x[\da-f]{6,}/0xNNNN/gi; s/\b[\da-f]{6,}/&lt;long number&gt;/gi'


=head1 WARNING AND ERROR MESSAGES

=head2 Fatal Errors

=over 4

=item Can't call method "prepare" without a package or object reference

The C&lt;$dbh&gt; handle you're using to call C&lt;prepare&gt; is probably undefined because
the preceding C&lt;connect&gt; failed. You should always check the return status of
DBI methods, or use the L&lt;/RaiseError&gt; attribute.

=item Can't call method "execute" without a package or object reference

The C&lt;$sth&gt; handle you're using to call C&lt;execute&gt; is probably undefined because
the preceeding C&lt;prepare&gt; failed. You should always check the return status of
DBI methods, or use the L&lt;/RaiseError&gt; attribute.

=item DBI/DBD internal version mismatch

The DBD driver module was built with a different version of DBI than
the one currently being used.  You should rebuild the DBD module under
the current version of DBI.

(Some rare platforms require "static linking". On those platforms, there
may be an old DBI or DBD driver version actually embedded in the Perl
executable being used.)

=item DBD driver has not implemented the AutoCommit attribute

The DBD driver implementation is incomplete. Consult the author.

=item Can't [sg]et %s-&gt;{%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&lt;DBI::PurePerl&gt;.

=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 Standards Reference Information

More detailed information about the semantics of certain DBI methods
that are based on ODBC and SQL/CLI standards is available on-line
via microsoft.com, for ODBC, and www.jtc1sc32.org for the SQL/CLI
standard:

 DBI method        ODBC function     SQL/CLI Working Draft
 ----------        -------------     ---------------------
 column_info       SQLColumns        Page 124
 foreign_key_info  SQLForeignKeys    Page 163
 get_info          SQLGetInfo        Page 214
 primary_key_info  SQLPrimaryKeys    Page 254
 table_info        SQLTables         Page 294
 type_info         SQLGetTypeInfo    Page 239

For example, for ODBC information on SQLColumns you'd visit:

  http://msdn.microsoft.com/library/en-us/odbc/htm/odbcsqlcolumns.asp

If that URL ceases to work then use the MSDN search facility at:

  http://search.microsoft.com/us/dev/

and search for C&lt;SQLColumns returns&gt; using the exact phrase option.
The link you want will probably just be called C&lt;SQLColumns&gt; 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:

  http://www.jtc1sc32.org/sc32/jtc1sc32.nsf/Attachments/7E3B41486BD99C3488256B410064C877/$FILE/32N0744T.PDF


A hyperlinked, browsable version of the BNF syntax for SQL92 (plus
Oracle 7 SQL and PL/SQL) is available here:

  http://cui.unige.ch/db-research/Enseignement/analyseinfo/SQL92/BNFindex.html

A BNF syntax for SQL3 is available here:

  http://www.sqlstandards.org/SC32/WG3/Progression_Documents/Informal_working_drafts/iso-9075-2-1999.bnf


=head2 Books and Journals

 Programming the Perl DBI, by Alligator Descartes and Tim Bunce.

 Programming Perl 2nd Ed. by Larry Wall, Tom Christiansen &amp; Randal Schwartz.

 Learning Perl by Randal Schwartz.

 Dr Dobb's Journal, November 1996.

 The Perl Journal, April 1997.

=head2 Perl Modules

Index of DBI related modules available from CPAN:

 http://search.cpan.org/search?mode=module&amp;query=DBIx%3A%3A
 http://search.cpan.org/search?mode=doc&amp;query=DBI

For a good comparison of RDBMS-OO mappers and some OO-RDBMS mappers
(including Class::DBI, Alzabo, and DBIx::RecordSet in the former
category and Tangram and SPOPS in the latter) see the Perl
Object-Oriented Persistence project pages at:

 http://poop.sourceforge.net

=head2 Manual Pages

L&lt;perl(1)&gt;, L&lt;perlmod(1)&gt;, L&lt;perlbook(1)&gt;

=head2 Mailing List

The I&lt;dbi-users&gt; mailing list is the primary means of communication among
users of the DBI and its related modules. For details send email to:

 dbi-users-help@perl.org

There are typically between 700 and 900 messages per month.  You have
to subscribe in order to be able to post. However you can opt for a
'post-only' subscription.

Mailing list archives (of variable quality) are held at:

 http://www.xray.mpe.mpg.de/mailing-lists/dbi/
 http://groups.yahoo.com/group/dbi-users
 http://www.bitmechanic.com/mail-archives/dbi-users/
 http://marc.theaimsgroup.com/?l=perl-dbi&amp;r=1&amp;w=2
 http://www.mail-archive.com/dbi-users%40perl.org/

=head2 Assorted Related WWW Links

The DBI "Home Page":

 http://dbi.perl.org/

Other DBI related links:

 http://tegan.deltanet.com/~phlip/DBUIdoc.html
 http://dc.pm.org/perl_db.html
 http://wdvl.com/Authoring/DB/Intro/toc.html
 http://www.hotwired.com/webmonkey/backend/tutorials/tutorial1.html
 http://bumppo.net/lists/macperl/1999/06/msg00197.html

Other database related links:

 http://www.jcc.com/sql_stnd.html
 http://cuiwww.unige.ch/OSG/info/FreeDB/FreeDB.home.html

Commercial and Data Warehouse Links

 http://www.dwinfocenter.org
 http://www.datawarehouse.com
 http://www.datamining.org
 http://www.olapcouncil.org
 http://www.idwa.org
 http://www.knowledgecenters.org/dwcenter.asp

Recommended Perl Programming Links

 http://language.perl.com/style/


=head2 FAQ

Please also read the DBI FAQ which is installed as a DBI::FAQ module.
You can use I&lt;perldoc&gt; to read it by executing the C&lt;perldoc DBI::FAQ&gt; command.

=head1 AUTHORS

DBI by Tim Bunce.  This pod text by Tim Bunce, J. Douglas Dunlop,
Jonathan Leffler and others.  Perl by Larry Wall and the
C&lt;perl5-porters&gt;.

=head1 COPYRIGHT

The DBI module is Copyright (c) 1994-2002 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 ACKNOWLEDGEMENTS

I would like to acknowledge the valuable contributions of the many
people I have worked with on the DBI project, especially in the early
years (1992-1994). In no particular order: Kevin Stock, Buzz Moschetti,
Kurt Andersen, Ted Lemon, William Hails, Garth Kennedy, Michael Peppler,
Neil S. Briscoe, Jeff Urlwin, David J. Hughes, Jeff Stander,
Forrest D Whitcher, Larry Wall, Jeff Fried, Roy Johnson, Paul Hudson,
Georg Rehfeld, Steve Sizemore, Ron Pool, Jon Meek, Tom Christiansen,
Steve Baumgarten, Randal Schwartz, and a whole lot more.

Then, of course, there are the poor souls who have struggled through
untold and undocumented obstacles to actually implement DBI drivers.
Among their ranks are Jochen Wiedmann, Alligator Descartes, Jonathan
Leffler, Jeff Urlwin, Michael Peppler, Henrik Tougaard, Edwin Pratomo,
Davide Migliavacca, Jan Pazdziora, Peter Haworth, Edmund Mergl, Steve
Williams, Thomas Lowery, and Phlip Plumlee. Without them, the DBI would
not be the practical reality it is today.  I'm also especially grateful
to Alligator Descartes for starting work on the "Programming the Perl
DBI" book and letting me jump on board.

Much of the DBI and DBD::Oracle was developed while I was Technical
Director (CTO) of the Paul Ingram Group (www.ig.co.uk).  So I'd
especially like to thank Paul for his generosity and vision in
supporting this work for many years.

=head1 TRANSLATIONS

A German translation of this manual (possibly slightly out of date) is
available, thanks to O'Reilly, at:

  http://www.oreilly.de/catalog/perldbiger/

Some other translations:

 http://cronopio.net/perl/                              - Spanish
 http://member.nifty.ne.jp/hippo2000/dbimemo.htm        - Japanese


=head1 SUPPORT / WARRANTY

The DBI is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.

Commercial support for Perl and the DBI, DBD::Oracle and
Oraperl modules can be arranged via The Perl Clinic.
For more details visit:

  http://www.perlclinic.com

For direct DBI and DBD::Oracle support, enhancement, and related work
I am available for consultancy on standard commercial terms.


=head1 TRAINING

References to DBI related training resources. No recommendation implied.

  http://www.treepax.co.uk/
  http://www.keller.com/dbweb/

=head1 FREQUENTLY ASKED QUESTIONS

See the DBI FAQ for a more comprehensive list of FAQs. Use the
C&lt;perldoc DBI::FAQ&gt; command to read it.

=head2 How fast is the DBI?

To measure the speed of the DBI and DBD::Oracle code, I modified
DBD::Oracle so you can set an attribute that will cause the
same row to be fetched from the row cache over and over again (without
involving Oracle code but exercising *all* the DBI and DBD::Oracle code
in the code path for a fetch).

The results (on my lightly loaded old Sparc 10) fetching 50000 rows using:

	1 while $csr-&gt;fetch;

were:
	one field:   5300 fetches per cpu second (approx)
	ten fields:  4000 fetches per cpu second (approx)

Obviously results will vary between platforms (newer faster platforms
can reach around 50000 fetches per second), but it does give a feel for
the maximum performance: fast.  By way of comparison, using the code:

	1 while @row = $csr-&gt;fetchrow_array;

(C&lt;fetchrow_array&gt; is roughly the same as C&lt;ora_fetch&gt;) gives:

	one field:   3100 fetches per cpu second (approx)
	ten fields:  1000 fetches per cpu second (approx)

Notice the slowdown and the more dramatic impact of extra fields.
(The fields were all one char long. The impact would be even bigger for
longer strings.)

Changing that slightly to represent actually doing something in Perl
with the fetched data:

    while(@row = $csr-&gt;fetchrow_array) {
        $hash{++$i} = [ @row ];
    }

gives:	ten fields:  500 fetches per cpu second (approx)

That simple addition has *halved* the performance.

I therefore conclude that DBI and DBD::Oracle overheads are small
compared with Perl language overheads (and probably database overheads).

So, if you think the DBI or your driver is slow, try replacing your
fetch loop with just:

	1 while $csr-&gt;fetch;

and time that. If that helps then point the finger at your own code. If
that doesn't help much then point the finger at the database, the
platform, the network etc. But think carefully before pointing it at
the DBI or your driver.

(Having said all that, if anyone can show me how to make the DBI or
drivers even more efficient, I'm all ears.)


=head2 Why doesn't my CGI script work right?

Read the information in the references below.  Please do I&lt;not&gt; post
CGI related questions to the I&lt;dbi-users&gt; mailing list (or to me).

 http://www.perl.com/cgi-bin/pace/pub/doc/FAQs/cgi/perl-cgi-faq.html
 http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml
 http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html
 http://www.boutell.com/faq/
 http://www.perl.com/perl/faq/

General problems and good ideas:

 Use the CGI::ErrorWrap module.
 Remember that many env vars won't be set for CGI scripts.

=head2 How can I maintain a WWW connection to a database?

For information on the Apache httpd server and the C&lt;mod_perl&gt; module see

  http://perl.apache.org/

=head2 What about ODBC?

A DBD::ODBC module is available.

=head2 Does the DBI have a year 2000 problem?

No. The DBI has no knowledge or understanding of dates at all.

Individual drivers (DBD::*) may have some date handling code but are
unlikely to have year 2000 related problems within their code. However,
your application code which I&lt;uses&gt; the DBI and DBD drivers may have
year 2000 related problems if it has not been designed and written well.

See also the "Does Perl have a year 2000 problem?" section of the Perl FAQ:

  http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html

=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&lt;mod_perl&gt;. 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 JDBC Server by Stuart 'Zen' Bishop zen@bf.rmit.edu.au

The server is written in Perl. The client classes that talk to it are
of course in Java. Thus, a Java applet or application will be able to
comunicate via the JDBC API with any database that has a DBI driver installed.
The URL used is in the form C&lt;jdbc:dbi://host.domain.etc:999/Driver/DBName&gt;.
It seems to be very similar to some commercial products, such as jdbcKona.

=item Remote Proxy DBD support

As of DBI 1.02, a complete implementation of a DBD::Proxy driver and the
DBI::ProxyServer are part of the DBI distribution.

=item SQL Parser

See also the SQL::Statement module, a very simple SQL parser and engine,
base of the DBD::CSV driver.

=back

=cut
</pre></body></html>