JFIF ( %!1!%)+...383-7(-.+  -% &5/------------------------------------------------";!1AQ"aq2#3BRrb*!1"AQa2q#B ?yRd&vGlJwZvK)YrxB#j]ZAT^dpt{[wkWSԋ*QayBbm*&0<|0pfŷM`̬ ^.qR𽬷^EYTFíw<-.j)M-/s yqT'&FKz-([lև<G$wm2*e Z(Y-FVen櫧lҠDwүH4FX1 VsIOqSBۡNzJKzJξcX%vZcFSuMٖ%B ִ##\[%yYꉅ !VĂ1َRI-NsZJLTAPמQ:y״g_g= m֯Ye+Hyje!EcݸࢮSo{׬*h g<@KI$W+W'_> lUs1,o*ʺE.U"N&CTu7_0VyH,q ,)H㲣5<t ;rhnz%ݓz+4 i۸)P6+F>0Tв`&i}Shn?ik܀՟ȧ@mUSLFηh_er i_qt]MYhq 9LaJpPןߘvꀡ\"z[VƬ¤*aZMo=WkpSp \QhMb˒YH=ܒ m`CJt 8oFp]>pP1F>n8(*aڈ.Y݉[iTع JM!x]ԶaJSWҼܩ`yQ`*kE#nNkZKwA_7~ ΁JЍ;-2qRxYk=Uր>Z qThv@.w c{#&@#l;D$kGGvz/7[P+i3nIl`nrbmQi%}rAVPT*SF`{'6RX46PԮp(3W҅U\a*77lq^rT$vs2MU %*ŧ+\uQXVH !4t*Hg"Z챮 JX+RVU+ތ]PiJT XI= iPO=Ia3[ uؙ&2Z@.*SZ (")s8Y/-Fh Oc=@HRlPYp!wr?-dugNLpB1yWHyoP\ѕрiHִ,ِ0aUL.Yy`LSۜ,HZz!JQiVMb{( tژ <)^Qi_`: }8ٱ9_.)a[kSr> ;wWU#M^#ivT܎liH1Qm`cU+!2ɒIX%ֳNړ;ZI$?b$(9f2ZKe㼭qU8I[ U)9!mh1^N0 f_;׆2HFF'4b! yBGH_jтp'?uibQ T#ѬSX5gޒSF64ScjwU`xI]sAM( 5ATH_+s 0^IB++h@_Yjsp0{U@G -:*} TނMH*֔2Q:o@ w5(߰ua+a ~w[3W(дPYrF1E)3XTmIFqT~z*Is*清Wɴa0Qj%{T.ޅ״cz6u6݁h;֦ 8d97ݴ+ޕxзsȁ&LIJT)R0}f }PJdp`_p)əg(ŕtZ 'ϸqU74iZ{=Mhd$L|*UUn &ͶpHYJۋj /@9X?NlܾHYxnuXږAƞ8j ໲݀pQ4;*3iMlZ6w ȵP Shr!ݔDT7/ҡϲigD>jKAX3jv+ ߧز #_=zTm¦>}Tց<|ag{E*ֳ%5zW.Hh~a%j"e4i=vױi8RzM75i֟fEu64\էeo00d H韧rȪz2eulH$tQ>eO$@B /?=#٤ǕPS/·.iP28s4vOuz3zT& >Z2[0+[#Fޑ]!((!>s`rje('|,),y@\pЖE??u˹yWV%8mJ iw:u=-2dTSuGL+m<*צ1as&5su\phƃ qYLֳ>Y(PKi;Uڕp ..!i,54$IUEGLXrUE6m UJC?%4AT]I]F>׹P9+ee"Aid!Wk|tDv/ODc/,o]i"HIHQ_n spv"b}}&I:pȟU-_)Ux$l:fژɕ(I,oxin8*G>ÌKG}Rڀ8Frajٷh !*za]lx%EVRGYZoWѮ昀BXr{[d,t Eq ]lj+ N})0B,e iqT{z+O B2eB89Cڃ9YkZySi@/(W)d^Ufji0cH!hm-wB7C۔֛X$Zo)EF3VZqm)!wUxM49< 3Y .qDfzm |&T"} {*ih&266U9* <_# 7Meiu^h--ZtLSb)DVZH*#5UiVP+aSRIª!p挤c5g#zt@ypH={ {#0d N)qWT kA<Ÿ)/RT8D14y b2^OW,&Bcc[iViVdִCJ'hRh( 1K4#V`pِTw<1{)XPr9Rc 4)Srgto\Yτ~ xd"jO:A!7􋈒+E0%{M'T^`r=E*L7Q]A{]A<5ˋ.}<9_K (QL9FЍsĮC9!rpi T0q!H \@ܩB>F6 4ۺ6΋04ϲ^#>/@tyB]*ĸp6&<џDP9ᗟatM'> b쪗wI!܁V^tN!6=FD܆9*? q6h8  {%WoHoN.l^}"1+uJ ;r& / IɓKH*ǹP-J3+9 25w5IdcWg0n}U@2 #0iv腳z/^ƃOR}IvV2j(tB1){S"B\ ih.IXbƶ:GnI F.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /proc/thread-self/root/usr/local/man/man3/

Linux boscustweb5006.eigbox.net 5.4.91 #1 SMP Wed Jan 20 18:10:28 EST 2021 x86_64
Upload File :
Current File : //proc/thread-self/root/usr/local/man/man3/DBI.3

.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "DBI 3"
.TH DBI 3 "2006-02-07" "perl v5.8.8" "User Contributed Perl Documentation"
.SH "NAME"
DBI \- Database independent interface for Perl
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&  use DBI;
.Ve
.PP
.Vb 3
\&  @driver_names = DBI->available_drivers;
\&  %drivers      = DBI->installed_drivers;
\&  @data_sources = DBI->data_sources($driver_name, \e%attr);
.Ve
.PP
.Vb 1
\&  $dbh = DBI->connect($data_source, $username, $auth, \e%attr);
.Ve
.PP
.Vb 3
\&  $rv  = $dbh->do($statement);
\&  $rv  = $dbh->do($statement, \e%attr);
\&  $rv  = $dbh->do($statement, \e%attr, @bind_values);
.Ve
.PP
.Vb 2
\&  $ary_ref  = $dbh->selectall_arrayref($statement);
\&  $hash_ref = $dbh->selectall_hashref($statement, $key_field);
.Ve
.PP
.Vb 2
\&  $ary_ref  = $dbh->selectcol_arrayref($statement);
\&  $ary_ref  = $dbh->selectcol_arrayref($statement, \e%attr);
.Ve
.PP
.Vb 3
\&  @row_ary  = $dbh->selectrow_array($statement);
\&  $ary_ref  = $dbh->selectrow_arrayref($statement);
\&  $hash_ref = $dbh->selectrow_hashref($statement);
.Ve
.PP
.Vb 2
\&  $sth = $dbh->prepare($statement);
\&  $sth = $dbh->prepare_cached($statement);
.Ve
.PP
.Vb 3
\&  $rc = $sth->bind_param($p_num, $bind_value);
\&  $rc = $sth->bind_param($p_num, $bind_value, $bind_type);
\&  $rc = $sth->bind_param($p_num, $bind_value, \e%attr);
.Ve
.PP
.Vb 3
\&  $rv = $sth->execute;
\&  $rv = $sth->execute(@bind_values);
\&  $rv = $sth->execute_array(\e%attr, ...);
.Ve
.PP
.Vb 2
\&  $rc = $sth->bind_col($col_num, \e$col_variable);
\&  $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
.Ve
.PP
.Vb 3
\&  @row_ary  = $sth->fetchrow_array;
\&  $ary_ref  = $sth->fetchrow_arrayref;
\&  $hash_ref = $sth->fetchrow_hashref;
.Ve
.PP
.Vb 2
\&  $ary_ref  = $sth->fetchall_arrayref;
\&  $ary_ref  = $sth->fetchall_arrayref( $slice, $max_rows );
.Ve
.PP
.Vb 1
\&  $hash_ref = $sth->fetchall_hashref( $key_field );
.Ve
.PP
.Vb 1
\&  $rv  = $sth->rows;
.Ve
.PP
.Vb 3
\&  $rc  = $dbh->begin_work;
\&  $rc  = $dbh->commit;
\&  $rc  = $dbh->rollback;
.Ve
.PP
.Vb 1
\&  $quoted_string = $dbh->quote($string);
.Ve
.PP
.Vb 3
\&  $rc  = $h->err;
\&  $str = $h->errstr;
\&  $rv  = $h->state;
.Ve
.PP
.Vb 1
\&  $rc  = $dbh->disconnect;
.Ve
.PP
\&\fIThe synopsis above only lists the major methods and parameters.\fR
.Sh "\s-1GETTING\s0 \s-1HELP\s0"
.IX Subsection "GETTING HELP"
If you have questions about \s-1DBI\s0, or \s-1DBD\s0 driver modules, you can get
help from the \fIdbi\-users@perl.org\fR mailing list.  You can get help
on subscribing and using the list by emailing \fIdbi\-users\-help@perl.org\fR.
.PP
To help you make the best use of the dbi-users mailing list,
and any other lists or forums you may use, I \fIstrongly\fR
recommend that you read \*(L"How To Ask Questions The Smart Way\*(R"
by Eric Raymond: <http://www.catb.org/~esr/faqs/smart\-questions.html>.
.PP
If you think you've found a bug then please also read
\&\*(L"How to Report Bugs Effectively\*(R" by Simon Tatham:
<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>.
.PP
The \s-1DBI\s0 home page at <http://dbi.perl.org/> is always worth a visit
and includes an \s-1FAQ\s0 and links to other resources.
.PP
Before asking any questions, reread this document, consult the
archives and read the \s-1DBI\s0 \s-1FAQ\s0. The archives are listed
at the end of this document and on the \s-1DBI\s0 home page.
An \s-1FAQ\s0 is installed as a \s-1DBI::FAQ\s0 module so
you can read it by executing \f(CW\*(C`perldoc DBI::FAQ\*(C'\fR.
However the \s-1DBI::FAQ\s0 module is currently (2004) outdated relative
to the online \s-1FAQ\s0 on the \s-1DBI\s0 home page.
.PP
This document often uses terms like \fIreferences\fR, \fIobjects\fR,
\&\fImethods\fR.  If you're not familar with those terms then it would
be a good idea to read at least the following perl manuals first:
perlreftut, perldsc, perllol, and perlboot.
.PP
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 \fIdbi-users\fR mailing list has lots of experienced
people who should be able to help you if you need it. If you do email
Tim he's very likely to just forward it to the mailing list.
.Sh "\s-1NOTES\s0"
.IX Subsection "NOTES"
This is the \s-1DBI\s0 specification that corresponds to the \s-1DBI\s0 version 1.53.
.PP
The \s-1DBI\s0 is evolving at a steady pace, so it's good to check that
you have the latest copy.
.PP
The significant user-visible changes in each release are documented
in the DBI::Changes module so you can read them by executing
\&\f(CW\*(C`perldoc DBI::Changes\*(C'\fR.
.PP
Some \s-1DBI\s0 changes require changes in the drivers, but the drivers
can take some time to catch up. Newer versions of the \s-1DBI\s0 have
added features that may not yet be supported by the drivers you
use.  Talk to the authors of your drivers if you need a new feature
that's not yet supported.
.PP
Features added after \s-1DBI\s0 1.21 (February 2002) are marked in the
text with the version number of the \s-1DBI\s0 release they first appeared in.
.PP
Extensions to the \s-1DBI\s0 \s-1API\s0 often use the \f(CW\*(C`DBIx::*\*(C'\fR namespace.
See \*(L"Naming Conventions and Name Space\*(R". \s-1DBI\s0 extension modules
can be found at <http://search.cpan.org/search?mode=module&query=DBIx>.
And all modules related to the \s-1DBI\s0 can be found at
<http://search.cpan.org/search?query=DBI&mode=all>.
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \s-1DBI\s0 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.
.PP
It is important to remember that the \s-1DBI\s0 is just an interface.
The \s-1DBI\s0 is a layer
of \*(L"glue\*(R" between an application and one or more database \fIdriver\fR
modules.  It is the driver modules which do most of the real work. The \s-1DBI\s0
provides a standard interface and framework for the drivers to operate
within.
.Sh "Architecture of a \s-1DBI\s0 Application"
.IX Subsection "Architecture of a DBI Application"
.Vb 11
\&             |<- Scope of DBI ->|
\&                  .-.   .--------------.   .-------------.
\&  .-------.       | |---| XYZ Driver   |---| XYZ Engine  |
\&  | Perl  |       | |   `--------------'   `-------------'
\&  | script|  |A|  |D|   .--------------.   .-------------.
\&  | using |--|P|--|B|---|Oracle Driver |---|Oracle Engine|
\&  | DBI   |  |I|  |I|   `--------------'   `-------------'
\&  | API   |       | |...
\&  |methods|       | |... Other drivers
\&  `-------'       | |...
\&                  `-'
.Ve
.PP
The \s-1API\s0, or Application Programming Interface, defines the
call interface and variables for Perl scripts to use. The \s-1API\s0
is implemented by the Perl \s-1DBI\s0 extension.
.PP
The \s-1DBI\s0 \*(L"dispatches\*(R" the method calls to the appropriate driver for
actual execution.  The \s-1DBI\s0 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.
.PP
Each driver
contains implementations of the \s-1DBI\s0 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.
.Sh "Notation and Conventions"
.IX Subsection "Notation and Conventions"
The following conventions are used in this document:
.PP
.Vb 11
\&  $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
\&  \e%attr  Reference to a hash of attribute values passed to methods
.Ve
.PP
Note that Perl will automatically destroy database and statement handle objects
if all references to them are deleted.
.Sh "Outline Usage"
.IX Subsection "Outline Usage"
To use \s-1DBI\s0,
first you need to load the \s-1DBI\s0 module:
.PP
.Vb 2
\&  use DBI;
\&  use strict;
.Ve
.PP
(The \f(CW\*(C`use strict;\*(C'\fR isn't required but is strongly recommended.)
.PP
Then you need to \*(L"connect\*(R" to your data source and get a \fIhandle\fR for that
connection:
.PP
.Vb 2
\&  $dbh = DBI->connect($dsn, $user, $password,
\&                      { RaiseError => 1, AutoCommit => 0 });
.Ve
.PP
Since connecting can be expensive, you generally just connect at the
start of your program and disconnect at the end.
.PP
Explicitly defining the required \f(CW\*(C`AutoCommit\*(C'\fR behaviour 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.
.PP
The \s-1DBI\s0 allows an application to \*(L"prepare\*(R" statements for later
execution.  A prepared statement is identified by a statement handle
held in a Perl variable.
We'll call the Perl variable \f(CW$sth\fR in our examples.
.PP
The typical method call sequence for a \f(CW\*(C`SELECT\*(C'\fR statement is:
.PP
.Vb 4
\&  prepare,
\&    execute, fetch, fetch, ...
\&    execute, fetch, fetch, ...
\&    execute, fetch, fetch, ...
.Ve
.PP
for example:
.PP
.Vb 1
\&  $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?");
.Ve
.PP
.Vb 1
\&  $sth->execute( $baz );
.Ve
.PP
.Vb 3
\&  while ( @row = $sth->fetchrow_array ) {
\&    print "@row\en";
\&  }
.Ve
.PP
The typical method call sequence for a \fInon\fR\-\f(CW\*(C`SELECT\*(C'\fR statement is:
.PP
.Vb 4
\&  prepare,
\&    execute,
\&    execute,
\&    execute.
.Ve
.PP
for example:
.PP
.Vb 1
\&  $sth = $dbh->prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)");
.Ve
.PP
.Vb 5
\&  while(<CSV>) {
\&    chomp;
\&    my ($foo,$bar,$baz) = split /,/;
\&        $sth->execute( $foo, $bar, $baz );
\&  }
.Ve
.PP
The \f(CW\*(C`do()\*(C'\fR method can be used for non repeated \fInon\fR\-\f(CW\*(C`SELECT\*(C'\fR statement
(or with drivers that don't support placeholders):
.PP
.Vb 1
\&  $rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1");
.Ve
.PP
To commit your changes to the database (when \*(L"AutoCommit\*(R" is off):
.PP
.Vb 1
\&  $dbh->commit;  # or call $dbh->rollback; to undo changes
.Ve
.PP
Finally, when you have finished working with the data source, you should
\&\*(L"disconnect\*(R" from it:
.PP
.Vb 1
\&  $dbh->disconnect;
.Ve
.Sh "General Interface Rules & Caveats"
.IX Subsection "General Interface Rules & Caveats"
The \s-1DBI\s0 does not have a concept of a \*(L"current session\*(R". Every session
has a handle object (i.e., a \f(CW$dbh\fR) returned from the \f(CW\*(C`connect\*(C'\fR method.
That handle object is used to invoke database related methods.
.PP
Most data is returned to the Perl script as strings. (Null values are
returned as \f(CW\*(C`undef\*(C'\fR.)  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.
.PP
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.
.PP
Perl supports binary data in Perl strings, and the \s-1DBI\s0 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.
.PP
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 behaviour, then it should do so; it should not require
the application to do that.
.PP
Multiple \s-1SQL\s0 statements may not be combined in a single statement
handle (\f(CW$sth\fR), although some databases and drivers do support this
(notably Sybase and \s-1SQL\s0 Server).
.PP
Non-sequential record reads are not supported in this version of the \s-1DBI\s0.
In other words, records can only be fetched in the order that the
database returned them, and once fetched they are forgotten.
.PP
Positioned updates and deletes are not directly supported by the \s-1DBI\s0.
See the description of the \f(CW\*(C`CursorName\*(C'\fR attribute for an alternative.
.PP
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 \s-1DBI\s0 \f(CW\*(C`func()\*(C'\fR method.
Private driver attributes are accessed just like standard attributes.
.PP
Many methods have an optional \f(CW\*(C`\e%attr\*(C'\fR parameter which can be used to
pass information to the driver implementing the method. Except where
specifically documented, the \f(CW\*(C`\e%attr\*(C'\fR parameter can only be used to pass
driver specific hints. In general, you can ignore \f(CW\*(C`\e%attr\*(C'\fR parameters
or pass it as \f(CW\*(C`undef\*(C'\fR.
.Sh "Naming Conventions and Name Space"
.IX Subsection "Naming Conventions and Name Space"
The \s-1DBI\s0 package and all packages below it (\f(CW\*(C`DBI::*\*(C'\fR) are reserved for
use by the \s-1DBI\s0. Extensions and related modules use the \f(CW\*(C`DBIx::\*(C'\fR
namespace (see <http://www.perl.com/CPAN/modules/by\-module/DBIx/>).
Package names beginning with \f(CW\*(C`DBD::\*(C'\fR are reserved for use
by \s-1DBI\s0 database drivers.  All environment variables used by the \s-1DBI\s0
or by individual DBDs begin with "\f(CW\*(C`DBI_\*(C'\fR\*(L" or \*(R"\f(CW\*(C`DBD_\*(C'\fR".
.PP
The letter case used for attribute names is significant and plays an
important part in the portability of \s-1DBI\s0 scripts.  The case of the
attribute name is used to signify who defined the meaning of that name
and its values.
.PP
.Vb 5
\&  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)
.Ve
.PP
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., "\f(CW\*(C`ora_\*(C'\fR\*(L" for Oracle, \*(R"\f(CW\*(C`ing_\*(C'\fR" for Ingres, etc).
.Sh "\s-1SQL\s0 \- A Query Language"
.IX Subsection "SQL - A Query Language"
Most \s-1DBI\s0 drivers require applications to use a dialect of \s-1SQL\s0
(Structured Query Language) to interact with the database engine.
The \*(L"Standards Reference Information\*(R" section provides links
to useful information about \s-1SQL\s0.
.PP
The \s-1DBI\s0 itself does not mandate or require any particular language to
be used; it is language independent. In \s-1ODBC\s0 terms, the \s-1DBI\s0 is in
\&\*(L"pass\-thru\*(R" 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"prepare\*(R" or
\&\*(L"do\*(R" methods.
.PP
For an interesting diversion on the \fIreal\fR history of \s-1RDBMS\s0 and \s-1SQL\s0,
from the people who made it happen, see:
.PP
.Vb 1
\&  http://ftp.digital.com/pub/DEC/SRC/technical-notes/SRC-1997-018-html/sqlr95.html
.Ve
.PP
Follow the \*(L"Full Contents\*(R" then \*(L"Intergalactic dataspeak\*(R" links for the
\&\s-1SQL\s0 history.
.Sh "Placeholders and Bind Values"
.IX Subsection "Placeholders and Bind Values"
Some drivers support placeholders and bind values.
\&\fIPlaceholders\fR, 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 \s-1SALES\s0 table:
.PP
.Vb 1
\&  INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
.Ve
.PP
or the following, to select the description for a product:
.PP
.Vb 1
\&  SELECT description FROM products WHERE product_code = ?
.Ve
.PP
The \f(CW\*(C`?\*(C'\fR characters are the placeholders.  The association of actual
values with placeholders is known as \fIbinding\fR, and the values are
referred to as \fIbind values\fR.
.PP
Note that the \f(CW\*(C`?\*(C'\fR is not enclosed in quotation marks, even when the
placeholder represents a string.  Some drivers also allow placeholders
like \f(CW\*(C`:\*(C'\fR\fIname\fR and \f(CW\*(C`:\*(C'\fR\fIn\fR (e.g., \f(CW\*(C`:1\*(C'\fR, \f(CW\*(C`:2\*(C'\fR, and so on)
in addition to \f(CW\*(C`?\*(C'\fR, but their use is not portable.
.PP
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:
.PP
.Vb 2
\&  "SELECT name, age FROM ?"         # wrong (will probably fail)
\&  "SELECT name, ?   FROM people"    # wrong (but may not 'fail')
.Ve
.PP
Also, placeholders can only represent single scalar values.
For example, the following
statement won't work as expected for more than one value:
.PP
.Vb 2
\&  "SELECT name, age FROM people WHERE name IN (?)"    # wrong
\&  "SELECT name, age FROM people WHERE name IN (?,?)"  # two names
.Ve
.PP
When using placeholders with the \s-1SQL\s0 \f(CW\*(C`LIKE\*(C'\fR qualifier, you must
remember that the placeholder substitutes for the whole string.
So you should use "\f(CW\*(C`... LIKE ? ...\*(C'\fR" and include any wildcard
characters in the value that you bind to the placeholder.
.PP
\&\fB\s-1NULL\s0 Values\fR
.PP
Undefined values, or \f(CW\*(C`undef\*(C'\fR, are used to indicate \s-1NULL\s0 values.
You can insert and update columns with a \s-1NULL\s0 value as you would a
non-NULL value.  These examples insert and update the column
\&\f(CW\*(C`age\*(C'\fR with a \s-1NULL\s0 value:
.PP
.Vb 4
\&  $sth = $dbh->prepare(qq{
\&    INSERT INTO people (fullname, age) VALUES (?, ?)
\&  });
\&  $sth->execute("Joe Bloggs", undef);
.Ve
.PP
.Vb 4
\&  $sth = $dbh->prepare(qq{
\&    UPDATE people SET age = ? WHERE fullname = ?
\&  });
\&  $sth->execute(undef, "Joe Bloggs");
.Ve
.PP
However, care must be taken when trying to use \s-1NULL\s0 values in a
\&\f(CW\*(C`WHERE\*(C'\fR clause.  Consider:
.PP
.Vb 1
\&  SELECT fullname FROM people WHERE age = ?
.Ve
.PP
Binding an \f(CW\*(C`undef\*(C'\fR (\s-1NULL\s0) to the placeholder will \fInot\fR select rows
which have a \s-1NULL\s0 \f(CW\*(C`age\*(C'\fR!  At least for database engines that
conform to the \s-1SQL\s0 standard.  Refer to the \s-1SQL\s0 manual for your database
engine or any \s-1SQL\s0 book for the reasons for this.  To explicitly select
NULLs you have to say "\f(CW\*(C`WHERE age IS NULL\*(C'\fR".
.PP
A common issue is to have a code fragment handle a value that could be
either \f(CW\*(C`defined\*(C'\fR or \f(CW\*(C`undef\*(C'\fR (non\-NULL or \s-1NULL\s0) at runtime.
A simple technique is to prepare the appropriate statement as needed,
and substitute the placeholder for non-NULL cases:
.PP
.Vb 5
\&  $sql_clause = defined $age? "age = ?" : "age IS NULL";
\&  $sth = $dbh->prepare(qq{
\&    SELECT fullname FROM people WHERE $sql_clause
\&  });
\&  $sth->execute(defined $age ? $age : ());
.Ve
.PP
The following technique illustrates qualifying a \f(CW\*(C`WHERE\*(C'\fR clause with
several columns, whose associated values (\f(CW\*(C`defined\*(C'\fR or \f(CW\*(C`undef\*(C'\fR) are
in a hash \f(CW%h:\fR
.PP
.Vb 14
\&  for my $col ("age", "phone", "email") {
\&    if (defined $h{$col}) {
\&      push @sql_qual, "$col = ?";
\&      push @sql_bind, $h{$col};
\&    }
\&    else {
\&      push @sql_qual, "$col IS NULL";
\&    }
\&  }
\&  $sql_clause = join(" AND ", @sql_qual);
\&  $sth = $dbh->prepare(qq{
\&      SELECT fullname FROM people WHERE $sql_clause
\&  });
\&  $sth->execute(@sql_bind);
.Ve
.PP
The techniques above call prepare for the \s-1SQL\s0 statement with each call to
execute.  Because calls to \fIprepare()\fR can be expensive, performance
can suffer when an application iterates many times over statements
like the above.
.PP
A better solution is a single \f(CW\*(C`WHERE\*(C'\fR clause that supports both
\&\s-1NULL\s0 and non-NULL comparisons.  Its \s-1SQL\s0 statement would need to be
prepared only once for all cases, thus improving performance.
Several examples of \f(CW\*(C`WHERE\*(C'\fR clauses that support this are presented
below.  But each example lacks portability, robustness, or simplicity.
Whether an example is supported on your database engine depends on
what \s-1SQL\s0 extensions it provides, and where it supports the \f(CW\*(C`?\*(C'\fR
placeholder in a statement.
.PP
.Vb 7
\&  0)  age = ?
\&  1)  NVL(age, xx) = NVL(?, xx)
\&  2)  ISNULL(age, xx) = ISNULL(?, xx)
\&  3)  DECODE(age, ?, 1, 0) = 1
\&  4)  age = ? OR (age IS NULL AND ? IS NULL)
\&  5)  age = ? OR (age IS NULL AND SP_ISNULL(?) = 1)
\&  6)  age = ? OR (age IS NULL AND ? = 1)
.Ve
.PP
Statements formed with the above \f(CW\*(C`WHERE\*(C'\fR clauses require execute
statements as follows.  The arguments are required, whether their
values are \f(CW\*(C`defined\*(C'\fR or \f(CW\*(C`undef\*(C'\fR.
.PP
.Vb 3
\&  0,1,2,3)  $sth->execute($age);
\&  4,5)      $sth->execute($age, $age);
\&  6)        $sth->execute($age, defined($age) ? 0 : 1);
.Ve
.PP
Example 0 should not work (as mentioned earlier), but may work on
a few database engines anyway (e.g. Sybase).  Example 0 is part
of examples 4, 5, and 6, so if example 0 works, these other
examples may work, even if the engine does not properly support
the right hand side of the \f(CW\*(C`OR\*(C'\fR expression.
.PP
Examples 1 and 2 are not robust: they require that you provide a
valid column value xx (e.g. '~') which is not present in any row.
That means you must have some notion of what data won't be stored
in the column, and expect clients to adhere to that.
.PP
Example 5 requires that you provide a stored procedure (\s-1SP_ISNULL\s0
in this example) that acts as a function: it checks whether a value
is null, and returns 1 if it is, or 0 if not.
.PP
Example 6, the least simple, is probably the most portable, i.e., it
should work with with most, if not all, database engines.
.PP
Here is a table that indicates which examples above are known to
work on various database engines:
.PP
.Vb 8
\&                   -----Examples------
\&                   0  1  2  3  4  5  6
\&                   -  -  -  -  -  -  -
\&  Oracle 9         N  Y  N  Y  Y  ?  Y
\&  Informix IDS 9   N  N  N  Y  N  Y  Y
\&  MS SQL           N  N  Y  N  Y  ?  Y
\&  Sybase           Y  N  N  N  N  N  Y
\&  AnyData,DBM,CSV  Y  N  N  N  Y  Y* Y
.Ve
.PP
* Works only because Example 0 works.
.PP
\&\s-1DBI\s0 provides a sample perl script that will test the examples above
on your database engine and tell you which ones work.  It is located
in the \fIex/\fR subdirectory of the \s-1DBI\s0 source distribution, or here:
<http://svn.perl.org/modules/dbi/trunk/ex/perl_dbi_nulls_test.pl>
Please use the script to help us fill-in and maintain this table.
.PP
\&\fBPerformance\fR
.PP
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 \f(CW\*(C`execute\*(C'\fR 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:
.PP
.Vb 9
\&  my $sth = $dbh->prepare(q{
\&    INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
\&  }) or die $dbh->errstr;
\&  while (<>) {
\&      chomp;
\&      my ($product_code, $qty, $price) = split /,/;
\&      $sth->execute($product_code, $qty, $price) or die $dbh->errstr;
\&  }
\&  $dbh->commit or die $dbh->errstr;
.Ve
.PP
See \*(L"execute\*(R" and \*(L"bind_param\*(R" for more details.
.PP
The \f(CW\*(C`q{...}\*(C'\fR style quoting used in this example avoids clashing with
quotes that may be used in the \s-1SQL\s0 statement. Use the double-quote like
\&\f(CW\*(C`qq{...}\*(C'\fR operator if you want to interpolate variables into the string.
See \*(L"Quote and Quote-like Operators\*(R" in perlop for more details.
.PP
See also the \*(L"bind_columns\*(R" method, which is used to associate Perl
variables with the output columns of a \f(CW\*(C`SELECT\*(C'\fR statement.
.SH "THE DBI PACKAGE AND CLASS"
.IX Header "THE DBI PACKAGE AND CLASS"
In this section, we cover the \s-1DBI\s0 class methods, utility functions,
and the dynamic attributes associated with generic \s-1DBI\s0 handles.
.Sh "\s-1DBI\s0 Constants"
.IX Subsection "DBI Constants"
Constants representing the values of the \s-1SQL\s0 standard types can be
imported individually by name, or all together by importing the
special \f(CW\*(C`:sql_types\*(C'\fR tag.
.PP
The names and values of all the defined \s-1SQL\s0 standard types can be
produced like this:
.PP
.Vb 3
\&  foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
\&    printf "%s=%d\en", $_, &{"DBI::$_"};
\&  }
.Ve
.PP
These constants are defined by \s-1SQL/CLI\s0, \s-1ODBC\s0 or both.
\&\f(CW\*(C`SQL_BIGINT\*(C'\fR is (currently) omitted, because \s-1SQL/CLI\s0 and \s-1ODBC\s0 provide
conflicting codes.
.PP
See the \*(L"type_info\*(R", \*(L"type_info_all\*(R", and \*(L"bind_param\*(R" methods
for possible uses.
.PP
Note that just because the \s-1DBI\s0 defines a named constant for a given
data type doesn't mean that drivers will support that data type.
.Sh "\s-1DBI\s0 Class Methods"
.IX Subsection "DBI Class Methods"
The following methods are provided by the \s-1DBI\s0 class:
.ie n .IP """parse_dsn""" 4
.el .IP "\f(CWparse_dsn\fR" 4
.IX Item "parse_dsn"
.Vb 2
\&  ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn($dsn)
\&      or die "Can't parse DBI DSN '$dsn'";
.Ve
.Sp
Breaks apart a \s-1DBI\s0 Data Source Name (\s-1DSN\s0) and returns the individual
parts. If \f(CW$dsn\fR doesn't contain a valid \s-1DSN\s0 then \fIparse_dsn()\fR returns
an empty list.
.Sp
$scheme is the first part of the \s-1DSN\s0 and is currently always 'dbi'.
\&\f(CW$driver\fR is the driver name, possibly defaulted to \f(CW$ENV\fR{\s-1DBI_DRIVER\s0},
and may be undefined.  \f(CW$attr_string\fR is the contents of the optional attribute
string, which may be undefined.  If \f(CW$attr_string\fR is not empty then \f(CW$attr_hash\fR
is a reference to a hash containing the parsed attribute names and values.
\&\f(CW$driver_dsn\fR is the last part of the \s-1DBI\s0 \s-1DSN\s0 string. For example:
.Sp
.Vb 7
\&  ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn)
\&      = DBI->parse_dsn("DBI:MyDriver(RaiseError=>1):db=test;port=42");
\&  $scheme      = 'dbi';
\&  $driver      = 'MyDriver';
\&  $attr_string = 'RaiseError=>1';
\&  $attr_hash   = { 'RaiseError' => '1' };
\&  $driver_dsn  = 'db=test;port=42';
.Ve
.Sp
The \fIparse_dsn()\fR method was added in \s-1DBI\s0 1.43.
.ie n .IP """connect""" 4
.el .IP "\f(CWconnect\fR" 4
.IX Item "connect"
.Vb 4
\&  $dbh = DBI->connect($data_source, $username, $password)
\&            or die $DBI::errstr;
\&  $dbh = DBI->connect($data_source, $username, $password, \e%attr)
\&            or die $DBI::errstr;
.Ve
.Sp
Establishes a database connection, or session, to the requested \f(CW$data_source\fR.
Returns a database handle object if the connection succeeds. Use
\&\f(CW\*(C`$dbh\->disconnect\*(C'\fR to terminate the connection.
.Sp
If the connect fails (see below), it returns \f(CW\*(C`undef\*(C'\fR and sets both \f(CW$DBI::err\fR
and \f(CW$DBI::errstr\fR. (It does \fInot\fR explicitly set \f(CW$!\fR.) You should generally
test the return status of \f(CW\*(C`connect\*(C'\fR and \f(CW\*(C`print $DBI::errstr\*(C'\fR if it has failed.
.Sp
Multiple simultaneous connections to multiple databases through multiple
drivers can be made via the \s-1DBI\s0. Simply make one \f(CW\*(C`connect\*(C'\fR call for each
database and keep a copy of each returned database handle.
.Sp
The \f(CW$data_source\fR value must begin with "\f(CW\*(C`dbi:\*(C'\fR\fIdriver_name\fR\f(CW\*(C`:\*(C'\fR".
The \fIdriver_name\fR specifies the driver that will be used to make the
connection. (Letter case is significant.)
.Sp
As a convenience, if the \f(CW$data_source\fR parameter is undefined or empty,
the \s-1DBI\s0 will substitute the value of the environment variable \f(CW\*(C`DBI_DSN\*(C'\fR.
If just the \fIdriver_name\fR part is empty (i.e., the \f(CW$data_source\fR
prefix is "\f(CW\*(C`dbi::\*(C'\fR"), the environment variable \f(CW\*(C`DBI_DRIVER\*(C'\fR is
used. If neither variable is set, then \f(CW\*(C`connect\*(C'\fR dies.
.Sp
Examples of \f(CW$data_source\fR values are:
.Sp
.Vb 3
\&  dbi:DriverName:database_name
\&  dbi:DriverName:database_name@hostname:port
\&  dbi:DriverName:database=database_name;host=hostname;port=port
.Ve
.Sp
There is \fIno standard\fR for the text following the driver name. Each
driver is free to use whatever syntax it wants. The only requirement the
\&\s-1DBI\s0 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.
.Sp
It is recommended that drivers support the \s-1ODBC\s0 style, shown in the
last example above. It is also recommended that that they support the
three common names '\f(CW\*(C`host\*(C'\fR', '\f(CW\*(C`port\*(C'\fR', and '\f(CW\*(C`database\*(C'\fR' (plus '\f(CW\*(C`db\*(C'\fR'
as an alias for \f(CW\*(C`database\*(C'\fR). This simplifies automatic construction
of basic DSNs: \f(CW"dbi:$driver:database=$db;host=$host;port=$port"\fR.
Drivers should aim to 'do something reasonable' when given a \s-1DSN\s0
in this form, but if any part is meaningless for that driver (such
as 'port' for Informix) it should generate an error if that part
is not empty.
.Sp
If the environment variable \f(CW\*(C`DBI_AUTOPROXY\*(C'\fR is defined (and the
driver in \f(CW$data_source\fR is not "\f(CW\*(C`Proxy\*(C'\fR") then the connect request
will automatically be changed to:
.Sp
.Vb 1
\&  $ENV{DBI_AUTOPROXY};dsn=$data_source
.Ve
.Sp
\&\f(CW\*(C`DBI_AUTOPROXY\*(C'\fR is typically set as "\f(CW\*(C`dbi:Proxy:hostname=...;port=...\*(C'\fR".
If \f(CW$ENV\fR{\s-1DBI_AUTOPROXY\s0} doesn't begin with '\f(CW\*(C`dbi:\*(C'\fR' then \*(L"dbi:Proxy:\*(R"
will be prepended to it first.  See the DBD::Proxy documentation
for more details.
.Sp
If \f(CW$username\fR or \f(CW$password\fR are undefined (rather than just empty),
then the \s-1DBI\s0 will substitute the values of the \f(CW\*(C`DBI_USER\*(C'\fR and \f(CW\*(C`DBI_PASS\*(C'\fR
environment variables, respectively.  The \s-1DBI\s0 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.
See below for alternative way to specify the username and password.
.Sp
\&\f(CW\*(C`DBI\->connect\*(C'\fR automatically installs the driver if it has not been
installed yet. Driver installation either returns a valid driver
handle, or it \fIdies\fR with an error message that includes the string
"\f(CW\*(C`install_driver\*(C'\fR" and the underlying problem. So \f(CW\*(C`DBI\->connect\*(C'\fR
will die
on a driver installation failure and will only return \f(CW\*(C`undef\*(C'\fR on a
connect failure, in which case \f(CW$DBI::errstr\fR will hold the error message.
Use \f(CW\*(C`eval { ... }\*(C'\fR if you need to catch the "\f(CW\*(C`install_driver\*(C'\fR" error.
.Sp
The \f(CW$data_source\fR argument (with the "\f(CW\*(C`dbi:...:\*(C'\fR" prefix removed) and the
\&\f(CW$username\fR and \f(CW$password\fR arguments are then passed to the driver for
processing. The \s-1DBI\s0 does not define any interpretation for the
contents of these fields.  The driver is free to interpret the
\&\f(CW$data_source\fR, \f(CW$username\fR, and \f(CW$password\fR fields in any way, and supply
whatever defaults are appropriate for the engine being accessed.
(Oracle, for example, uses the \s-1ORACLE_SID\s0 and \s-1TWO_TASK\s0 environment
variables if no \f(CW$data_source\fR is specified.)
.Sp
The \f(CW\*(C`AutoCommit\*(C'\fR and \f(CW\*(C`PrintError\*(C'\fR attributes for each connection
default to \*(L"on\*(R". (See \*(L"AutoCommit\*(R" and \*(L"PrintError\*(R" for more information.)
However, it is strongly recommended that you explicitly define \f(CW\*(C`AutoCommit\*(C'\fR
rather than rely on the default. The \f(CW\*(C`PrintWarn\*(C'\fR attribute defaults to
on if $^W is true, i.e., perl is running with warnings enabled.
.Sp
The \f(CW\*(C`\e%attr\*(C'\fR parameter can be used to alter the default settings of
\&\f(CW\*(C`PrintError\*(C'\fR, \f(CW\*(C`RaiseError\*(C'\fR, \f(CW\*(C`AutoCommit\*(C'\fR, and other attributes. For example:
.Sp
.Vb 4
\&  $dbh = DBI->connect($data_source, $user, $pass, {
\&        PrintError => 0,
\&        AutoCommit => 0
\&  });
.Ve
.Sp
The username and password can also be specified using the attributes
\&\f(CW\*(C`Username\*(C'\fR and \f(CW\*(C`Password\*(C'\fR, in which case they take precedence
over the \f(CW$username\fR and \f(CW$password\fR parameters.
.Sp
You can also define connection attribute values within the \f(CW$data_source\fR
parameter. For example:
.Sp
.Vb 1
\&  dbi:DriverName(PrintWarn=>1,PrintError=>0,Taint=>1):...
.Ve
.Sp
Individual attributes values specified in this way take precedence over
any conflicting values specified via the \f(CW\*(C`\e%attr\*(C'\fR parameter to \f(CW\*(C`connect\*(C'\fR.
.Sp
The \f(CW\*(C`dbi_connect_method\*(C'\fR 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).
.Sp
Where possible, each session (\f(CW$dbh\fR) 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.
.Sp
For compatibility with old \s-1DBI\s0 scripts, the driver can be specified by
passing its name as the fourth argument to \f(CW\*(C`connect\*(C'\fR (instead of \f(CW\*(C`\e%attr\*(C'\fR):
.Sp
.Vb 1
\&  $dbh = DBI->connect($data_source, $user, $pass, $driver);
.Ve
.Sp
In this \*(L"old\-style\*(R" form of \f(CW\*(C`connect\*(C'\fR, the \f(CW$data_source\fR should not start
with "\f(CW\*(C`dbi:driver_name:\*(C'\fR". (If it does, the embedded driver_name
will be ignored). Also note that in this older form of \f(CW\*(C`connect\*(C'\fR,
the \f(CW\*(C`$dbh\->{AutoCommit}\*(C'\fR attribute is \fIundefined\fR, the
\&\f(CW\*(C`$dbh\->{PrintError}\*(C'\fR attribute is off, and the old \f(CW\*(C`DBI_DBNAME\*(C'\fR
environment variable is
checked if \f(CW\*(C`DBI_DSN\*(C'\fR is not defined. Beware that this \*(L"old\-style\*(R"
\&\f(CW\*(C`connect\*(C'\fR will soon be withdrawn in a future version of \s-1DBI\s0.
.ie n .IP """connect_cached""" 4
.el .IP "\f(CWconnect_cached\fR" 4
.IX Item "connect_cached"
.Vb 4
\&  $dbh = DBI->connect_cached($data_source, $username, $password)
\&            or die $DBI::errstr;
\&  $dbh = DBI->connect_cached($data_source, $username, $password, \e%attr)
\&            or die $DBI::errstr;
.Ve
.Sp
\&\f(CW\*(C`connect_cached\*(C'\fR is like \*(L"connect\*(R", except that the database handle
returned is also
stored in a hash associated with the given parameters. If another call
is made to \f(CW\*(C`connect_cached\*(C'\fR with the same parameter values, then the
corresponding cached \f(CW$dbh\fR 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 \f(CW\*(C`ping\*(C'\fR method fails.
.Sp
That the behaviour of this method differs in several respects from the
behaviour of persistent connections implemented by Apache::DBI.
However, if Apache::DBI is loaded then \f(CW\*(C`connect_cached\*(C'\fR will use it.
.Sp
Caching connections can be useful in some applications, but it can
also cause problems, such as too many connections, and so should
be used with care. In particular, avoid changing the attributes of
a database handle created via \fIconnect_cached()\fR because it will affect
other code that may be using the same handle.
.Sp
Where multiple separate parts of a program are using \fIconnect_cached()\fR
to connect to the same database with the same (initial) attributes
it is a good idea to add a private attribute to the \fIconnect_cached()\fR
call to effectively limit the scope of the caching. For example:
.Sp
.Vb 1
\&  DBI->connect_cached(..., { private_foo_cachekey => "Bar", ... });
.Ve
.Sp
Handles returned from that \fIconnect_cached()\fR call will only be returned
by other \fIconnect_cached()\fR call elsewhere in the code if those other
calls also pass in the same attribute values, including the private one.
(I've used \f(CW\*(C`private_foo_cachekey\*(C'\fR here as an example, you can use
any attribute name with a \f(CW\*(C`private_\*(C'\fR prefix.)
.Sp
Taking that one step further, you can limit a particular \fIconnect_cached()\fR
call to return handles unique to that one place in the code by setting the
private attribute to a unique value for that place:
.Sp
.Vb 1
\&  DBI->connect_cached(..., { private_foo_cachekey => __FILE__.__LINE__, ... });
.Ve
.Sp
By using a private attribute you still get connection caching for
the individual calls to \fIconnect_cached()\fR but, by making separate
database conections for separate parts of the code, the database
handles are isolated from any attribute changes made to other handles.
.Sp
The cache can be accessed (and cleared) via the \*(L"CachedKids\*(R" attribute:
.Sp
.Vb 2
\&  my $CachedKids_hashref = $dbh->{Driver}->{CachedKids};
\&  %$CachedKids_hashref = () if $CachedKids_hashref;
.Ve
.ie n .IP """available_drivers""" 4
.el .IP "\f(CWavailable_drivers\fR" 4
.IX Item "available_drivers"
.Vb 2
\&  @ary = DBI->available_drivers;
\&  @ary = DBI->available_drivers($quiet);
.Ve
.Sp
Returns a list of all available drivers by searching for \f(CW\*(C`DBD::*\*(C'\fR modules
through the directories in \f(CW@INC\fR. 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 \f(CW$quiet\fR will inhibit the warning.
.ie n .IP """installed_drivers""" 4
.el .IP "\f(CWinstalled_drivers\fR" 4
.IX Item "installed_drivers"
.Vb 1
\&  %drivers = DBI->installed_drivers();
.Ve
.Sp
Returns a list of driver name and driver handle pairs for all drivers
\&'installed' (loaded) into the current process.  The driver name does not
include the '\s-1DBD::\s0' prefix.
.Sp
To get a list of all drivers available in your perl instalation you can use
\&\*(L"available_drivers\*(R".
.Sp
Added in \s-1DBI\s0 1.49.
.ie n .IP """installed_versions""" 4
.el .IP "\f(CWinstalled_versions\fR" 4
.IX Item "installed_versions"
.Vb 3
\&  DBI->installed_versions;
\&  @ary  = DBI->installed_versions;
\&  %hash = DBI->installed_versions;
.Ve
.Sp
Calls \fIavailable_drivers()\fR and attempts to load each of them in turn
using \fIinstall_driver()\fR.  For each load that succeeds the driver
name and version number are added to a hash. When running under
DBI::PurePerl drivers which appear not be pure-perl are ignored.
.Sp
When called in array context the list of successfully loaded drivers
is returned (without the '\s-1DBD::\s0' prefix).
.Sp
When called in scalar context a reference to the hash is returned
and the hash will also contain other entries for the \f(CW\*(C`DBI\*(C'\fR version,
\&\f(CW\*(C`OS\*(C'\fR name, etc.
.Sp
When called in a void context the \fIinstalled_versions()\fR method will
print out a formatted list of the hash contents, one per line.
.Sp
Due to the potentially high memory cost and unknown risks of loading
in an unknown number of drivers that just happen to be installed
on the system, this method is nor recommended for general use.
Use \fIavailable_drivers()\fR instead.
.Sp
The \fIinstalled_versions()\fR method is primarily intended as a quick
way to see from the command line what's installed. For example:
.Sp
.Vb 1
\&  perl -MDBI -e 'DBI->installed_versions'
.Ve
.Sp
The \fIinstalled_versions()\fR method was added in \s-1DBI\s0 1.38.
.ie n .IP """data_sources""" 4
.el .IP "\f(CWdata_sources\fR" 4
.IX Item "data_sources"
.Vb 2
\&  @ary = DBI->data_sources($driver);
\&  @ary = DBI->data_sources($driver, \e%attr);
.Ve
.Sp
Returns a list of data sources (databases) available via the named
driver.  If \f(CW$driver\fR is empty or \f(CW\*(C`undef\*(C'\fR, then the value of the
\&\f(CW\*(C`DBI_DRIVER\*(C'\fR environment variable is used.
.Sp
The driver will be loaded if it hasn't been already. Note that if the
driver loading fails then \fIdata_sources()\fR \fIdies\fR with an error message
that includes the string "\f(CW\*(C`install_driver\*(C'\fR" and the underlying problem.
.Sp
Data sources are returned in a form suitable for passing to the
\&\*(L"connect\*(R" method (that is, they will include the "\f(CW\*(C`dbi:$driver:\*(C'\fR" prefix).
.Sp
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.
.Sp
There is also a \fIdata_sources()\fR method defined for database handles.
.ie n .IP """trace""" 4
.el .IP "\f(CWtrace\fR" 4
.IX Item "trace"
.Vb 3
\&  DBI->trace($trace_setting)
\&  DBI->trace($trace_setting, $trace_filename)
\&  $trace_setting = DBI->trace;
.Ve
.Sp
The \f(CW\*(C`DBI\->trace\*(C'\fR method sets the \fIglobal default\fR trace
settings and returns the \fIprevious\fR trace settings. It can also
be used to change where the trace output is sent.
.Sp
There's a similar method, \f(CW\*(C`$h\->trace\*(C'\fR, which sets the trace
settings for the specific handle it's called on.
.Sp
See the \*(L"\s-1TRACING\s0\*(R" section for full details about the \s-1DBI\s0's powerful
tracing facilities.
.Sh "\s-1DBI\s0 Utility Functions"
.IX Subsection "DBI Utility Functions"
In addition to the \s-1DBI\s0 methods listed in the previous section,
the \s-1DBI\s0 package also provides several utility functions.
.PP
These can be imported into your code by listing them in
the \f(CW\*(C`use\*(C'\fR statement. For example:
.PP
.Vb 1
\&  use DBI qw(neat data_diff);
.Ve
.PP
Alternatively, all these utility functions (except hash) can be
imported using the \f(CW\*(C`:utils\*(C'\fR import tag. For example:
.PP
.Vb 1
\&  use DBI qw(:utils);
.Ve
.ie n .IP """data_string_desc""" 4
.el .IP "\f(CWdata_string_desc\fR" 4
.IX Item "data_string_desc"
.Vb 1
\&  $description = data_string_desc($string);
.Ve
.Sp
Returns an informal description of the string. For example:
.Sp
.Vb 5
\&  UTF8 off, ASCII, 42 characters 42 bytes
\&  UTF8 off, non-ASCII, 42 characters 42 bytes
\&  UTF8 on, non-ASCII, 4 characters 6 bytes
\&  UTF8 on but INVALID encoding, non-ASCII, 4 characters 6 bytes
\&  UTF8 off, undef
.Ve
.Sp
The initial \f(CW\*(C`UTF8\*(C'\fR on/off refers to Perl's internal SvUTF8 flag.
If \f(CW$string\fR has the SvUTF8 flag set but the sequence of bytes it
contains are not a valid \s-1UTF\-8\s0 encoding then \fIdata_string_desc()\fR
will report \f(CW\*(C`UTF8 on but INVALID encoding\*(C'\fR.
.Sp
The \f(CW\*(C`ASCII\*(C'\fR vs \f(CW\*(C`non\-ASCII\*(C'\fR portion shows \f(CW\*(C`ASCII\*(C'\fR if \fIall\fR the
characters in the string are \s-1ASCII\s0 (have code points <= 127).
.Sp
The \fIdata_string_desc()\fR function was added in \s-1DBI\s0 1.46.
.ie n .IP """data_string_diff""" 4
.el .IP "\f(CWdata_string_diff\fR" 4
.IX Item "data_string_diff"
.Vb 1
\&  $diff = data_string_diff($a, $b);
.Ve
.Sp
Returns an informal description of the first character difference
between the strings. If both \f(CW$a\fR and \f(CW$b\fR contain the same sequence
of characters then \fIdata_string_diff()\fR returns an empty string.
For example:
.Sp
.Vb 6
\& Params a & b     Result
\& ------------     ------
\& 'aaa', 'aaa'     ''
\& 'aaa', 'abc'     'Strings differ at index 2: a[2]=a, b[2]=b'
\& 'aaa', undef     'String b is undef, string a has 3 characters'
\& 'aaa', 'aa'      'String b truncated after 2 characters'
.Ve
.Sp
Unicode characters are reported in \f(CW\*(C`\ex{XXXX}\*(C'\fR format. Unicode
code points in the range U+0800 to U+08FF are unassigned and most
likely to occur due to double\-encoding. Characters in this range
are reported as \f(CW\*(C`\ex{08XX}='C'\*(C'\fR where \f(CW\*(C`C\*(C'\fR is the corresponding
latin\-1 character.
.Sp
The \fIdata_string_diff()\fR function only considers logical \fIcharacters\fR
and not the underlying encoding. See \*(L"data_diff\*(R" for an alternative.
.Sp
The \fIdata_string_diff()\fR function was added in \s-1DBI\s0 1.46.
.ie n .IP """data_diff""" 4
.el .IP "\f(CWdata_diff\fR" 4
.IX Item "data_diff"
.Vb 2
\&  $diff = data_diff($a, $b);
\&  $diff = data_diff($a, $b, $logical);
.Ve
.Sp
Returns an informal description of the difference between two strings.
It calls \*(L"data_string_desc\*(R" and \*(L"data_string_diff\*(R"
and returns the combined results as a multi-line string.
.Sp
For example, \f(CW\*(C`data_diff("abc", "ab\ex{263a}")\*(C'\fR will return:
.Sp
.Vb 3
\&  a: UTF8 off, ASCII, 3 characters 3 bytes
\&  b: UTF8 on, non-ASCII, 3 characters 5 bytes
\&  Strings differ at index 2: a[2]=c, b[2]=\ex{263A}
.Ve
.Sp
If \f(CW$a\fR and \f(CW$b\fR are identical in both the characters they contain \fIand\fR
their physical encoding then \fIdata_diff()\fR returns an empty string.
If \f(CW$logical\fR is true then physical encoding differences are ignored
(but are still reported if there is a difference in the characters).
.Sp
The \fIdata_diff()\fR function was added in \s-1DBI\s0 1.46.
.ie n .IP """neat""" 4
.el .IP "\f(CWneat\fR" 4
.IX Item "neat"
.Vb 2
\&  $str = neat($value);
\&  $str = neat($value, $maxlen);
.Ve
.Sp
Return a string containing a neat (and tidy) representation of the
supplied value.
.Sp
Strings will be quoted, although internal quotes will \fInot\fR be escaped.
Values known to be numeric will be unquoted. Undefined (\s-1NULL\s0) values
will be shown as \f(CW\*(C`undef\*(C'\fR (without quotes).
.Sp
If the string is flagged internally as utf8 then double quotes will
be used, otherwise single quotes are used and unprintable characters
will be replaced by dot (.).
.Sp
For result strings longer than \f(CW$maxlen\fR the result string will be
truncated to \f(CW\*(C`$maxlen\-4\*(C'\fR and "\f(CW\*(C`...'\*(C'\fR" will be appended.  If \f(CW$maxlen\fR is 0
or \f(CW\*(C`undef\*(C'\fR, it defaults to \f(CW$DBI::neat_maxlen\fR which, in turn, defaults to 400.
.Sp
This function is designed to format values for human consumption.
It is used internally by the \s-1DBI\s0 for \*(L"trace\*(R" output. It should
typically \fInot\fR be used for formatting values for database use.
(See also \*(L"quote\*(R".)
.ie n .IP """neat_list""" 4
.el .IP "\f(CWneat_list\fR" 4
.IX Item "neat_list"
.Vb 1
\&  $str = neat_list(\e@listref, $maxlen, $field_sep);
.Ve
.Sp
Calls \f(CW\*(C`neat\*(C'\fR on each element of the list and returns a string
containing the results joined with \f(CW$field_sep\fR. \f(CW$field_sep\fR defaults
to \f(CW", "\fR.
.ie n .IP """looks_like_number""" 4
.el .IP "\f(CWlooks_like_number\fR" 4
.IX Item "looks_like_number"
.Vb 1
\&  @bool = looks_like_number(@array);
.Ve
.Sp
Returns true for each element that looks like a number.
Returns false for each element that does not look like a number.
Returns \f(CW\*(C`undef\*(C'\fR for each element that is undefined or empty.
.ie n .IP """hash""" 4
.el .IP "\f(CWhash\fR" 4
.IX Item "hash"
.Vb 1
\&  $hash_value = DBI::hash($buffer, $type);
.Ve
.Sp
Return a 32\-bit integer 'hash' value corresponding to the contents of \f(CW$buffer\fR.
The \f(CW$type\fR parameter selects which kind of hash algorithm should be used.
.Sp
For the technically curious, type 0 (which is the default if \f(CW$type\fR
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 \*(L"Fowler / Noll / Vo\*(R" (\s-1FNV\s0) hash. See
<http://www.isthe.com/chongo/tech/comp/fnv/> for more information.
Both types are implemented in C and are very fast.
.Sp
This function doesn't have much to do with databases, except that
it can be handy to store hash values in a database.
.Sh "\s-1DBI\s0 Dynamic Attributes"
.IX Subsection "DBI Dynamic Attributes"
Dynamic attributes are always associated with the \fIlast handle used\fR
(that handle is represented by \f(CW$h\fR in the descriptions below).
.PP
Where an attribute is equivalent to a method call, then refer to
the method call for all related documentation.
.PP
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 \fIimmediately\fR after
calling the method that \*(L"sets\*(R" them.
If in any doubt, use the corresponding method call.
.ie n .IP "$DBI::err" 4
.el .IP "\f(CW$DBI::err\fR" 4
.IX Item "$DBI::err"
Equivalent to \f(CW\*(C`$h\->err\*(C'\fR.
.ie n .IP "$DBI::errstr" 4
.el .IP "\f(CW$DBI::errstr\fR" 4
.IX Item "$DBI::errstr"
Equivalent to \f(CW\*(C`$h\->errstr\*(C'\fR.
.ie n .IP "$DBI::state" 4
.el .IP "\f(CW$DBI::state\fR" 4
.IX Item "$DBI::state"
Equivalent to \f(CW\*(C`$h\->state\*(C'\fR.
.ie n .IP "$DBI::rows" 4
.el .IP "\f(CW$DBI::rows\fR" 4
.IX Item "$DBI::rows"
Equivalent to \f(CW\*(C`$h\->rows\*(C'\fR. Please refer to the documentation
for the \*(L"rows\*(R" method.
.ie n .IP "$DBI::lasth" 4
.el .IP "\f(CW$DBI::lasth\fR" 4
.IX Item "$DBI::lasth"
Returns the \s-1DBI\s0 object handle used for the most recent \s-1DBI\s0 method call.
If the last \s-1DBI\s0 method call was a \s-1DESTROY\s0 then \f(CW$DBI::lasth\fR will return
the handle of the parent of the destroyed handle, if there is one.
.SH "METHODS COMMON TO ALL HANDLES"
.IX Header "METHODS COMMON TO ALL HANDLES"
The following methods can be used by all types of \s-1DBI\s0 handles.
.ie n .IP """err""" 4
.el .IP "\f(CWerr\fR" 4
.IX Item "err"
.Vb 1
\&  $rv = $h->err;
.Ve
.Sp
Returns the \fInative\fR database engine error code from the last driver
method called. The code is typically an integer but you should not
assume that.
.Sp
The \s-1DBI\s0 resets \f(CW$h\fR\->err to undef before almost all \s-1DBI\s0 method calls, so the
value only has a short lifespan. Also, for most drivers, the statement
handles share the same error variable as the parent database handle,
so calling a method on one handle may reset the error on the
related handles.
.Sp
(Methods which don't reset err before being called include \fIerr()\fR and \fIerrstr()\fR,
obviously, \fIstate()\fR, \fIrows()\fR, \fIfunc()\fR, \fItrace()\fR, \fItrace_msg()\fR, \fIping()\fR, and the
tied hash attribute \s-1\fIFETCH\s0()\fR and \s-1\fISTORE\s0()\fR methods.)
.Sp
If you need to test for specific error conditions \fIand\fR 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.
.Sp
A driver may return \f(CW0\fR from \fIerr()\fR to indicate a warning condition
after a method call. Similarly, a driver may return an empty string
to indicate a 'success with information' condition. In both these
cases the value is false but not undef. The \fIerrstr()\fR and \fIstate()\fR
methods may be used to retrieve extra information in these cases.
.Sp
See \*(L"set_err\*(R" for more information.
.ie n .IP """errstr""" 4
.el .IP "\f(CWerrstr\fR" 4
.IX Item "errstr"
.Vb 1
\&  $str = $h->errstr;
.Ve
.Sp
Returns the native database engine error message from the last \s-1DBI\s0
method called. This has the same lifespan issues as the \*(L"err\*(R" method
described above.
.Sp
The returned string may contain multiple messages separated by
newline characters.
.Sp
The \fIerrstr()\fR method should not be used to test for errors, use \fIerr()\fR
for that, because drivers may return 'success with information' or
warning messages via \fIerrstr()\fR for methods that have not 'failed'.
.Sp
See \*(L"set_err\*(R" for more information.
.ie n .IP """state""" 4
.el .IP "\f(CWstate\fR" 4
.IX Item "state"
.Vb 1
\&  $str = $h->state;
.Ve
.Sp
Returns a state code in the standard \s-1SQLSTATE\s0 five character format.
Note that the specific success code \f(CW00000\fR is translated to any empty string
(false). If the driver does not support \s-1SQLSTATE\s0 (and most don't),
then state will return \f(CW\*(C`S1000\*(C'\fR (General Error) for all errors.
.Sp
The driver is free to return any value via \f(CW\*(C`state\*(C'\fR, e.g., warning
codes, even if it has not declared an error by returning a true value
via the \*(L"err\*(R" method described above.
.Sp
The \fIstate()\fR method should not be used to test for errors, use \fIerr()\fR
for that, because drivers may return a 'success with information' or
warning state code via \fIerrstr()\fR for methods that have not 'failed'.
.ie n .IP """set_err""" 4
.el .IP "\f(CWset_err\fR" 4
.IX Item "set_err"
.Vb 4
\&  $rv = $h->set_err($err, $errstr);
\&  $rv = $h->set_err($err, $errstr, $state);
\&  $rv = $h->set_err($err, $errstr, $state, $method);
\&  $rv = $h->set_err($err, $errstr, $state, $method, $rv);
.Ve
.Sp
Set the \f(CW\*(C`err\*(C'\fR, \f(CW\*(C`errstr\*(C'\fR, and \f(CW\*(C`state\*(C'\fR values for the handle.
This method is typically only used by \s-1DBI\s0 drivers and \s-1DBI\s0 subclasses.
.Sp
If the \*(L"HandleSetErr\*(R" attribute holds a reference to a subroutine
it is called first. The subroutine can alter the \f(CW$err\fR, \f(CW$errstr\fR, \f(CW$state\fR,
and \f(CW$method\fR values. See \*(L"HandleSetErr\*(R" for full details.
If the subroutine returns a true value then the handle \f(CW\*(C`err\*(C'\fR,
\&\f(CW\*(C`errstr\*(C'\fR, and \f(CW\*(C`state\*(C'\fR values are not altered and \fIset_err()\fR returns
an empty list (it normally returns \f(CW$rv\fR which defaults to undef, see below).
.Sp
Setting \f(CW\*(C`err\*(C'\fR to a \fItrue\fR value indicates an error and will trigger
the normal \s-1DBI\s0 error handling mechanisms, such as \f(CW\*(C`RaiseError\*(C'\fR and
\&\f(CW\*(C`HandleError\*(C'\fR, if they are enabled, when execution returns from
the \s-1DBI\s0 back to the application.
.Sp
Setting \f(CW\*(C`err\*(C'\fR to \f(CW""\fR indicates an 'information' state, and setting
it to \f(CW"0"\fR indicates a 'warning' state. Setting \f(CW\*(C`err\*(C'\fR to \f(CW\*(C`undef\*(C'\fR
also sets \f(CW\*(C`errstr\*(C'\fR to undef, and \f(CW\*(C`state\*(C'\fR to \f(CW""\fR, irrespective
of the values of the \f(CW$errstr\fR and \f(CW$state\fR parameters.
.Sp
The \f(CW$method\fR parameter provides an alternate method name for the
\&\f(CW\*(C`RaiseError\*(C'\fR/\f(CW\*(C`PrintError\*(C'\fR/\f(CW\*(C`PrintWarn\*(C'\fR error string instead of
the fairly unhelpful '\f(CW\*(C`set_err\*(C'\fR'.
.Sp
The \f(CW\*(C`set_err\*(C'\fR method normally returns undef.  The \f(CW$rv\fR parameter
provides an alternate return value.
.Sp
Some special rules apply if the \f(CW\*(C`err\*(C'\fR or \f(CW\*(C`errstr\*(C'\fR
values for the handle are \fIalready\fR set...
.Sp
If \f(CW\*(C`errstr\*(C'\fR is true then: "\f(CW\*(C` [err was %s now %s]\*(C'\fR" is appended if
\&\f(CW$err\fR is true and \f(CW\*(C`err\*(C'\fR is already true; "\f(CW\*(C` [state was %s now %s]\*(C'\fR"
is appended if \f(CW$state\fR is true and \f(CW\*(C`state\*(C'\fR is already true; then
"\f(CW\*(C`\en\*(C'\fR" and the new \f(CW$errstr\fR are appended. Obviously the \f(CW%s\fR's
above are replaced by the corresponding values.
.Sp
The handle \f(CW\*(C`err\*(C'\fR value is set to \f(CW$err\fR if: \f(CW$err\fR is true; or handle
\&\f(CW\*(C`err\*(C'\fR value is undef; or \f(CW$err\fR is defined and the length is greater
than the handle \f(CW\*(C`err\*(C'\fR length. The effect is that an 'information'
state only overrides undef; a 'warning' overrides undef or 'information',
and an 'error' state overrides anything.
.Sp
The handle \f(CW\*(C`state\*(C'\fR value is set to \f(CW$state\fR if \f(CW$state\fR is true and
the handle \f(CW\*(C`err\*(C'\fR value was set (by the rules above).
.Sp
Support for warning and information states was added in \s-1DBI\s0 1.41.
.ie n .IP """trace""" 4
.el .IP "\f(CWtrace\fR" 4
.IX Item "trace"
.Vb 3
\&  $h->trace($trace_settings);
\&  $h->trace($trace_settings, $trace_filename);
\&  $trace_settings = $h->trace;
.Ve
.Sp
The \fItrace()\fR method is used to alter the trace settings for a handle
(and any future children of that handle).  It can also be used to
change where the trace output is sent.
.Sp
There's a similar method, \f(CW\*(C`DBI\->trace\*(C'\fR, which sets the global
default trace settings.
.Sp
See the \*(L"\s-1TRACING\s0\*(R" section for full details about the \s-1DBI\s0's powerful
tracing facilities.
.ie n .IP """trace_msg""" 4
.el .IP "\f(CWtrace_msg\fR" 4
.IX Item "trace_msg"
.Vb 2
\&  $h->trace_msg($message_text);
\&  $h->trace_msg($message_text, $min_level);
.Ve
.Sp
Writes \f(CW$message_text\fR to the trace file if the trace level is
greater than or equal to \f(CW$min_level\fR (which defaults to 1).
Can also be called as \f(CW\*(C`DBI\->trace_msg($msg)\*(C'\fR.
.Sp
See \*(L"\s-1TRACING\s0\*(R" for more details.
.ie n .IP """func""" 4
.el .IP "\f(CWfunc\fR" 4
.IX Item "func"
.Vb 1
\&  $h->func(@func_arguments, $func_name) or die ...;
.Ve
.Sp
The \f(CW\*(C`func\*(C'\fR 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 \fIlast\fR argument.
.Sp
It's also important to note that the \fIfunc()\fR method does not clear
a previous error ($DBI::err etc.) and it does not trigger automatic
error detection (RaiseError etc.) so you must check the return
status and/or \f(CW$h\fR\->err to detect errors.
.Sp
(This method is not directly related to calling stored procedures.
Calling stored procedures is currently not defined by the \s-1DBI\s0.
Some drivers, such as DBD::Oracle, support it in non-portable ways.
See driver documentation for more details.)
.Sp
See also \*(L"install_method\*(R" for how you can avoid needing to
use \fIfunc()\fR and gain.
.ie n .IP """can""" 4
.el .IP "\f(CWcan\fR" 4
.IX Item "can"
.Vb 1
\&  $is_implemented = $h->can($method_name);
.Ve
.Sp
Returns true if \f(CW$method_name\fR is implemented by the driver or a
default method is provided by the \s-1DBI\s0.
It returns false where a driver hasn't implemented a method and the
default method is provided by the \s-1DBI\s0 is just an empty stub.
.ie n .IP """parse_trace_flags""" 4
.el .IP "\f(CWparse_trace_flags\fR" 4
.IX Item "parse_trace_flags"
.Vb 1
\&  $trace_settings_integer = $h->parse_trace_flags($trace_settings);
.Ve
.Sp
Parses a string containing trace settings and returns the corresponding
integer value used internally by the \s-1DBI\s0 and drivers.
.Sp
The \f(CW$trace_settings\fR argument is a string containing a trace level
between 0 and 15 and/or trace flag names separated by vertical bar
("\f(CW\*(C`|\*(C'\fR\*(L") or comma (\*(R"\f(CW\*(C`,\*(C'\fR") characters. For example: \f(CW"SQL|3|foo"\fR.
.Sp
It uses the \fIparse_trace_flag()\fR method, described below, to process
the individual trage flag names.
.Sp
The \fIparse_trace_flags()\fR method was added in \s-1DBI\s0 1.42.
.ie n .IP """parse_trace_flag""" 4
.el .IP "\f(CWparse_trace_flag\fR" 4
.IX Item "parse_trace_flag"
.Vb 1
\&  $bit_flag = $h->parse_trace_flag($trace_flag_name);
.Ve
.Sp
Returns the bit flag corresponding to the trace flag name in
\&\f(CW$trace_flag_name\fR.  Drivers are expected to override this method and
check if \f(CW$trace_flag_name\fR is a driver specific trace flags and, if
not, then call the DBIs default \fIparse_trace_flag()\fR.
.Sp
The \fIparse_trace_flag()\fR method was added in \s-1DBI\s0 1.42.
.ie n .IP """swap_inner_handle""" 4
.el .IP "\f(CWswap_inner_handle\fR" 4
.IX Item "swap_inner_handle"
.Vb 2
\&  $rc = $h1->swap_inner_handle( $h2 );
\&  $rc = $h1->swap_inner_handle( $h2, $allow_reparent );
.Ve
.Sp
Brain transplants for handles. You don't need to know about this
unless you want to become a handle surgeon.
.Sp
A \s-1DBI\s0 handle is a reference to a tied hash. A tied hash has an
\&\fIinner\fR hash that actually holds the contents.  The \fIswap_inner_handle()\fR
method swaps the inner hashes between two handles. The \f(CW$h1\fR and \f(CW$h2\fR
handles still point to the same tied hashes, but what those hashes
are tied to has been swapped.  In effect \f(CW$h1\fR \fIbecomes\fR \f(CW$h2\fR and
vice\-versa. This is powerful stuff, expect problems. Use with care.
.Sp
As a small safety measure, the two handles, \f(CW$h1\fR and \f(CW$h2\fR, have to
share the same parent unless \f(CW$allow_reparent\fR is true.
.Sp
The \fIswap_inner_handle()\fR method was added in \s-1DBI\s0 1.44.
.Sp
Here's a quick kind of 'diagram' as a worked example to help think about what's
happening:
.Sp
.Vb 4
\&    Original state:
\&            dbh1o -> dbh1i
\&            sthAo -> sthAi(dbh1i)
\&            dbh2o -> dbh2i
.Ve
.Sp
.Vb 4
\&    swap_inner_handle dbh1o with dbh2o:
\&            dbh2o -> dbh1i
\&            sthAo -> sthAi(dbh1i)
\&            dbh1o -> dbh2i
.Ve
.Sp
.Vb 5
\&    create new sth from dbh1o:
\&            dbh2o -> dbh1i
\&            sthAo -> sthAi(dbh1i)
\&            dbh1o -> dbh2i
\&            sthBo -> sthBi(dbh2i)
.Ve
.Sp
.Vb 5
\&    swap_inner_handle sthAo with sthBo:
\&            dbh2o -> dbh1i
\&            sthBo -> sthAi(dbh1i)
\&            dbh1o -> dbh2i
\&            sthAo -> sthBi(dbh2i)
.Ve
.SH "ATTRIBUTES COMMON TO ALL HANDLES"
.IX Header "ATTRIBUTES COMMON TO ALL HANDLES"
These attributes are common to all types of \s-1DBI\s0 handles.
.PP
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.
.PP
Attempting to set or get the value of an unknown attribute generates a warning,
except for private driver specific attributes (which all have names
starting with a lowercase letter).
.PP
Example:
.PP
.Vb 2
\&  $h->{AttributeName} = ...;    # set/write
\&  ... = $h->{AttributeName};    # get/read
.Ve
.ie n .IP """Warn"" (boolean, inherited)" 4
.el .IP "\f(CWWarn\fR (boolean, inherited)" 4
.IX Item "Warn (boolean, inherited)"
The \f(CW\*(C`Warn\*(C'\fR attribute enables useful warnings for certain bad
practices. It is enabled by default and should only be disabled in
rare circumstances.  Since warnings are generated using the Perl
\&\f(CW\*(C`warn\*(C'\fR function, they can be intercepted using the Perl \f(CW$SIG{_\|_WARN_\|_}\fR
hook.
.Sp
The \f(CW\*(C`Warn\*(C'\fR attribute is not related to the \f(CW\*(C`PrintWarn\*(C'\fR attribute.
.ie n .IP """Active"" (boolean, read\-only)" 4
.el .IP "\f(CWActive\fR (boolean, read\-only)" 4
.IX Item "Active (boolean, read-only)"
The \f(CW\*(C`Active\*(C'\fR attribute is true if the handle object is \*(L"active\*(R". 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 (\f(CW\*(C`$dbh\->disconnect\*(C'\fR sets \f(CW\*(C`Active\*(C'\fR off).  For
a statement handle it typically means that the handle is a \f(CW\*(C`SELECT\*(C'\fR
that may have more data to fetch. (Fetching all the data or calling \f(CW\*(C`$sth\->finish\*(C'\fR
sets \f(CW\*(C`Active\*(C'\fR off.)
.ie n .IP """Executed"" (boolean)" 4
.el .IP "\f(CWExecuted\fR (boolean)" 4
.IX Item "Executed (boolean)"
The \f(CW\*(C`Executed\*(C'\fR attribute is true if the handle object has been \*(L"executed\*(R".
Currently only the \f(CW$dbh\fR \fIdo()\fR method and the \f(CW$sth\fR \fIexecute()\fR, \fIexecute_array()\fR,
and \fIexecute_for_fetch()\fR methods set the \f(CW\*(C`Executed\*(C'\fR attribute.
.Sp
When it's set on a handle it is also set on the parent handle at the
same time. So calling \fIexecute()\fR on a \f(CW$sth\fR also sets the \f(CW\*(C`Executed\*(C'\fR
attribute on the parent \f(CW$dbh\fR.
.Sp
The \f(CW\*(C`Executed\*(C'\fR attribute for a database handle is cleared by the
\&\fIcommit()\fR and \fIrollback()\fR methods. The \f(CW\*(C`Executed\*(C'\fR attribute of a
statement handle is not cleared by the \s-1DBI\s0 under any circumstances
and so acts as a permanent record of whether the statement handle
was ever used.
.Sp
The \f(CW\*(C`Executed\*(C'\fR attribute was added in \s-1DBI\s0 1.41.
.ie n .IP """Kids"" (integer, read\-only)" 4
.el .IP "\f(CWKids\fR (integer, read\-only)" 4
.IX Item "Kids (integer, read-only)"
For a driver handle, \f(CW\*(C`Kids\*(C'\fR is the number of currently existing database
handles that were created from that driver handle.  For a database
handle, \f(CW\*(C`Kids\*(C'\fR is the number of currently existing statement handles that
were created from that database handle.
For a statement handle, the value is zero.
.ie n .IP """ActiveKids"" (integer, read\-only)" 4
.el .IP "\f(CWActiveKids\fR (integer, read\-only)" 4
.IX Item "ActiveKids (integer, read-only)"
Like \f(CW\*(C`Kids\*(C'\fR, but only counting those that are \f(CW\*(C`Active\*(C'\fR (as above).
.ie n .IP """CachedKids"" (hash ref)" 4
.el .IP "\f(CWCachedKids\fR (hash ref)" 4
.IX Item "CachedKids (hash ref)"
For a database handle, \f(CW\*(C`CachedKids\*(C'\fR returns a reference to the cache (hash) of
statement handles created by the \*(L"prepare_cached\*(R" method.  For a
driver handle, returns a reference to the cache (hash) of
database handles created by the \*(L"connect_cached\*(R" method.
.ie n .IP """Type"" (scalar)" 4
.el .IP "\f(CWType\fR (scalar)" 4
.IX Item "Type (scalar)"
The \f(CW\*(C`Type\*(C'\fR attribute identifies the type of a \s-1DBI\s0 handle.  Returns
\&\*(L"dr\*(R" for driver handles, \*(L"db\*(R" for database handles and \*(L"st\*(R" for
statement handles.
.ie n .IP """ChildHandles"" (array ref)" 4
.el .IP "\f(CWChildHandles\fR (array ref)" 4
.IX Item "ChildHandles (array ref)"
The ChildHandles attribute contains a reference to an array of all the
handles created by this handle which are still accessible.  The
contents of the array are weak-refs and will become undef when the
handle goes out of scope.
.Sp
\&\f(CW\*(C`ChildHandles\*(C'\fR returns undef if your perl version does not support weak
references (check the Scalar::Util module).  The referenced
array returned should be treated as read\-only.
.Sp
For example, to enumerate all driver handles, database handles and
statement handles:
.Sp
.Vb 7
\&    sub show_child_handles {
\&        my ($h, $level) = @_;
\&        $level ||= 0;
\&        printf "%sh %s %s\en", $h->{Type}, "\et" x $level, $h;
\&        show_child_handles($_, $level + 1) 
\&            for (grep { defined } @{$h->{ChildHandles}});
\&    }
.Ve
.Sp
.Vb 2
\&    my %drivers = DBI->installed_drivers();
\&    show_child_handles($_) for (values %drivers);
.Ve
.ie n .IP """CompatMode"" (boolean, inherited)" 4
.el .IP "\f(CWCompatMode\fR (boolean, inherited)" 4
.IX Item "CompatMode (boolean, inherited)"
The \f(CW\*(C`CompatMode\*(C'\fR attribute is used by emulation layers (such as
Oraperl) to enable compatible behaviour in the underlying driver
(e.g., DBD::Oracle) for this handle. Not normally set by application code.
.Sp
It also has the effect of disabling the 'quick \s-1FETCH\s0' of attribute
values from the handles attribute cache. So all attribute values
are handled by the drivers own \s-1FETCH\s0 method. This makes them slightly
slower but is useful for special-purpose drivers like DBD::Multiplex.
.ie n .IP """InactiveDestroy"" (boolean)" 4
.el .IP "\f(CWInactiveDestroy\fR (boolean)" 4
.IX Item "InactiveDestroy (boolean)"
The default value, false, means a handle will be fully destroyed
as normal when the last reference to it is removed, just as you'd expect.
.Sp
If set true then the handle will be treated by the \s-1DESTROY\s0 as if it was no
longer Active, and so the \fIdatabase engine\fR related effects of DESTROYing a
handle will be skipped.
.Sp
Think of the name as meaning 'treat the handle as not-Active in the \s-1DESTROY\s0
method'.
.Sp
For a database handle, this attribute does not disable an \fIexplicit\fR
call to the disconnect method, only the implicit call from \s-1DESTROY\s0
that happens if the handle is still marked as \f(CW\*(C`Active\*(C'\fR.
.Sp
This attribute is specifically designed for use in Unix applications
that \*(L"fork\*(R" child processes. Either the parent or the child process,
but not both, should set \f(CW\*(C`InactiveDestroy\*(C'\fR true on all their shared handles.
(Note that some databases, including Oracle, don't support passing a
database connection across a fork.)
.Sp
To help tracing applications using fork the process id is shown in
the trace log whenever a \s-1DBI\s0 or handle \fItrace()\fR method is called.
The process id also shown for \fIevery\fR method call if the \s-1DBI\s0 trace
level (not handle trace level) is set high enough to show the trace
from the \s-1DBI\s0's method dispatcher, e.g. >= 9.
.ie n .IP """PrintWarn"" (boolean, inherited)" 4
.el .IP "\f(CWPrintWarn\fR (boolean, inherited)" 4
.IX Item "PrintWarn (boolean, inherited)"
The \f(CW\*(C`PrintWarn\*(C'\fR attribute controls the printing of warnings recorded
by the driver.  When set to a true value the \s-1DBI\s0 will check method
calls to see if a warning condition has been set. If so, the \s-1DBI\s0
will effectively do a \f(CW\*(C`warn("$class $method warning: $DBI::errstr")\*(C'\fR
where \f(CW$class\fR is the driver class and \f(CW$method\fR is the name of
the method which failed. E.g.,
.Sp
.Vb 1
\&  DBD::Oracle::db execute warning: ... warning text here ...
.Ve
.Sp
By default, \f(CW\*(C`DBI\->connect\*(C'\fR sets \f(CW\*(C`PrintWarn\*(C'\fR \*(L"on\*(R" if $^W is true,
i.e., perl is running with warnings enabled.
.Sp
If desired, the warnings can be caught and processed using a \f(CW$SIG{_\|_WARN_\|_}\fR
handler or modules like CGI::Carp and CGI::ErrorWrap.
.Sp
See also \*(L"set_err\*(R" for how warnings are recorded and \*(L"HandleSetErr\*(R"
for how to influence it.
.Sp
Fetching the full details of warnings can require an extra round-trip
to the database server for some drivers. In which case the driver
may opt to only fetch the full details of warnings if the \f(CW\*(C`PrintWarn\*(C'\fR
attribute is true. If \f(CW\*(C`PrintWarn\*(C'\fR is false then these drivers should
still indicate the fact that there were warnings by setting the
warning string to, for example: \*(L"3 warnings\*(R".
.ie n .IP """PrintError"" (boolean, inherited)" 4
.el .IP "\f(CWPrintError\fR (boolean, inherited)" 4
.IX Item "PrintError (boolean, inherited)"
The \f(CW\*(C`PrintError\*(C'\fR attribute can be used to force errors to generate warnings (using
\&\f(CW\*(C`warn\*(C'\fR) in addition to returning error codes in the normal way.  When set
\&\*(L"on\*(R", any method which results in an error occuring will cause the \s-1DBI\s0 to
effectively do a \f(CW\*(C`warn("$class $method failed: $DBI::errstr")\*(C'\fR where \f(CW$class\fR
is the driver class and \f(CW$method\fR is the name of the method which failed. E.g.,
.Sp
.Vb 1
\&  DBD::Oracle::db prepare failed: ... error text here ...
.Ve
.Sp
By default, \f(CW\*(C`DBI\->connect\*(C'\fR sets \f(CW\*(C`PrintError\*(C'\fR \*(L"on\*(R".
.Sp
If desired, the warnings can be caught and processed using a \f(CW$SIG{_\|_WARN_\|_}\fR
handler or modules like CGI::Carp and CGI::ErrorWrap.
.ie n .IP """RaiseError"" (boolean, inherited)" 4
.el .IP "\f(CWRaiseError\fR (boolean, inherited)" 4
.IX Item "RaiseError (boolean, inherited)"
The \f(CW\*(C`RaiseError\*(C'\fR attribute can be used to force errors to raise exceptions rather
than simply return error codes in the normal way. It is \*(L"off\*(R" by default.
When set \*(L"on\*(R", any method which results in an error will cause
the \s-1DBI\s0 to effectively do a \f(CW\*(C`die("$class $method failed: $DBI::errstr")\*(C'\fR,
where \f(CW$class\fR is the driver class and \f(CW$method\fR is the name of the method
that failed. E.g.,
.Sp
.Vb 1
\&  DBD::Oracle::db prepare failed: ... error text here ...
.Ve
.Sp
If you turn \f(CW\*(C`RaiseError\*(C'\fR on then you'd normally turn \f(CW\*(C`PrintError\*(C'\fR off.
If \f(CW\*(C`PrintError\*(C'\fR is also on, then the \f(CW\*(C`PrintError\*(C'\fR is done first (naturally).
.Sp
Typically \f(CW\*(C`RaiseError\*(C'\fR is used in conjunction with \f(CW\*(C`eval { ... }\*(C'\fR
to catch the exception that's been thrown and followed by an
\&\f(CW\*(C`if ($@) { ... }\*(C'\fR block to handle the caught exception.
For example:
.Sp
.Vb 10
\&  eval {
\&    ...
\&    $sth->execute();
\&    ...
\&  };
\&  if ($@) {
\&    # $sth->err and $DBI::err will be true if error was from DBI
\&    warn $@; # print the error
\&    ... # do whatever you need to deal with the error
\&  }
.Ve
.Sp
In that eval block the \f(CW$DBI::lasth\fR variable can be useful for
diagnosis and reporting if you can't be sure which handle triggered
the error.  For example, \f(CW$DBI::lasth\fR\->{Type} and \f(CW$DBI::lasth\fR\->{Statement}.
.Sp
See also \*(L"Transactions\*(R".
.Sp
If you want to temporarily turn \f(CW\*(C`RaiseError\*(C'\fR off (inside a library function
that is likely to fail, for example), the recommended way is like this:
.Sp
.Vb 4
\&  {
\&    local $h->{RaiseError};  # localize and turn off for this block
\&    ...
\&  }
.Ve
.Sp
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 \f(CW\*(C`PrintError\*(C'\fR.
.ie n .IP """HandleError"" (code ref, inherited)" 4
.el .IP "\f(CWHandleError\fR (code ref, inherited)" 4
.IX Item "HandleError (code ref, inherited)"
The \f(CW\*(C`HandleError\*(C'\fR 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
\&\f(CW\*(C`RaiseError\*(C'\fR and \f(CW\*(C`PrintError\*(C'\fR are handled).
.Sp
The subroutine is called with three parameters: the error message
string that \f(CW\*(C`RaiseError\*(C'\fR and \f(CW\*(C`PrintError\*(C'\fR would use,
the \s-1DBI\s0 handle being used, and the first value being returned by
the method that failed (typically undef).
.Sp
If the subroutine returns a false value then the \f(CW\*(C`RaiseError\*(C'\fR
and/or \f(CW\*(C`PrintError\*(C'\fR attributes are checked and acted upon as normal.
.Sp
For example, to \f(CW\*(C`die\*(C'\fR with a full stack trace for any error:
.Sp
.Vb 2
\&  use Carp;
\&  $h->{HandleError} = sub { confess(shift) };
.Ve
.Sp
Or to turn errors into exceptions:
.Sp
.Vb 2
\&  use Exception; # or your own favourite exception module
\&  $h->{HandleError} = sub { Exception->new('DBI')->raise($_[0]) };
.Ve
.Sp
It is possible to 'stack' multiple HandleError handlers by using
closures:
.Sp
.Vb 7
\&  sub your_subroutine {
\&    my $previous_handler = $h->{HandleError};
\&    $h->{HandleError} = sub {
\&      return 1 if $previous_handler and &$previous_handler(@_);
\&      ... your code here ...
\&    };
\&  }
.Ve
.Sp
Using a \f(CW\*(C`my\*(C'\fR inside a subroutine to store the previous \f(CW\*(C`HandleError\*(C'\fR
value is important.  See perlsub and perlref for more information
about \fIclosures\fR.
.Sp
It is possible for \f(CW\*(C`HandleError\*(C'\fR to alter the error message that
will be used by \f(CW\*(C`RaiseError\*(C'\fR and \f(CW\*(C`PrintError\*(C'\fR if it returns false.
It can do that by altering the value of \f(CW$_\fR[0]. This example appends
a stack trace to all errors and, unlike the previous example using
Carp::confess, this will work \f(CW\*(C`PrintError\*(C'\fR as well as \f(CW\*(C`RaiseError\*(C'\fR:
.Sp
.Vb 1
\&  $h->{HandleError} = sub { $_[0]=Carp::longmess($_[0]); 0; };
.Ve
.Sp
It is also possible for \f(CW\*(C`HandleError\*(C'\fR to hide an error, to a limited
degree, by using \*(L"set_err\*(R" to reset \f(CW$DBI::err\fR and \f(CW$DBI::errstr\fR,
and altering the return value of the failed method. For example:
.Sp
.Vb 7
\&  $h->{HandleError} = sub {
\&    return 0 unless $_[0] =~ /^\eS+ fetchrow_arrayref failed:/;
\&    return 0 unless $_[1]->err == 1234; # the error to 'hide'
\&    $h->set_err(undef,undef);   # turn off the error
\&    $_[2] = [ ... ];    # supply alternative return value
\&    return 1;
\&  };
.Ve
.Sp
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 \fIgood\fR use for it then
please let me know.
.ie n .IP """HandleSetErr"" (code ref, inherited)" 4
.el .IP "\f(CWHandleSetErr\fR (code ref, inherited)" 4
.IX Item "HandleSetErr (code ref, inherited)"
The \f(CW\*(C`HandleSetErr\*(C'\fR attribute can be used to intercept
the setting of handle \f(CW\*(C`err\*(C'\fR, \f(CW\*(C`errstr\*(C'\fR, and \f(CW\*(C`state\*(C'\fR values.
If set to a reference to a subroutine then that subroutine is called
whenever \fIset_err()\fR is called, typically by the driver or a subclass.
.Sp
The subroutine is called with five arguments, the first five that
were passed to \fIset_err()\fR: the handle, the \f(CW\*(C`err\*(C'\fR, \f(CW\*(C`errstr\*(C'\fR, and
\&\f(CW\*(C`state\*(C'\fR values being set, and the method name. These can be altered
by changing the values in the \f(CW@_\fR array. The return value affects
\&\fIset_err()\fR behaviour, see \*(L"set_err\*(R" for details.
.Sp
It is possible to 'stack' multiple HandleSetErr handlers by using
closures. See \*(L"HandleError\*(R" for an example.
.Sp
The \f(CW\*(C`HandleSetErr\*(C'\fR and \f(CW\*(C`HandleError\*(C'\fR subroutines differ in subtle
but significant ways. HandleError is only invoked at the point where
the \s-1DBI\s0 is about to return to the application with \f(CW\*(C`err\*(C'\fR set true.
It's not invoked by the failure of a method that's been called by
another \s-1DBI\s0 method.  HandleSetErr, on the other hand, is called
whenever \fIset_err()\fR is called with a defined \f(CW\*(C`err\*(C'\fR value, even if false.
So it's not just for errors, despite the name, but also warn and info states.
The \fIset_err()\fR method, and thus HandleSetErr, may be called multiple
times within a method and is usually invoked from deep within driver code.
.Sp
In theory a driver can use the return value from HandleSetErr via
\&\fIset_err()\fR to decide whether to continue or not. If \fIset_err()\fR returns
an empty list, indicating that the HandleSetErr code has 'handled'
the 'error', the driver could then continue instead of failing (if
that's a reasonable thing to do).  This isn't excepted to be
common and any such cases should be clearly marked in the driver
documentation and discussed on the dbi-dev mailing list.
.Sp
The \f(CW\*(C`HandleSetErr\*(C'\fR attribute was added in \s-1DBI\s0 1.41.
.ie n .IP """ErrCount"" (unsigned integer)" 4
.el .IP "\f(CWErrCount\fR (unsigned integer)" 4
.IX Item "ErrCount (unsigned integer)"
The \f(CW\*(C`ErrCount\*(C'\fR attribute is incremented whenever the \fIset_err()\fR
method records an error. It isn't incremented by warnings or
information states. It is not reset by the \s-1DBI\s0 at any time.
.Sp
The \f(CW\*(C`ErrCount\*(C'\fR attribute was added in \s-1DBI\s0 1.41. Older drivers may
not have been updated to use \fIset_err()\fR to record errors and so this
attribute may not be incremented when using them.
.ie n .IP """ShowErrorStatement"" (boolean, inherited)" 4
.el .IP "\f(CWShowErrorStatement\fR (boolean, inherited)" 4
.IX Item "ShowErrorStatement (boolean, inherited)"
The \f(CW\*(C`ShowErrorStatement\*(C'\fR attribute can be used to cause the relevant
Statement text to be appended to the error messages generated by
the \f(CW\*(C`RaiseError\*(C'\fR, \f(CW\*(C`PrintError\*(C'\fR, and \f(CW\*(C`PrintWarn\*(C'\fR attributes.
Only applies to errors on statement handles
plus the \fIprepare()\fR, \fIdo()\fR, and the various \f(CW\*(C`select*()\*(C'\fR database handle methods.
(The exact format of the appended text is subject to change.)
.Sp
If \f(CW\*(C`$h\->{ParamValues}\*(C'\fR returns a hash reference of parameter
(placeholder) values then those are formatted and appended to the
end of the Statement text in the error message.
.ie n .IP """TraceLevel"" (integer, inherited)" 4
.el .IP "\f(CWTraceLevel\fR (integer, inherited)" 4
.IX Item "TraceLevel (integer, inherited)"
The \f(CW\*(C`TraceLevel\*(C'\fR attribute can be used as an alternative to the
\&\*(L"trace\*(R" method to set the \s-1DBI\s0 trace level and trace flags for a
specific handle.  See \*(L"\s-1TRACING\s0\*(R" for more details.
.Sp
The \f(CW\*(C`TraceLevel\*(C'\fR attribute is especially useful combined with
\&\f(CW\*(C`local\*(C'\fR to alter the trace settings for just a single block of code.
.ie n .IP """FetchHashKeyName"" (string, inherited)" 4
.el .IP "\f(CWFetchHashKeyName\fR (string, inherited)" 4
.IX Item "FetchHashKeyName (string, inherited)"
The \f(CW\*(C`FetchHashKeyName\*(C'\fR attribute is used to specify whether the \fIfetchrow_hashref()\fR
method should perform case conversion on the field names used for
the hash keys. For historical reasons it defaults to '\f(CW\*(C`NAME\*(C'\fR' but
it is recommended to set it to '\f(CW\*(C`NAME_lc\*(C'\fR' (convert to lower case)
or '\f(CW\*(C`NAME_uc\*(C'\fR' (convert to upper case) according to your preference.
It can only be set for driver and database handles.  For statement
handles the value is frozen when \fIprepare()\fR is called.
.ie n .IP """ChopBlanks"" (boolean, inherited)" 4
.el .IP "\f(CWChopBlanks\fR (boolean, inherited)" 4
.IX Item "ChopBlanks (boolean, inherited)"
The \f(CW\*(C`ChopBlanks\*(C'\fR attribute can be used to control the trimming of trailing space
characters from fixed width character (\s-1CHAR\s0) fields. No other field
types are affected, even where field values have trailing spaces.
.Sp
The default is false (although it is possible that the default may change).
Applications that need specific behaviour should set the attribute as
needed.
.Sp
Drivers are not required to support this attribute, but any driver which
does not support it must arrange to return \f(CW\*(C`undef\*(C'\fR as the attribute value.
.ie n .IP """LongReadLen"" (unsigned integer, inherited)" 4
.el .IP "\f(CWLongReadLen\fR (unsigned integer, inherited)" 4
.IX Item "LongReadLen (unsigned integer, inherited)"
The \f(CW\*(C`LongReadLen\*(C'\fR attribute may be used to control the maximum
length of 'long' type fields (\s-1LONG\s0, \s-1BLOB\s0, \s-1CLOB\s0, \s-1MEMO\s0, etc.) which the driver will
read from the database automatically when it fetches each row of data.
.Sp
The \f(CW\*(C`LongReadLen\*(C'\fR attribute only relates to fetching and reading
long values; it is not involved in inserting or updating them.
.Sp
A value of 0 means not to automatically fetch any long data.
Drivers may return undef or an empty string for long fields when
\&\f(CW\*(C`LongReadLen\*(C'\fR is 0.
.Sp
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.
.Sp
Some databases return some long types encoded as pairs of hex digits.
For these types, \f(CW\*(C`LongReadLen\*(C'\fR relates to the underlying data
length and not the doubled-up length of the encoded string.
.Sp
Changing the value of \f(CW\*(C`LongReadLen\*(C'\fR for a statement handle after it
has been \f(CW\*(C`prepare\*(C'\fR'd will typically have no effect, so it's common to
set \f(CW\*(C`LongReadLen\*(C'\fR on the \f(CW$dbh\fR before calling \f(CW\*(C`prepare\*(C'\fR.
.Sp
For most drivers the value used here has a direct effect on the
memory used by the statement handle while it's active, so don't be
too generous. If you can't be sure what value to use you could
execute an extra select statement to determine the longest value.
For example:
.Sp
.Vb 7
\&  $dbh->{LongReadLen} = $dbh->selectrow_array(qq{
\&      SELECT MAX(OCTET_LENGTH(long_column_name))
\&      FROM table WHERE ...
\&  });
\&  $sth = $dbh->prepare(qq{
\&      SELECT long_column_name, ... FROM table WHERE ...
\&  });
.Ve
.Sp
You may need to take extra care if the table can be modified between
the first select and the second being executed. You may also need to
use a different function if \s-1\fIOCTET_LENGTH\s0()\fR does not work for long
types in your database. For example, for Sybase use \s-1\fIDATALENGTH\s0()\fR and
for Oracle use \s-1\fILENGTHB\s0()\fR.
.Sp
See also \*(L"LongTruncOk\*(R" for information on truncation of long types.
.ie n .IP """LongTruncOk"" (boolean, inherited)" 4
.el .IP "\f(CWLongTruncOk\fR (boolean, inherited)" 4
.IX Item "LongTruncOk (boolean, inherited)"
The \f(CW\*(C`LongTruncOk\*(C'\fR 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 \f(CW\*(C`LongReadLen\*(C'\fR attribute).
.Sp
By default, \f(CW\*(C`LongTruncOk\*(C'\fR 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.)
.Sp
If a fetch fails due to a long field truncation when \f(CW\*(C`LongTruncOk\*(C'\fR is
false, many drivers will allow you to continue fetching further rows.
.Sp
See also \*(L"LongReadLen\*(R".
.ie n .IP """TaintIn"" (boolean, inherited)" 4
.el .IP "\f(CWTaintIn\fR (boolean, inherited)" 4
.IX Item "TaintIn (boolean, inherited)"
If the \f(CW\*(C`TaintIn\*(C'\fR attribute is set to a true value \fIand\fR Perl is running in
taint mode (e.g., started with the \f(CW\*(C`\-T\*(C'\fR option), then all the arguments
to most \s-1DBI\s0 method calls are checked for being tainted. \fIThis may change.\fR
.Sp
The attribute defaults to off, even if Perl is in taint mode.
See perlsec for more about taint mode.  If Perl is not
running in taint mode, this attribute has no effect.
.Sp
When fetching data that you trust you can turn off the TaintIn attribute,
for that statement handle, for the duration of the fetch loop.
.Sp
The \f(CW\*(C`TaintIn\*(C'\fR attribute was added in \s-1DBI\s0 1.31.
.ie n .IP """TaintOut"" (boolean, inherited)" 4
.el .IP "\f(CWTaintOut\fR (boolean, inherited)" 4
.IX Item "TaintOut (boolean, inherited)"
If the \f(CW\*(C`TaintOut\*(C'\fR attribute is set to a true value \fIand\fR Perl is running in
taint mode (e.g., started with the \f(CW\*(C`\-T\*(C'\fR option), then most data fetched
from the database is considered tainted. \fIThis may change.\fR
.Sp
The attribute defaults to off, even if Perl is in taint mode.
See perlsec for more about taint mode.  If Perl is not
running in taint mode, this attribute has no effect.
.Sp
When fetching data that you trust you can turn off the TaintOut attribute,
for that statement handle, for the duration of the fetch loop.
.Sp
Currently only fetched data is tainted. It is possible that the results
of other \s-1DBI\s0 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 \s-1DBI\s0 Taint mode,
please report your experience and any suggestions for changes.
.Sp
The \f(CW\*(C`TaintOut\*(C'\fR attribute was added in \s-1DBI\s0 1.31.
.ie n .IP """Taint"" (boolean, inherited)" 4
.el .IP "\f(CWTaint\fR (boolean, inherited)" 4
.IX Item "Taint (boolean, inherited)"
The \f(CW\*(C`Taint\*(C'\fR attribute is a shortcut for \*(L"TaintIn\*(R" and \*(L"TaintOut\*(R" (it is also present
for backwards compatibility).
.Sp
Setting this attribute sets both \*(L"TaintIn\*(R" and \*(L"TaintOut\*(R", and retrieving
it returns a true value if and only if \*(L"TaintIn\*(R" and \*(L"TaintOut\*(R" are
both set to true values.
.ie n .IP """Profile"" (inherited)" 4
.el .IP "\f(CWProfile\fR (inherited)" 4
.IX Item "Profile (inherited)"
The \f(CW\*(C`Profile\*(C'\fR attribute enables the collection and reporting of method call timing statistics.
See the DBI::Profile module documentation for \fImuch\fR more detail.
.Sp
The \f(CW\*(C`Profile\*(C'\fR attribute was added in \s-1DBI\s0 1.24.
.ie n .IP """private_your_module_name_*""" 4
.el .IP "\f(CWprivate_your_module_name_*\fR" 4
.IX Item "private_your_module_name_*"
The \s-1DBI\s0 provides a way to store extra information in a \s-1DBI\s0 handle as
\&\*(L"private\*(R" attributes. The \s-1DBI\s0 will allow you to store and retrieve any
attribute which has a name starting with "\f(CW\*(C`private_\*(C'\fR".
.Sp
It is \fIstrongly\fR recommended that you use just \fIone\fR private
attribute (e.g., use a hash ref) \fIand\fR give it a long and unambiguous
name that includes the module or application name that the attribute
relates to (e.g., "\f(CW\*(C`private_YourFullModuleName_thingy\*(C'\fR").
.Sp
Because of the way the Perl tie mechanism works you cannot reliably
use the \f(CW\*(C`||=\*(C'\fR operator directly to initialise the attribute, like this:
.Sp
.Vb 1
\&  my $foo = $dbh->{private_yourmodname_foo} ||= { ... }; # WRONG
.Ve
.Sp
you should use a two step approach like this:
.Sp
.Vb 2
\&  my $foo = $dbh->{private_yourmodname_foo};
\&  $foo ||= $dbh->{private_yourmodname_foo} = { ... };
.Ve
.Sp
This attribute is primarily of interest to people sub-classing \s-1DBI\s0.
.SH "DBI DATABASE HANDLE OBJECTS"
.IX Header "DBI DATABASE HANDLE OBJECTS"
This section covers the methods and attributes associated with
database handles.
.Sh "Database Handle Methods"
.IX Subsection "Database Handle Methods"
The following methods are specified for \s-1DBI\s0 database handles:
.ie n .IP """clone""" 4
.el .IP "\f(CWclone\fR" 4
.IX Item "clone"
.Vb 2
\&  $new_dbh = $dbh->clone();
\&  $new_dbh = $dbh->clone(\e%attr);
.Ve
.Sp
The \f(CW\*(C`clone\*(C'\fR method duplicates the \f(CW$dbh\fR connection by connecting
with the same parameters ($dsn, \f(CW$user\fR, \f(CW$password\fR) as originally used.
.Sp
The attributes for the cloned connect are the same as those used
for the original connect, with some other attribute merged over
them depending on the \e%attr parameter.
.Sp
If \e%attr is given then the attributes it contains are merged into
the original attributes and override any with the same names.
Effectively the same as doing:
.Sp
.Vb 1
\&  %attribues_used = ( %original_attributes, %attr );
.Ve
.Sp
If \e%attr is not given then it defaults to a hash containing all
the attributes in the attribute cache of \f(CW$dbh\fR excluding any non-code
references, plus the main boolean attributes (RaiseError, PrintError,
AutoCommit, etc.). This behaviour is subject to change.
.Sp
The clone method can be used even if the database handle is disconnected.
.Sp
The \f(CW\*(C`clone\*(C'\fR method was added in \s-1DBI\s0 1.33. It is very new and likely
to change.
.ie n .IP """data_sources""" 4
.el .IP "\f(CWdata_sources\fR" 4
.IX Item "data_sources"
.Vb 2
\&  @ary = $dbh->data_sources();
\&  @ary = $dbh->data_sources(\e%attr);
.Ve
.Sp
Returns a list of data sources (databases) available via the \f(CW$dbh\fR
driver's \fIdata_sources()\fR method, plus any extra data sources that
the driver can discover via the connected \f(CW$dbh\fR. Typically the extra
data sources are other databases managed by the same server process
that the \f(CW$dbh\fR is connected to.
.Sp
Data sources are returned in a form suitable for passing to the
\&\*(L"connect\*(R" method (that is, they will include the "\f(CW\*(C`dbi:$driver:\*(C'\fR" prefix).
.Sp
The \fIdata_sources()\fR method, for a \f(CW$dbh\fR, was added in \s-1DBI\s0 1.38.
.ie n .IP """do""" 4
.el .IP "\f(CWdo\fR" 4
.IX Item "do"
.Vb 3
\&  $rows = $dbh->do($statement)           or die $dbh->errstr;
\&  $rows = $dbh->do($statement, \e%attr)   or die $dbh->errstr;
\&  $rows = $dbh->do($statement, \e%attr, @bind_values) or die ...
.Ve
.Sp
Prepare and execute a single statement. Returns the number of rows
affected or \f(CW\*(C`undef\*(C'\fR on error. A return value of \f(CW\*(C`\-1\*(C'\fR means the
number of rows is not known, not applicable, or not available.
.Sp
This method is typically most useful for \fInon\fR\-\f(CW\*(C`SELECT\*(C'\fR 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 \f(CW\*(C`SELECT\*(C'\fR statements because it does not return a statement
handle (so you can't fetch any data).
.Sp
The default \f(CW\*(C`do\*(C'\fR method is logically similar to:
.Sp
.Vb 7
\&  sub do {
\&      my($dbh, $statement, $attr, @bind_values) = @_;
\&      my $sth = $dbh->prepare($statement, $attr) or return undef;
\&      $sth->execute(@bind_values) or return undef;
\&      my $rows = $sth->rows;
\&      ($rows == 0) ? "0E0" : $rows; # always return true if no error
\&  }
.Ve
.Sp
For example:
.Sp
.Vb 4
\&  my $rows_deleted = $dbh->do(q{
\&      DELETE FROM table
\&      WHERE status = ?
\&  }, undef, 'DONE') or die $dbh->errstr;
.Ve
.Sp
Using placeholders and \f(CW@bind_values\fR with the \f(CW\*(C`do\*(C'\fR method can be
useful because it avoids the need to correctly quote any variables
in the \f(CW$statement\fR. But if you'll be executing the statement many
times then it's more efficient to \f(CW\*(C`prepare\*(C'\fR it once and call
\&\f(CW\*(C`execute\*(C'\fR many times instead.
.Sp
The \f(CW\*(C`q{...}\*(C'\fR style quoting used in this example avoids clashing with
quotes that may be used in the \s-1SQL\s0 statement. Use the double-quote-like
\&\f(CW\*(C`qq{...}\*(C'\fR operator if you want to interpolate variables into the string.
See \*(L"Quote and Quote-like Operators\*(R" in perlop for more details.
.ie n .IP """last_insert_id""" 4
.el .IP "\f(CWlast_insert_id\fR" 4
.IX Item "last_insert_id"
.Vb 2
\&  $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
\&  $rv = $dbh->last_insert_id($catalog, $schema, $table, $field, \e%attr);
.Ve
.Sp
Returns a value 'identifying' the row just inserted, if possible.
Typically this would be a value assigned by the database server
to a column with an \fIauto_increment\fR or \fIserial\fR type.
Returns undef if the driver does not support the method or can't
determine the value.
.Sp
The \f(CW$catalog\fR, \f(CW$schema\fR, \f(CW$table\fR, and \f(CW$field\fR parameters may be required
for some drivers (see below).  If you don't know the parameter values
and your driver does not need them, then use \f(CW\*(C`undef\*(C'\fR for each.
.Sp
There are several caveats to be aware of with this method if you want
to use it for portable applications:
.Sp
\&\fB*\fR For some drivers the value may only available immediately after
the insert statement has executed (e.g., mysql, Informix).
.Sp
\&\fB*\fR For some drivers the \f(CW$catalog\fR, \f(CW$schema\fR, \f(CW$table\fR, and \f(CW$field\fR parameters
are required, for others they are ignored (e.g., mysql).
.Sp
\&\fB*\fR Drivers may return an indeterminate value if no insert has
been performed yet.
.Sp
\&\fB*\fR For some drivers the value may only be available if placeholders
have \fInot\fR been used (e.g., Sybase, \s-1MS\s0 \s-1SQL\s0). In this case the value
returned would be from the last non-placeholder insert statement.
.Sp
\&\fB*\fR Some drivers may need driver-specific hints about how to get
the value. For example, being told the name of the database 'sequence'
object that holds the value. Any such hints are passed as driver-specific
attributes in the \e%attr parameter.
.Sp
\&\fB*\fR If the underlying database offers nothing better, then some
drivers may attempt to implement this method by executing
"\f(CW\*(C`select max($field) from $table\*(C'\fR". Drivers using any approach
like this should issue a warning if \f(CW\*(C`AutoCommit\*(C'\fR is true because
it is generally unsafe \- another process may have modified the table
between your insert and the select. For situations where you know
it is safe, such as when you have locked the table, you can silence
the warning by passing \f(CW\*(C`Warn\*(C'\fR => 0 in \e%attr.
.Sp
\&\fB*\fR If no insert has been performed yet, or the last insert failed,
then the value is implementation defined.
.Sp
Given all the caveats above, it's clear that this method must be
used with care.
.Sp
The \f(CW\*(C`last_insert_id\*(C'\fR method was added in \s-1DBI\s0 1.38.
.ie n .IP """selectrow_array""" 4
.el .IP "\f(CWselectrow_array\fR" 4
.IX Item "selectrow_array"
.Vb 3
\&  @row_ary = $dbh->selectrow_array($statement);
\&  @row_ary = $dbh->selectrow_array($statement, \e%attr);
\&  @row_ary = $dbh->selectrow_array($statement, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R" and
\&\*(L"fetchrow_array\*(R" into a single call. If called in a list context, it
returns the first row of data from the statement.  The \f(CW$statement\fR
parameter can be a previously prepared statement handle, in which case
the \f(CW\*(C`prepare\*(C'\fR is skipped.
.Sp
If any method fails, and \*(L"RaiseError\*(R" is not set, \f(CW\*(C`selectrow_array\*(C'\fR
will return an empty list.
.Sp
If called in a scalar context for a statement handle that has more
than one column, it is undefined whether the driver will return
the value of the first column or the last. So don't do that.
Also, in a scalar context, an \f(CW\*(C`undef\*(C'\fR is returned if there are no
more rows or if an error occurred. That \f(CW\*(C`undef\*(C'\fR can't be distinguished
from an \f(CW\*(C`undef\*(C'\fR returned because the first field value was \s-1NULL\s0.
For these reasons you should exercise some caution if you use
\&\f(CW\*(C`selectrow_array\*(C'\fR in a scalar context, or just don't do that.
.ie n .IP """selectrow_arrayref""" 4
.el .IP "\f(CWselectrow_arrayref\fR" 4
.IX Item "selectrow_arrayref"
.Vb 3
\&  $ary_ref = $dbh->selectrow_arrayref($statement);
\&  $ary_ref = $dbh->selectrow_arrayref($statement, \e%attr);
\&  $ary_ref = $dbh->selectrow_arrayref($statement, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R" and
\&\*(L"fetchrow_arrayref\*(R" into a single call. It returns the first row of
data from the statement.  The \f(CW$statement\fR parameter can be a previously
prepared statement handle, in which case the \f(CW\*(C`prepare\*(C'\fR is skipped.
.Sp
If any method fails, and \*(L"RaiseError\*(R" is not set, \f(CW\*(C`selectrow_array\*(C'\fR
will return undef.
.ie n .IP """selectrow_hashref""" 4
.el .IP "\f(CWselectrow_hashref\fR" 4
.IX Item "selectrow_hashref"
.Vb 3
\&  $hash_ref = $dbh->selectrow_hashref($statement);
\&  $hash_ref = $dbh->selectrow_hashref($statement, \e%attr);
\&  $hash_ref = $dbh->selectrow_hashref($statement, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R" and
\&\*(L"fetchrow_hashref\*(R" into a single call. It returns the first row of
data from the statement.  The \f(CW$statement\fR parameter can be a previously
prepared statement handle, in which case the \f(CW\*(C`prepare\*(C'\fR is skipped.
.Sp
If any method fails, and \*(L"RaiseError\*(R" is not set, \f(CW\*(C`selectrow_hashref\*(C'\fR
will return undef.
.ie n .IP """selectall_arrayref""" 4
.el .IP "\f(CWselectall_arrayref\fR" 4
.IX Item "selectall_arrayref"
.Vb 3
\&  $ary_ref = $dbh->selectall_arrayref($statement);
\&  $ary_ref = $dbh->selectall_arrayref($statement, \e%attr);
\&  $ary_ref = $dbh->selectall_arrayref($statement, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R" and
\&\*(L"fetchall_arrayref\*(R" into a single call. It returns a reference to an
array containing a reference to an array (or hash, see below) for each row of
data fetched.
.Sp
The \f(CW$statement\fR parameter can be a previously prepared statement handle,
in which case the \f(CW\*(C`prepare\*(C'\fR is skipped. This is recommended if the
statement is going to be executed many times.
.Sp
If \*(L"RaiseError\*(R" is not set and any method except \f(CW\*(C`fetchall_arrayref\*(C'\fR
fails then \f(CW\*(C`selectall_arrayref\*(C'\fR will return \f(CW\*(C`undef\*(C'\fR; if
\&\f(CW\*(C`fetchall_arrayref\*(C'\fR fails then it will return with whatever data
has been fetched thus far. You should check \f(CW\*(C`$sth\->err\*(C'\fR
afterwards (or use the \f(CW\*(C`RaiseError\*(C'\fR attribute) to discover if the data is
complete or was truncated due to an error.
.Sp
The \*(L"fetchall_arrayref\*(R" method called by \f(CW\*(C`selectall_arrayref\*(C'\fR
supports a \f(CW$max_rows\fR parameter. You can specify a value for \f(CW$max_rows\fR
by including a '\f(CW\*(C`MaxRows\*(C'\fR' attribute in \e%attr. In which case \fIfinish()\fR
is called for you after \fIfetchall_arrayref()\fR returns.
.Sp
The \*(L"fetchall_arrayref\*(R" method called by \f(CW\*(C`selectall_arrayref\*(C'\fR
also supports a \f(CW$slice\fR parameter. You can specify a value for \f(CW$slice\fR by
including a '\f(CW\*(C`Slice\*(C'\fR' or '\f(CW\*(C`Columns\*(C'\fR' attribute in \e%attr. The only
difference between the two is that if \f(CW\*(C`Slice\*(C'\fR is not defined and
\&\f(CW\*(C`Columns\*(C'\fR 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 \f(CW\*(C`/fetchall_arrayref\*(C'\fR.
.Sp
You may often want to fetch an array of rows where each row is stored as a
hash. That can be done simple using:
.Sp
.Vb 7
\&  my $emps = $dbh->selectall_arrayref(
\&      "SELECT ename FROM emp ORDER BY ename",
\&      { Slice => {} }
\&  );
\&  foreach my $emp ( @$emps ) {
\&      print "Employee: $emp->{ename}\en";
\&  }
.Ve
.Sp
Or, to fetch into an array instead of an array ref:
.Sp
.Vb 1
\&  @result = @{ $dbh->selectall_arrayref($sql, { Slice => {} }) };
.Ve
.Sp
See \*(L"fetchall_arrayref\*(R" method for more details.
.ie n .IP """selectall_hashref""" 4
.el .IP "\f(CWselectall_hashref\fR" 4
.IX Item "selectall_hashref"
.Vb 3
\&  $hash_ref = $dbh->selectall_hashref($statement, $key_field);
\&  $hash_ref = $dbh->selectall_hashref($statement, $key_field, \e%attr);
\&  $hash_ref = $dbh->selectall_hashref($statement, $key_field, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R" and
\&\*(L"fetchall_hashref\*(R" into a single call. It returns a reference to a
hash containing one entry, at most, for each row, as returned by \fIfetchall_hashref()\fR.
.Sp
The \f(CW$statement\fR parameter can be a previously prepared statement handle,
in which case the \f(CW\*(C`prepare\*(C'\fR is skipped.  This is recommended if the
statement is going to be executed many times.
.Sp
The \f(CW$key_field\fR parameter defines which column, or columns, are used as keys
in the returned hash. It can either be the name of a single field, or a
reference to an array containing multiple field names. Using multiple names
yields a tree of nested hashes.
.Sp
If a row has the same key as an earlier row then it replaces the earlier row.
.Sp
If any method except \f(CW\*(C`fetchrow_hashref\*(C'\fR fails, and \*(L"RaiseError\*(R" is not set,
\&\f(CW\*(C`selectall_hashref\*(C'\fR will return \f(CW\*(C`undef\*(C'\fR.  If \f(CW\*(C`fetchrow_hashref\*(C'\fR fails and
\&\*(L"RaiseError\*(R" is not set, then it will return with whatever data it
has fetched thus far. \f(CW$DBI::err\fR should be checked to catch that.
.Sp
See \fIfetchall_hashref()\fR for more details.
.ie n .IP """selectcol_arrayref""" 4
.el .IP "\f(CWselectcol_arrayref\fR" 4
.IX Item "selectcol_arrayref"
.Vb 3
\&  $ary_ref = $dbh->selectcol_arrayref($statement);
\&  $ary_ref = $dbh->selectcol_arrayref($statement, \e%attr);
\&  $ary_ref = $dbh->selectcol_arrayref($statement, \e%attr, @bind_values);
.Ve
.Sp
This utility method combines \*(L"prepare\*(R", \*(L"execute\*(R", 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.
.Sp
The \f(CW$statement\fR parameter can be a previously prepared statement handle,
in which case the \f(CW\*(C`prepare\*(C'\fR is skipped. This is recommended if the
statement is going to be executed many times.
.Sp
If any method except \f(CW\*(C`fetch\*(C'\fR fails, and \*(L"RaiseError\*(R" is not set,
\&\f(CW\*(C`selectcol_arrayref\*(C'\fR will return \f(CW\*(C`undef\*(C'\fR.  If \f(CW\*(C`fetch\*(C'\fR fails and
\&\*(L"RaiseError\*(R" is not set, then it will return with whatever data it
has fetched thus far. \f(CW$DBI::err\fR should be checked to catch that.
.Sp
The \f(CW\*(C`selectcol_arrayref\*(C'\fR 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 '\f(CW\*(C`Columns\*(C'\fR'
attribute which must be a ref to an array containing the column number
or numbers to use. For example:
.Sp
.Vb 3
\&  # get array of id and name pairs:
\&  my $ary_ref = $dbh->selectcol_arrayref("select id, name from table", { Columns=>[1,2] });
\&  my %hash = @$ary_ref; # build hash from key-value pairs so $hash{$id} => name
.Ve
.Sp
You can specify a maximum number of rows to fetch by including a
\&'\f(CW\*(C`MaxRows\*(C'\fR' attribute in \e%attr.
.ie n .IP """prepare""" 4
.el .IP "\f(CWprepare\fR" 4
.IX Item "prepare"
.Vb 2
\&  $sth = $dbh->prepare($statement)          or die $dbh->errstr;
\&  $sth = $dbh->prepare($statement, \e%attr)  or die $dbh->errstr;
.Ve
.Sp
Prepares a statement for later execution by the database
engine and returns a reference to a statement handle object.
.Sp
The returned statement handle can be used to get attributes of the
statement and invoke the \*(L"execute\*(R" method. See \*(L"Statement Handle Methods\*(R".
.Sp
Drivers for engines without the concept of preparing a
statement will typically just store the statement in the returned
handle and process it when \f(CW\*(C`$sth\->execute\*(C'\fR is called. Such drivers are
unlikely to give much useful information about the
statement, such as \f(CW\*(C`$sth\->{NUM_OF_FIELDS}\*(C'\fR, until after \f(CW\*(C`$sth\->execute\*(C'\fR
has been called. Portable applications should take this into account.
.Sp
In general, \s-1DBI\s0 drivers do not parse the contents of the statement
(other than simply counting any \*(L"Placeholders\*(R"). 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.
.Sp
Portable applications should not assume that a new statement can be
prepared and/or executed while still fetching results from a previous
statement.
.Sp
Some command-line \s-1SQL\s0 tools use statement terminators, like a semicolon,
to indicate the end of a statement. Such terminators should not normally
be used with the \s-1DBI\s0.
.ie n .IP """prepare_cached""" 4
.el .IP "\f(CWprepare_cached\fR" 4
.IX Item "prepare_cached"
.Vb 3
\&  $sth = $dbh->prepare_cached($statement)
\&  $sth = $dbh->prepare_cached($statement, \e%attr)
\&  $sth = $dbh->prepare_cached($statement, \e%attr, $if_active)
.Ve
.Sp
Like \*(L"prepare\*(R" except that the statement handle returned will be
stored in a hash associated with the \f(CW$dbh\fR. If another call is made to
\&\f(CW\*(C`prepare_cached\*(C'\fR with the same \f(CW$statement\fR and \f(CW%attr\fR parameter values,
then the corresponding cached \f(CW$sth\fR will be returned without contacting the
database server.
.Sp
The \f(CW$if_active\fR parameter lets you adjust the behaviour if an
already cached statement handle is still Active.  There are several
alternatives:
.RS 4
.ie n .IP "\fB0\fR: A warning will be generated, and \fIfinish()\fR will be called on the statement handle before it is returned.  This is the default behaviour if $if_active is not passed." 4
.el .IP "\fB0\fR: A warning will be generated, and \fIfinish()\fR will be called on the statement handle before it is returned.  This is the default behaviour if \f(CW$if_active\fR is not passed." 4
.IX Item "0: A warning will be generated, and finish() will be called on the statement handle before it is returned.  This is the default behaviour if $if_active is not passed."
.PD 0
.IP "\fB1\fR: \fIfinish()\fR will be called on the statement handle, but the warning is suppressed." 4
.IX Item "1: finish() will be called on the statement handle, but the warning is suppressed."
.IP "\fB2\fR: Disables any checking." 4
.IX Item "2: Disables any checking."
.IP "\fB3\fR: The existing active statement handle will be removed from the cache and a new statement handle prepared and cached in its place. This is the safest option because it doesn't affect the state of the old handle, it just removes it from the cache. [Added in \s-1DBI\s0 1.40]" 4
.IX Item "3: The existing active statement handle will be removed from the cache and a new statement handle prepared and cached in its place. This is the safest option because it doesn't affect the state of the old handle, it just removes it from the cache. [Added in DBI 1.40]"
.RE
.RS 4
.PD
.Sp
Here are some examples of \f(CW\*(C`prepare_cached\*(C'\fR:
.Sp
.Vb 10
\&  sub insert_hash {
\&    my ($table, $field_values) = @_;
\&    # sort to keep field order, and thus sql, stable for prepare_cached
\&    my @fields = sort keys %$field_values;
\&    my @values = @{$field_values}{@fields};
\&    my $sql = sprintf "insert into %s (%s) values (%s)",
\&        $table, join(",", @fields), join(",", ("?")x@fields);
\&    my $sth = $dbh->prepare_cached($sql);
\&    return $sth->execute(@values);
\&  }
.Ve
.Sp
.Vb 10
\&  sub search_hash {
\&    my ($table, $field_values) = @_;
\&    # sort to keep field order, and thus sql, stable for prepare_cached
\&    my @fields = sort keys %$field_values;
\&    my @values = @{$field_values}{@fields};
\&    my $qualifier = "";
\&    $qualifier = "where ".join(" and ", map { "$_=?" } @fields) if @fields;
\&    $sth = $dbh->prepare_cached("SELECT * FROM $table $qualifier");
\&    return $dbh->selectall_arrayref($sth, {}, @values);
\&  }
.Ve
.Sp
\&\fICaveat emptor:\fR 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:
.Sp
.Vb 3
\&  my $sth = $dbh->prepare_cached('SELECT * FROM foo WHERE bar=?');
\&  $sth->execute(...);
\&  while (my $data = $sth->fetchrow_hashref) {
.Ve
.Sp
.Vb 7
\&    # later, in some other code called within the loop...
\&    my $sth2 = $dbh->prepare_cached('SELECT * FROM foo WHERE bar=?');
\&    $sth2->execute(...);
\&    while (my $data2 = $sth2->fetchrow_arrayref) {
\&      do_stuff(...);
\&    }
\&  }
.Ve
.Sp
In this example, since both handles are preparing the exact same statement,
\&\f(CW$sth2\fR will not be its own statement handle, but a duplicate of \f(CW$sth\fR
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 \f(CW$sth\fR
is the same as \f(CW$sth2\fR the outer fetch loop will also terminate.
.Sp
You'll know if you run into this problem because \fIprepare_cached()\fR
will generate a warning by default (when \f(CW$if_active\fR is false).
.Sp
The cache used by \fIprepare_cached()\fR is keyed by both the statement
and any attributes so you can also avoid this issue by doing something
like:
.Sp
.Vb 1
\&  $sth = $dbh->prepare_cached("...", { dbi_dummy => __FILE__.__LINE__ });
.Ve
.Sp
which will ensure that prepare_cached only returns statements cached
by that line of code in that source file. 
.Sp
If you'd like the cache to managed intelligently, you can tie the                                                                                                          
hashref returned by \f(CW\*(C`CachedKids\*(C'\fR to an appropriate caching module,                                                                                                        
such as Tie::Cache::LRU:                                                                                                                                                
.Sp
.Vb 2
\&  my $cache = $dbh->{CachedKids};                                                                                                                                          
\&  tie %$cache, 'Tie::Cache::LRU', 500;
.Ve
.RE
.ie n .IP """commit""" 4
.el .IP "\f(CWcommit\fR" 4
.IX Item "commit"
.Vb 1
\&  $rc  = $dbh->commit     or die $dbh->errstr;
.Ve
.Sp
Commit (make permanent) the most recent series of database changes
if the database supports transactions and AutoCommit is off.
.Sp
If \f(CW\*(C`AutoCommit\*(C'\fR is on, then calling
\&\f(CW\*(C`commit\*(C'\fR will issue a \*(L"commit ineffective with AutoCommit\*(R" warning.
.Sp
See also \*(L"Transactions\*(R" in the \*(L"\s-1FURTHER\s0 \s-1INFORMATION\s0\*(R" section below.
.ie n .IP """rollback""" 4
.el .IP "\f(CWrollback\fR" 4
.IX Item "rollback"
.Vb 1
\&  $rc  = $dbh->rollback   or die $dbh->errstr;
.Ve
.Sp
Rollback (undo) the most recent series of uncommitted database
changes if the database supports transactions and AutoCommit is off.
.Sp
If \f(CW\*(C`AutoCommit\*(C'\fR is on, then calling
\&\f(CW\*(C`rollback\*(C'\fR will issue a \*(L"rollback ineffective with AutoCommit\*(R" warning.
.Sp
See also \*(L"Transactions\*(R" in the \*(L"\s-1FURTHER\s0 \s-1INFORMATION\s0\*(R" section below.
.ie n .IP """begin_work""" 4
.el .IP "\f(CWbegin_work\fR" 4
.IX Item "begin_work"
.Vb 1
\&  $rc  = $dbh->begin_work   or die $dbh->errstr;
.Ve
.Sp
Enable transactions (by turning \f(CW\*(C`AutoCommit\*(C'\fR off) until the next call
to \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR. After the next \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR,
\&\f(CW\*(C`AutoCommit\*(C'\fR will automatically be turned on again.
.Sp
If \f(CW\*(C`AutoCommit\*(C'\fR is already off when \f(CW\*(C`begin_work\*(C'\fR is called then
it does nothing except return an error. If the driver does not support
transactions then when \f(CW\*(C`begin_work\*(C'\fR attempts to set \f(CW\*(C`AutoCommit\*(C'\fR off
the driver will trigger a fatal error.
.Sp
See also \*(L"Transactions\*(R" in the \*(L"\s-1FURTHER\s0 \s-1INFORMATION\s0\*(R" section below.
.ie n .IP """disconnect""" 4
.el .IP "\f(CWdisconnect\fR" 4
.IX Item "disconnect"
.Vb 1
\&  $rc = $dbh->disconnect  or warn $dbh->errstr;
.Ve
.Sp
Disconnects the database from the database handle. \f(CW\*(C`disconnect\*(C'\fR is typically only used
before exiting the program. The handle is of little use after disconnecting.
.Sp
The transaction behaviour of the \f(CW\*(C`disconnect\*(C'\fR 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 \f(CW\*(C`AutoCommit\*(C'\fR should explicitly call \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR before
calling \f(CW\*(C`disconnect\*(C'\fR.
.Sp
The database is automatically disconnected by the \f(CW\*(C`DESTROY\*(C'\fR method if
still connected when there are no longer any references to the handle.
The \f(CW\*(C`DESTROY\*(C'\fR method for each driver should implicitly call \f(CW\*(C`rollback\*(C'\fR to
undo any uncommitted changes. This is vital behaviour to ensure that
incomplete transactions don't get committed simply because Perl calls
\&\f(CW\*(C`DESTROY\*(C'\fR on every object before exiting. Also, do not rely on the order
of object destruction during \*(L"global destruction\*(R", as it is undefined.
.Sp
Generally, if you want your changes to be commited or rolled back when
you disconnect, then you should explicitly call \*(L"commit\*(R" or \*(L"rollback\*(R"
before disconnecting.
.Sp
If you disconnect from a database while you still have active
statement handles (e.g., \s-1SELECT\s0 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 \f(CW\*(C`finish\*(C'\fR method on the active handles.
.ie n .IP """ping""" 4
.el .IP "\f(CWping\fR" 4
.IX Item "ping"
.Vb 1
\&  $rc = $dbh->ping;
.Ve
.Sp
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.
.Sp
The current \fIdefault\fR implementation always returns true without
actually doing anything. Actually, it returns "\f(CW\*(C`0 but true\*(C'\fR" 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.
.Sp
Few applications would have direct use for this method. See the specialized
Apache::DBI module for one example usage.
.ie n .IP """get_info""" 4
.el .IP "\f(CWget_info\fR" 4
.IX Item "get_info"
.Vb 1
\&  $value = $dbh->get_info( $info_type );
.Ve
.Sp
Returns information about the implementation, i.e. driver and data
source capabilities, restrictions etc. It returns \f(CW\*(C`undef\*(C'\fR for
unknown or unimplemented information types. For example:
.Sp
.Vb 2
\&  $database_version  = $dbh->get_info(  18 ); # SQL_DBMS_VER
\&  $max_select_tables = $dbh->get_info( 106 ); # SQL_MAXIMUM_TABLES_IN_SELECT
.Ve
.Sp
See \*(L"Standards Reference Information\*(R" for more detailed information
about the information types and their meanings and possible return values.
.Sp
The DBI::Const::GetInfoType module exports a \f(CW%GetInfoType\fR hash that
can be used to map info type names to numbers. For example:
.Sp
.Vb 1
\&  $database_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );
.Ve
.Sp
The names are a merging of the \s-1ANSI\s0 and \s-1ODBC\s0 standards (which differ
in some cases). See DBI::Const::GetInfoType for more details.
.Sp
Because some \s-1DBI\s0 methods make use of \fIget_info()\fR, drivers are strongly
encouraged to support \fIat least\fR the following very minimal set
of information types to ensure the \s-1DBI\s0 itself works properly:
.Sp
.Vb 7
\& 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
.Ve
.ie n .IP """table_info""" 4
.el .IP "\f(CWtable_info\fR" 4
.IX Item "table_info"
.Vb 2
\&  $sth = $dbh->table_info( $catalog, $schema, $table, $type );
\&  $sth = $dbh->table_info( $catalog, $schema, $table, $type, \e%attr );
.Ve
.Sp
Returns an active statement handle that can be used to fetch
information about tables and views that exist in the database.
.Sp
The arguments \f(CW$catalog\fR, \f(CW$schema\fR and \f(CW$table\fR may accept search patterns
according to the database/driver, for example: \f(CW$table\fR = '%FOO%';
Remember that the underscore character ('\f(CW\*(C`_\*(C'\fR') is a search pattern
that means match any character, so 'FOO_%' is the same as 'FOO%'
and 'FOO_BAR%' will match names like '\s-1FOO1BAR\s0'.
.Sp
The value of \f(CW$type\fR 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.:
.Sp
.Vb 2
\&  $type = "TABLE";
\&  $type = "'TABLE','VIEW'";
.Ve
.Sp
In addition the following special cases may also be supported by some drivers:
.RS 4
.ie n .IP "* If the value of $catalog\fR is '%' and \f(CW$schema\fR and \f(CW$table name are empty strings, the result set contains a list of catalog names. For example:" 4
.el .IP "* If the value of \f(CW$catalog\fR is '%' and \f(CW$schema\fR and \f(CW$table\fR name are empty strings, the result set contains a list of catalog names. For example:" 4
.IX 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:"
.Vb 1
\&  $sth = $dbh->table_info('%', '', '');
.Ve
.ie n .IP "* If the value of $schema\fR is '%' and \f(CW$catalog\fR and \f(CW$table are empty strings, the result set contains a list of schema names." 4
.el .IP "* If the value of \f(CW$schema\fR is '%' and \f(CW$catalog\fR and \f(CW$table\fR are empty strings, the result set contains a list of schema names." 4
.IX Item "If the value of $schema is '%' and $catalog and $table are empty strings, the result set contains a list of schema names."
.PD 0
.ie n .IP "* If the value of $type\fR is '%' and \f(CW$catalog\fR, \f(CW$schema\fR, and \f(CW$table are all empty strings, the result set contains a list of table types." 4
.el .IP "* If the value of \f(CW$type\fR is '%' and \f(CW$catalog\fR, \f(CW$schema\fR, and \f(CW$table\fR are all empty strings, the result set contains a list of table types." 4
.IX 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."
.RE
.RS 4
.PD
.Sp
If your driver doesn't support one or more of the selection filter
parameters then you may get back more than you asked for and can
do the filtering yourself.
.Sp
This method can be expensive, and can return a large amount of data.
(For example, small Oracle installation returns over 2000 rows.)
So it's a good idea to use the filters to limit the data as much as possible.
.Sp
The statement handle returned has at least the following fields in the
order show below. Other fields, after these, may also be present.
.Sp
\&\fB\s-1TABLE_CAT\s0\fR: Table catalog identifier. This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not
applicable to the data source, which is usually the case. This field
is empty if not applicable to the table.
.Sp
\&\fB\s-1TABLE_SCHEM\s0\fR: The name of the schema containing the \s-1TABLE_NAME\s0 value.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to data source, and
empty if not applicable to the table.
.Sp
\&\fB\s-1TABLE_NAME\s0\fR: Name of the table (or view, synonym, etc).
.Sp
\&\fB\s-1TABLE_TYPE\s0\fR: One of the following: \*(L"\s-1TABLE\s0\*(R", \*(L"\s-1VIEW\s0\*(R", \*(L"\s-1SYSTEM\s0 \s-1TABLE\s0\*(R",
\&\*(L"\s-1GLOBAL\s0 \s-1TEMPORARY\s0\*(R", \*(L"\s-1LOCAL\s0 \s-1TEMPORARY\s0\*(R", \*(L"\s-1ALIAS\s0\*(R", \*(L"\s-1SYNONYM\s0\*(R" or a type
identifier that is specific to the data
source.
.Sp
\&\fB\s-1REMARKS\s0\fR: A description of the table. May be \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
.Sp
Note that \f(CW\*(C`table_info\*(C'\fR might not return records for all tables.
Applications can use any valid table regardless of whether it's
returned by \f(CW\*(C`table_info\*(C'\fR.
.Sp
See also \*(L"tables\*(R", \*(L"Catalog Methods\*(R" and
\&\*(L"Standards Reference Information\*(R".
.RE
.ie n .IP """column_info""" 4
.el .IP "\f(CWcolumn_info\fR" 4
.IX Item "column_info"
.Vb 1
\&  $sth = $dbh->column_info( $catalog, $schema, $table, $column );
.Ve
.Sp
Returns an active statement handle that can be used to fetch
information about columns in specified tables.
.Sp
The arguments \f(CW$schema\fR, \f(CW$table\fR and \f(CW$column\fR may accept search patterns
according to the database/driver, for example: \f(CW$table\fR = '%FOO%';
.Sp
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.
.Sp
The statement handle returned has at least the following fields in the
order shown below. Other fields, after these, may also be present.
.Sp
\&\fB\s-1TABLE_CAT\s0\fR: The catalog identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.
.Sp
\&\fB\s-1TABLE_SCHEM\s0\fR: The schema identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
and empty if not applicable to the table.
.Sp
\&\fB\s-1TABLE_NAME\s0\fR: The table identifier.
Note: A driver may provide column metadata not only for base tables, but
also for derived objects like \s-1SYNONYMS\s0 etc.
.Sp
\&\fB\s-1COLUMN_NAME\s0\fR: The column identifier.
.Sp
\&\fB\s-1DATA_TYPE\s0\fR: The concise data type code.
.Sp
\&\fB\s-1TYPE_NAME\s0\fR: A data source dependent data type name.
.Sp
\&\fB\s-1COLUMN_SIZE\s0\fR: 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.
.Sp
\&\fB\s-1BUFFER_LENGTH\s0\fR: The length in bytes of transferred data.
.Sp
\&\fB\s-1DECIMAL_DIGITS\s0\fR: The total number of significant digits to the right of
the decimal point.
.Sp
\&\fB\s-1NUM_PREC_RADIX\s0\fR: The radix for numeric precision.
The value is 10 or 2 for numeric data types and \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not
applicable.
.Sp
\&\fB\s-1NULLABLE\s0\fR: Indicates if a column can accept NULLs.
The following values are defined:
.Sp
.Vb 3
\&  SQL_NO_NULLS          0
\&  SQL_NULLABLE          1
\&  SQL_NULLABLE_UNKNOWN  2
.Ve
.Sp
\&\fB\s-1REMARKS\s0\fR: A description of the column.
.Sp
\&\fB\s-1COLUMN_DEF\s0\fR: The default value of the column.
.Sp
\&\fB\s-1SQL_DATA_TYPE\s0\fR: The \s-1SQL\s0 data type.
.Sp
\&\fB\s-1SQL_DATETIME_SUB\s0\fR: The subtype code for datetime and interval data types.
.Sp
\&\fB\s-1CHAR_OCTET_LENGTH\s0\fR: The maximum length in bytes of a character or binary
data type column.
.Sp
\&\fB\s-1ORDINAL_POSITION\s0\fR: The column sequence number (starting with 1).
.Sp
\&\fB\s-1IS_NULLABLE\s0\fR: Indicates if the column can accept NULLs.
Possible values are: '\s-1NO\s0', '\s-1YES\s0' and ''.
.Sp
\&\s-1SQL/CLI\s0 defines the following additional columns:
.Sp
.Vb 18
\&  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
.Ve
.Sp
Drivers capable of supplying any of those values should do so in
the corresponding column and supply undef values for the others.
.Sp
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.
.Sp
The result set is ordered by \s-1TABLE_CAT\s0, \s-1TABLE_SCHEM\s0, \s-1TABLE_NAME\s0
and \s-1ORDINAL_POSITION\s0.
.Sp
Note: There is some overlap with statement attributes (in perl) and
SQLDescribeCol (in \s-1ODBC\s0). However, SQLColumns provides more metadata.
.Sp
See also \*(L"Catalog Methods\*(R" and \*(L"Standards Reference Information\*(R".
.ie n .IP """primary_key_info""" 4
.el .IP "\f(CWprimary_key_info\fR" 4
.IX Item "primary_key_info"
.Vb 1
\&  $sth = $dbh->primary_key_info( $catalog, $schema, $table );
.Ve
.Sp
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 \fItable_info()\fR).
.Sp
For example:
.Sp
.Vb 2
\&  $sth = $dbh->primary_key_info( undef, $user, 'foo' );
\&  $data = $sth->fetchall_arrayref;
.Ve
.Sp
The statement handle will return one row per column, ordered by
\&\s-1TABLE_CAT\s0, \s-1TABLE_SCHEM\s0, \s-1TABLE_NAME\s0, and \s-1KEY_SEQ\s0.
If there is no primary key then the statement handle will fetch no rows.
.Sp
Note: The support for the selection criteria, such as \f(CW$catalog\fR, is
driver specific.  If the driver doesn't support catalogs and/or
schemas, it may ignore these criteria.
.Sp
The statement handle returned has at least the following fields in the
order shown below. Other fields, after these, may also be present.
.Sp
\&\fB\s-1TABLE_CAT\s0\fR: The catalog identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.
.Sp
\&\fB\s-1TABLE_SCHEM\s0\fR: The schema identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
and empty if not applicable to the table.
.Sp
\&\fB\s-1TABLE_NAME\s0\fR: The table identifier.
.Sp
\&\fB\s-1COLUMN_NAME\s0\fR: The column identifier.
.Sp
\&\fB\s-1KEY_SEQ\s0\fR: The column sequence number (starting with 1).
Note: This field is named \fB\s-1ORDINAL_POSITION\s0\fR in \s-1SQL/CLI\s0.
.Sp
\&\fB\s-1PK_NAME\s0\fR: The primary key constraint identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source.
.Sp
See also \*(L"Catalog Methods\*(R" and \*(L"Standards Reference Information\*(R".
.ie n .IP """primary_key""" 4
.el .IP "\f(CWprimary_key\fR" 4
.IX Item "primary_key"
.Vb 1
\&  @key_column_names = $dbh->primary_key( $catalog, $schema, $table );
.Ve
.Sp
Simple interface to the \fIprimary_key_info()\fR 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.
If there is no primary key then an empty list is returned.
.ie n .IP """foreign_key_info""" 4
.el .IP "\f(CWforeign_key_info\fR" 4
.IX Item "foreign_key_info"
.Vb 2
\&  $sth = $dbh->foreign_key_info( $pk_catalog, $pk_schema, $pk_table
\&                               , $fk_catalog, $fk_schema, $fk_table );
.Ve
.Sp
.Vb 3
\&  $sth = $dbh->foreign_key_info( $pk_catalog, $pk_schema, $pk_table
\&                               , $fk_catalog, $fk_schema, $fk_table
\&                               , \e%attr );
.Ve
.Sp
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 \fItable_info()\fR).
.Sp
\&\f(CW$pk_catalog\fR, \f(CW$pk_schema\fR, \f(CW$pk_table\fR
identify the primary (unique) key table (\fB\s-1PKT\s0\fR).
.Sp
\&\f(CW$fk_catalog\fR, \f(CW$fk_schema\fR, \f(CW$fk_table\fR
identify the foreign key table (\fB\s-1FKT\s0\fR).
.Sp
If both \fB\s-1PKT\s0\fR and \fB\s-1FKT\s0\fR are given, the function returns the foreign key, if
any, in table \fB\s-1FKT\s0\fR that refers to the primary (unique) key of table \fB\s-1PKT\s0\fR.
(Note: In \s-1SQL/CLI\s0, the result is implementation\-defined.)
.Sp
If only \fB\s-1PKT\s0\fR is given, then the result set contains the primary key
of that table and all foreign keys that refer to it.
.Sp
If only \fB\s-1FKT\s0\fR is given, then the result set contains all foreign keys
in that table and the primary keys to which they refer.
(Note: In \s-1SQL/CLI\s0, the result includes unique keys too.)
.Sp
For example:
.Sp
.Vb 3
\&  $sth = $dbh->foreign_key_info( undef, $user, 'master');
\&  $sth = $dbh->foreign_key_info( undef, undef,   undef , undef, $user, 'detail');
\&  $sth = $dbh->foreign_key_info( undef, $user, 'master', undef, $user, 'detail');
.Ve
.Sp
Note: The support for the selection criteria, such as \f(CW$catalog\fR, is
driver specific.  If the driver doesn't support catalogs and/or
schemas, it may ignore these criteria.
.Sp
The statement handle returned has the following fields in the order shown below.
Because \s-1ODBC\s0 never includes unique keys, they define different columns in the
result set than \s-1SQL/CLI\s0. \s-1SQL/CLI\s0 column names are shown in parentheses.
.Sp
\&\fB\s-1PKTABLE_CAT\s0    ( \s-1UK_TABLE_CAT\s0      )\fR:
The primary (unique) key table catalog identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.
.Sp
\&\fB\s-1PKTABLE_SCHEM\s0  ( \s-1UK_TABLE_SCHEM\s0    )\fR:
The primary (unique) key table schema identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
and empty if not applicable to the table.
.Sp
\&\fB\s-1PKTABLE_NAME\s0   ( \s-1UK_TABLE_NAME\s0     )\fR:
The primary (unique) key table identifier.
.Sp
\&\fB\s-1PKCOLUMN_NAME\s0  (\s-1UK_COLUMN_NAME\s0    )\fR:
The primary (unique) key column identifier.
.Sp
\&\fB\s-1FKTABLE_CAT\s0    ( \s-1FK_TABLE_CAT\s0      )\fR:
The foreign key table catalog identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.
.Sp
\&\fB\s-1FKTABLE_SCHEM\s0  ( \s-1FK_TABLE_SCHEM\s0    )\fR:
The foreign key table schema identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
and empty if not applicable to the table.
.Sp
\&\fB\s-1FKTABLE_NAME\s0   ( \s-1FK_TABLE_NAME\s0     )\fR:
The foreign key table identifier.
.Sp
\&\fB\s-1FKCOLUMN_NAME\s0  ( \s-1FK_COLUMN_NAME\s0    )\fR:
The foreign key column identifier.
.Sp
\&\fB\s-1KEY_SEQ\s0        ( \s-1ORDINAL_POSITION\s0  )\fR:
The column sequence number (starting with 1).
.Sp
\&\fB\s-1UPDATE_RULE\s0    ( \s-1UPDATE_RULE\s0       )\fR:
The referential action for the \s-1UPDATE\s0 rule.
The following codes are defined:
.Sp
.Vb 5
\&  CASCADE              0
\&  RESTRICT             1
\&  SET NULL             2
\&  NO ACTION            3
\&  SET DEFAULT          4
.Ve
.Sp
\&\fB\s-1DELETE_RULE\s0    ( \s-1DELETE_RULE\s0       )\fR:
The referential action for the \s-1DELETE\s0 rule.
The codes are the same as for \s-1UPDATE_RULE\s0.
.Sp
\&\fB\s-1FK_NAME\s0        ( \s-1FK_NAME\s0           )\fR:
The foreign key name.
.Sp
\&\fB\s-1PK_NAME\s0        ( \s-1UK_NAME\s0           )\fR:
The primary (unique) key name.
.Sp
\&\fB\s-1DEFERRABILITY\s0  ( \s-1DEFERABILITY\s0      )\fR:
The deferrability of the foreign key constraint.
The following codes are defined:
.Sp
.Vb 3
\&  INITIALLY DEFERRED   5
\&  INITIALLY IMMEDIATE  6
\&  NOT DEFERRABLE       7
.Ve
.Sp
\&\fB               ( \s-1UNIQUE_OR_PRIMARY\s0 )\fR:
This column is necessary if a driver includes all candidate (i.e. primary and
alternate) keys in the result set (as specified by \s-1SQL/CLI\s0).
The value of this column is \s-1UNIQUE\s0 if the foreign key references an alternate
key and \s-1PRIMARY\s0 if the foreign key references a primary key, or it
may be undefined if the driver doesn't have access to the information.
.Sp
See also \*(L"Catalog Methods\*(R" and \*(L"Standards Reference Information\*(R".
.ie n .IP """statistics_info""" 4
.el .IP "\f(CWstatistics_info\fR" 4
.IX Item "statistics_info"
\&\fBWarning:\fR This method is experimental and may change.
.Sp
.Vb 1
\&  $sth = $dbh->statistics_info( $catalog, $schema, $table, $unique_only, $quick );
.Ve
.Sp
Returns an active statement handle that can be used to fetch statistical
information about a table and its indexes.
.Sp
The arguments don't accept search patterns (unlike \*(L"table_info\*(R").
.Sp
If the boolean argument \f(CW$unique_only\fR is true, only \s-1UNIQUE\s0 indexes will be
returned in the result set, otherwise all indexes will be returned.
.Sp
If the boolean argument \f(CW$quick\fR is set, the actual statistical information
columns (\s-1CARDINALITY\s0 and \s-1PAGES\s0) will only be returned if they are readily
available from the server, and might not be current.  Some databases may
return stale statistics or no statistics at all with this flag set.
.Sp
For example:
.Sp
.Vb 2
\&  $sth = $dbh->statistics_info( undef, $user, 'foo', 1, 1 );
\&  $data = $sth->fetchall_arrayref;
.Ve
.Sp
The statement handle will return at most one row per column name per index,
plus at most one row for the entire table itself, ordered by \s-1NON_UNIQUE\s0, \s-1TYPE\s0,
\&\s-1INDEX_QUALIFIER\s0, \s-1INDEX_NAME\s0, and \s-1ORDINAL_POSITION\s0.
.Sp
Note: The support for the selection criteria, such as \f(CW$catalog\fR, is
driver specific.  If the driver doesn't support catalogs and/or
schemas, it may ignore these criteria.
.Sp
The statement handle returned has at least the following fields in the
order shown below. Other fields, after these, may also be present.
.Sp
\&\fB\s-1TABLE_CAT\s0\fR: The catalog identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
which is often the case.  This field is empty if not applicable to the
table.
.Sp
\&\fB\s-1TABLE_SCHEM\s0\fR: The schema identifier.
This field is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if not applicable to the data source,
and empty if not applicable to the table.
.Sp
\&\fB\s-1TABLE_NAME\s0\fR: The table identifier.
.Sp
\&\fB\s-1NON_UNIQUE\s0\fR: Unique index indicator.
Returns 0 for unique indexes, 1 for non-unique indexes
.Sp
\&\fB\s-1INDEX_QUALIFIER\s0\fR: Index qualifier identifier.
The identifier that is used to qualify the index name when doing a
\&\f(CW\*(C`DROP INDEX\*(C'\fR; \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned if an index qualifier is not
supported by the data source.
If a non-NULL (defined) value is returned in this column, it must be used
to qualify the index name on a \f(CW\*(C`DROP INDEX\*(C'\fR statement; otherwise,
the \s-1TABLE_SCHEM\s0 should be used to qualify the index name.
.Sp
\&\fB\s-1INDEX_NAME\s0\fR: The index identifier.
.Sp
\&\fB\s-1TYPE\s0\fR: The type of information being returned.  Can be any of the
following values: 'table', 'btree', 'clustered', 'content', 'hashed',
or 'other'.
.Sp
In the case that this field is 'table', all fields
other than \s-1TABLE_CAT\s0, \s-1TABLE_SCHEM\s0, \s-1TABLE_NAME\s0, \s-1TYPE\s0,
\&\s-1CARDINALITY\s0, and \s-1PAGES\s0 will be \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
.Sp
\&\fB\s-1ORDINAL_POSITION\s0\fR: Column sequence number (starting with 1).
.Sp
\&\fB\s-1COLUMN_NAME\s0\fR: The column identifier.
.Sp
\&\fB\s-1ASC_OR_DESC\s0\fR: Column sort sequence.
\&\f(CW\*(C`A\*(C'\fR for Ascending, \f(CW\*(C`D\*(C'\fR for Descending, or \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) if
not supported for this index.
.Sp
\&\fB\s-1CARDINALITY\s0\fR: Cardinality of the table or index.
For indexes, this is the number of unique values in the index.
For tables, this is the number of rows in the table.
If not supported, the value will be \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
.Sp
\&\fB\s-1PAGES\s0\fR: Number of storage pages used by this table or index.
If not supported, the value will be \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
.Sp
\&\fB\s-1FILTER_CONDITION\s0\fR: The index filter condition as a string.
If the index is not a filtered index, or it cannot be determined
whether the index is a filtered index, this value is \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
If the index is a filtered index, but the filter condition
cannot be determined, this value is the empty string \f(CW''\fR.
Otherwise it will be the literal filter condition as a string,
such as \f(CW\*(C`SALARY <= 4500\*(C'\fR.
.Sp
See also \*(L"Catalog Methods\*(R" and \*(L"Standards Reference Information\*(R".
.ie n .IP """tables""" 4
.el .IP "\f(CWtables\fR" 4
.IX Item "tables"
.Vb 2
\&  @names = $dbh->tables( $catalog, $schema, $table, $type );
\&  @names = $dbh->tables;        # deprecated
.Ve
.Sp
Simple interface to \fItable_info()\fR. Returns a list of matching
table names, possibly including a catalog/schema prefix.
.Sp
See \*(L"table_info\*(R" for a description of the parameters.
.Sp
If \f(CW\*(C`$dbh\->get_info(29)\*(C'\fR returns true (29 is \s-1SQL_IDENTIFIER_QUOTE_CHAR\s0)
then the table names are constructed and quoted by \*(L"quote_identifier\*(R"
to ensure they are usable even if they contain whitespace or reserved
words etc. This means that the table names returned will include
quote characters.
.ie n .IP """type_info_all""" 4
.el .IP "\f(CWtype_info_all\fR" 4
.IX Item "type_info_all"
.Vb 1
\&  $type_info_all = $dbh->type_info_all;
.Ve
.Sp
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.
.Sp
The first item is a reference to an 'index' hash of \f(CW\*(C`Name =\*(C'\fR> \f(CW\*(C`Index\*(C'\fR 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:
.Sp
.Vb 28
\&  $type_info_all = [
\&    {   TYPE_NAME         => 0,
\&        DATA_TYPE         => 1,
\&        COLUMN_SIZE       => 2,     # was PRECISION originally
\&        LITERAL_PREFIX    => 3,
\&        LITERAL_SUFFIX    => 4,
\&        CREATE_PARAMS     => 5,
\&        NULLABLE          => 6,
\&        CASE_SENSITIVE    => 7,
\&        SEARCHABLE        => 8,
\&        UNSIGNED_ATTRIBUTE=> 9,
\&        FIXED_PREC_SCALE  => 10,    # was MONEY originally
\&        AUTO_UNIQUE_VALUE => 11,    # was AUTO_INCREMENT originally
\&        LOCAL_TYPE_NAME   => 12,
\&        MINIMUM_SCALE     => 13,
\&        MAXIMUM_SCALE     => 14,
\&        SQL_DATA_TYPE     => 15,
\&        SQL_DATETIME_SUB  => 16,
\&        NUM_PREC_RADIX    => 17,
\&        INTERVAL_PRECISION=> 18,
\&    },
\&    [ '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
\&    ],
\&  ];
.Ve
.Sp
More than one row may have the same value in the \f(CW\*(C`DATA_TYPE\*(C'\fR
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 \f(CW\*(C`AUTO_UNIQUE_VALUE\*(C'\fR set, with and without \f(CW\*(C`UNSIGNED_ATTRIBUTE\*(C'\fR, etc).
.Sp
The rows are ordered by \f(CW\*(C`DATA_TYPE\*(C'\fR first and then by how closely each
type maps to the corresponding \s-1ODBC\s0 \s-1SQL\s0 data type, closest first.
.Sp
The meaning of the fields is described in the documentation for
the \*(L"type_info\*(R" method.
.Sp
An 'index' hash is provided so you don't need to rely on index
values defined above.  However, using \s-1DBD::ODBC\s0 with some old \s-1ODBC\s0
drivers may return older names, shown as comments in the example above.
Another issue with the index hash is that the lettercase of the
keys is not defined. It is usually uppercase, as show here, but
drivers may return names with any lettercase.
.Sp
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 \s-1DBI/ODBC\s0 specification.
.Sp
The \fItype_info_all()\fR method is not normally used directly.
The \*(L"type_info\*(R" method provides a more usable and useful interface
to the data.
.ie n .IP """type_info""" 4
.el .IP "\f(CWtype_info\fR" 4
.IX Item "type_info"
.Vb 1
\&  @type_info = $dbh->type_info($data_type);
.Ve
.Sp
Returns a list of hash references holding information about one or more
variants of \f(CW$data_type\fR. The list is ordered by \f(CW\*(C`DATA_TYPE\*(C'\fR first and
then by how closely each type maps to the corresponding \s-1ODBC\s0 \s-1SQL\s0 data
type, closest first.  If called in a scalar context then only the first
(best) element is returned.
.Sp
If \f(CW$data_type\fR is undefined or \f(CW\*(C`SQL_ALL_TYPES\*(C'\fR, then the list will
contain hashes for all data type variants supported by the database and driver.
.Sp
If \f(CW$data_type\fR is an array reference then \f(CW\*(C`type_info\*(C'\fR returns the
information for the \fIfirst\fR type in the array that has any matches.
.Sp
The keys of the hash follow the same letter case conventions as the
rest of the \s-1DBI\s0 (see \*(L"Naming Conventions and Name Space\*(R"). The
following uppercase items should always exist, though may be undef:
.RS 4
.IP "\s-1TYPE_NAME\s0 (string)" 4
.IX Item "TYPE_NAME (string)"
Data type name for use in \s-1CREATE\s0 \s-1TABLE\s0 statements etc.
.IP "\s-1DATA_TYPE\s0 (integer)" 4
.IX Item "DATA_TYPE (integer)"
\&\s-1SQL\s0 data type number.
.IP "\s-1COLUMN_SIZE\s0 (integer)" 4
.IX Item "COLUMN_SIZE (integer)"
For numeric types, this is either the total number of digits (if the
\&\s-1NUM_PREC_RADIX\s0 value is 10) or the total number of bits allowed in the
column (if \s-1NUM_PREC_RADIX\s0 is 2).
.Sp
For string types, this is the maximum size of the string in characters.
.Sp
For date and interval types, this is the maximum number of characters
needed to display the value.
.IP "\s-1LITERAL_PREFIX\s0 (string)" 4
.IX Item "LITERAL_PREFIX (string)"
Characters used to prefix a literal. A typical prefix is "\f(CW\*(C`'\*(C'\fR\*(L" for characters,
or possibly \*(R"\f(CW\*(C`0x\*(C'\fR" for binary values passed as hexadecimal.  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is
returned for data types for which this is not applicable.
.IP "\s-1LITERAL_SUFFIX\s0 (string)" 4
.IX Item "LITERAL_SUFFIX (string)"
Characters used to suffix a literal. Typically "\f(CW\*(C`'\*(C'\fR" for characters.
\&\s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned for data types where this is not applicable.
.IP "\s-1CREATE_PARAMS\s0 (string)" 4
.IX Item "CREATE_PARAMS (string)"
Parameter names for data type definition. For example, \f(CW\*(C`CREATE_PARAMS\*(C'\fR for a
\&\f(CW\*(C`DECIMAL\*(C'\fR would be "\f(CW\*(C`precision,scale\*(C'\fR" if the \s-1DECIMAL\s0 type should be
declared as \f(CW\*(C`DECIMAL(\*(C'\fR\fIprecision,scale\fR\f(CW\*(C`)\*(C'\fR where \fIprecision\fR and \fIscale\fR
are integer values.  For a \f(CW\*(C`VARCHAR\*(C'\fR it would be "\f(CW\*(C`max length\*(C'\fR".
\&\s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned for data types for which this is not applicable.
.IP "\s-1NULLABLE\s0 (integer)" 4
.IX Item "NULLABLE (integer)"
Indicates whether the data type accepts a \s-1NULL\s0 value:
\&\f(CW0\fR or an empty string = no, \f(CW1\fR = yes, \f(CW2\fR = unknown.
.IP "\s-1CASE_SENSITIVE\s0 (boolean)" 4
.IX Item "CASE_SENSITIVE (boolean)"
Indicates whether the data type is case sensitive in collations and
comparisons.
.IP "\s-1SEARCHABLE\s0 (integer)" 4
.IX Item "SEARCHABLE (integer)"
Indicates how the data type can be used in a \s-1WHERE\s0 clause, as
follows:
.Sp
.Vb 4
\&  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
.Ve
.IP "\s-1UNSIGNED_ATTRIBUTE\s0 (boolean)" 4
.IX Item "UNSIGNED_ATTRIBUTE (boolean)"
Indicates whether the data type is unsigned.  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned
for data types for which this is not applicable.
.IP "\s-1FIXED_PREC_SCALE\s0 (boolean)" 4
.IX Item "FIXED_PREC_SCALE (boolean)"
Indicates whether the data type always has the same precision and scale
(such as a money type).  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned for data types
for which
this is not applicable.
.IP "\s-1AUTO_UNIQUE_VALUE\s0 (boolean)" 4
.IX 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.  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned
for data types for which this is not applicable.
.IP "\s-1LOCAL_TYPE_NAME\s0 (string)" 4
.IX Item "LOCAL_TYPE_NAME (string)"
Localized version of the \f(CW\*(C`TYPE_NAME\*(C'\fR for use in dialog with users.
\&\s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned if a localized name is not available (in which
case \f(CW\*(C`TYPE_NAME\*(C'\fR should be used).
.IP "\s-1MINIMUM_SCALE\s0 (integer)" 4
.IX Item "MINIMUM_SCALE (integer)"
The minimum scale of the data type. If a data type has a fixed scale,
then \f(CW\*(C`MAXIMUM_SCALE\*(C'\fR holds the same value.  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned for
data types for which this is not applicable.
.IP "\s-1MAXIMUM_SCALE\s0 (integer)" 4
.IX Item "MAXIMUM_SCALE (integer)"
The maximum scale of the data type. If a data type has a fixed scale,
then \f(CW\*(C`MINIMUM_SCALE\*(C'\fR holds the same value.  \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned for
data types for which this is not applicable.
.IP "\s-1SQL_DATA_TYPE\s0 (integer)" 4
.IX Item "SQL_DATA_TYPE (integer)"
This column is the same as the \f(CW\*(C`DATA_TYPE\*(C'\fR column, except for interval
and datetime data types.  For interval and datetime data types, the
\&\f(CW\*(C`SQL_DATA_TYPE\*(C'\fR field will return \f(CW\*(C`SQL_INTERVAL\*(C'\fR or \f(CW\*(C`SQL_DATETIME\*(C'\fR, and the
\&\f(CW\*(C`SQL_DATETIME_SUB\*(C'\fR field below will return the subcode for the specific
interval or datetime data type. If this field is \s-1NULL\s0, then the driver
does not support or report on interval or datetime subtypes.
.IP "\s-1SQL_DATETIME_SUB\s0 (integer)" 4
.IX Item "SQL_DATETIME_SUB (integer)"
For interval or datetime data types, where the \f(CW\*(C`SQL_DATA_TYPE\*(C'\fR
field above is \f(CW\*(C`SQL_INTERVAL\*(C'\fR or \f(CW\*(C`SQL_DATETIME\*(C'\fR, this field will
hold the \fIsubcode\fR for the specific interval or datetime data type.
Otherwise it will be \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR).
.Sp
Although not mentioned explicitly in the standards, it seems there
is a simple relationship between these values:
.Sp
.Vb 1
\&  DATA_TYPE == (10 * SQL_DATA_TYPE) + SQL_DATETIME_SUB
.Ve
.IP "\s-1NUM_PREC_RADIX\s0 (integer)" 4
.IX Item "NUM_PREC_RADIX (integer)"
The radix value of the data type. For approximate numeric types,
\&\f(CW\*(C`NUM_PREC_RADIX\*(C'\fR
contains the value 2 and \f(CW\*(C`COLUMN_SIZE\*(C'\fR holds the number of bits. For
exact numeric types, \f(CW\*(C`NUM_PREC_RADIX\*(C'\fR contains the value 10 and \f(CW\*(C`COLUMN_SIZE\*(C'\fR holds
the number of decimal digits. \s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) is returned either for data types
for which this is not applicable or if the driver cannot report this information.
.IP "\s-1INTERVAL_PRECISION\s0 (integer)" 4
.IX Item "INTERVAL_PRECISION (integer)"
The interval leading precision for interval types. \s-1NULL\s0 is returned
either for data types for which this is not applicable or if the driver
cannot report this information.
.RE
.RS 4
.Sp
For example, to find the type name for the fields in a select statement
you can do:
.Sp
.Vb 1
\&  @names = map { scalar $dbh->type_info($_)->{TYPE_NAME} } @{ $sth->{TYPE} }
.Ve
.Sp
Since \s-1DBI\s0 and \s-1ODBC\s0 drivers vary in how they map their types into the
\&\s-1ISO\s0 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:
.Sp
.Vb 1
\&  $my_date_type = $dbh->type_info( [ SQL_DATE, SQL_TIMESTAMP ] );
.Ve
.Sp
Similarly, to more reliably find a type to store small integers, you could
use a list starting with \f(CW\*(C`SQL_SMALLINT\*(C'\fR, \f(CW\*(C`SQL_INTEGER\*(C'\fR, \f(CW\*(C`SQL_DECIMAL\*(C'\fR, etc.
.Sp
See also \*(L"Standards Reference Information\*(R".
.RE
.ie n .IP """quote""" 4
.el .IP "\f(CWquote\fR" 4
.IX Item "quote"
.Vb 2
\&  $sql = $dbh->quote($value);
\&  $sql = $dbh->quote($value, $data_type);
.Ve
.Sp
Quote a string literal for use as a literal value in an \s-1SQL\s0 statement,
by escaping any special characters (such as quotation marks)
contained within the string and adding the required type of outer
quotation marks.
.Sp
.Vb 2
\&  $sql = sprintf "SELECT foo FROM bar WHERE baz = %s",
\&                $dbh->quote("Don't");
.Ve
.Sp
For most database types, quote would return \f(CW'Don''t'\fR (including the
outer quotation marks).
.Sp
An undefined \f(CW$value\fR value will be returned as the string \f(CW\*(C`NULL\*(C'\fR (without
single quotation marks) to match how NULLs are represented in \s-1SQL\s0.
.Sp
If \f(CW$data_type\fR is supplied, it is used to try to determine the required
quoting behaviour by using the information returned by \*(L"type_info\*(R".
As a special case, the standard numeric types are optimized to return
\&\f(CW$value\fR without calling \f(CW\*(C`type_info\*(C'\fR.
.Sp
Quote will probably \fInot\fR 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.
.Sp
It is valid for the \fIquote()\fR method to return an \s-1SQL\s0 expression that
evaluates to the desired string. For example:
.Sp
.Vb 1
\&  $quoted = $dbh->quote("one\entwo\e0three")
.Ve
.Sp
may return something like:
.Sp
.Vb 1
\&  CONCAT('one', CHAR(12), 'two', CHAR(0), 'three')
.Ve
.Sp
The \fIquote()\fR method should \fInot\fR be used with \*(L"Placeholders and Bind Values\*(R".
.ie n .IP """quote_identifier""" 4
.el .IP "\f(CWquote_identifier\fR" 4
.IX Item "quote_identifier"
.Vb 2
\&  $sql = $dbh->quote_identifier( $name );
\&  $sql = $dbh->quote_identifier( $catalog, $schema, $table, \e%attr );
.Ve
.Sp
Quote an identifier (table name etc.) for use in an \s-1SQL\s0 statement,
by escaping any special characters (such as double quotation marks)
it contains and adding the required type of outer quotation marks.
.Sp
Undefined names are ignored and the remainder are quoted and then
joined together, typically with a dot (\f(CW\*(C`.\*(C'\fR) character. For example:
.Sp
.Vb 1
\&  $id = $dbh->quote_identifier( undef, 'Her schema', 'My table' );
.Ve
.Sp
would, for most database types, return \f(CW"Her schema"."My table"\fR
(including all the double quotation marks).
.Sp
If three names are supplied then the first is assumed to be a
catalog name and special rules may be applied based on what \*(L"get_info\*(R"
returns for \s-1SQL_CATALOG_NAME_SEPARATOR\s0 (41) and \s-1SQL_CATALOG_LOCATION\s0 (114).
For example, for Oracle:
.Sp
.Vb 1
\&  $id = $dbh->quote_identifier( 'link', 'schema', 'table' );
.Ve
.Sp
would return \f(CW"schema"."table"@"link"\fR.
.ie n .IP """take_imp_data""" 4
.el .IP "\f(CWtake_imp_data\fR" 4
.IX Item "take_imp_data"
.Vb 1
\&  $imp_data = $dbh->take_imp_data;
.Ve
.Sp
Leaves the \f(CW$dbh\fR in an almost dead, zombie\-like, state and returns
a binary string of raw implementation data from the driver which
describes the current database connection. Effectively it detaches
the underlying database \s-1API\s0 connection data from the \s-1DBI\s0 handle.
After calling \fItake_imp_data()\fR, all other methods except \f(CW\*(C`DESTROY\*(C'\fR
will generate a warning and return undef.
.Sp
Why would you want to do this? You don't, forget I even mentioned it.
Unless, that is, you're implementing something advanced like a
multi-threaded connection pool. See DBI::Pool.
.Sp
The returned \f(CW$imp_data\fR can be passed as a \f(CW\*(C`dbi_imp_data\*(C'\fR attribute
to a later \fIconnect()\fR call, even in a separate thread in the same
process, where the driver can use it to 'adopt' the existing
connection that the implementation data was taken from.
.Sp
Some things to keep in mind...
.Sp
\&\fB*\fR the \f(CW$imp_data\fR holds the only reference to the underlying
database \s-1API\s0 connection data. That connection is still 'live' and
won't be cleaned up properly unless the \f(CW$imp_data\fR is used to create
a new \f(CW$dbh\fR which is then allowed to \fIdisconnect()\fR normally.
.Sp
\&\fB*\fR using the same \f(CW$imp_data\fR to create more than one other new
\&\f(CW$dbh\fR at a time may well lead to unpleasant problems. Don't do that.
.Sp
Any child statement handles are effectively destroyed when \fItake_imp_data()\fR is
called.
.Sp
The \f(CW\*(C`take_imp_data\*(C'\fR method was added in \s-1DBI\s0 1.36 but wasn't useful till 1.49.
.Sh "Database Handle Attributes"
.IX Subsection "Database Handle Attributes"
This section describes attributes specific to database handles.
.PP
Changes to these database handle attributes do not affect any other
existing or future database handles.
.PP
Attempting to set or get the value of an unknown attribute generates a warning,
except for private driver-specific attributes (which all have names
starting with a lowercase letter).
.PP
Example:
.PP
.Vb 2
\&  $h->{AutoCommit} = ...;       # set/write
\&  ... = $h->{AutoCommit};       # get/read
.Ve
.ie n .IP """AutoCommit""  (boolean)" 4
.el .IP "\f(CWAutoCommit\fR  (boolean)" 4
.IX Item "AutoCommit  (boolean)"
If true, then database changes cannot be rolled-back (undone).  If false,
then database changes automatically occur within a \*(L"transaction\*(R", which
must either be committed or rolled back using the \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR
methods.
.Sp
Drivers should always default to \f(CW\*(C`AutoCommit\*(C'\fR mode (an unfortunate
choice largely forced on the \s-1DBI\s0 by \s-1ODBC\s0 and \s-1JDBC\s0 conventions.)
.Sp
Attempting to set \f(CW\*(C`AutoCommit\*(C'\fR to an unsupported value is a fatal error.
This is an important feature of the \s-1DBI\s0. Applications that need
full transaction behaviour can set \f(CW\*(C`$dbh\->{AutoCommit} = 0\*(C'\fR (or
set \f(CW\*(C`AutoCommit\*(C'\fR to 0 via \*(L"connect\*(R")
without having to check that the value was assigned successfully.
.Sp
For the purposes of this description, we can divide databases into three
categories:
.Sp
.Vb 3
\&  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<'BEGIN WORK'>).
.Ve
.Sp
\&\fB* Databases which don't support transactions at all\fR
.Sp
For these databases, attempting to turn \f(CW\*(C`AutoCommit\*(C'\fR off is a fatal error.
\&\f(CW\*(C`commit\*(C'\fR and \f(CW\*(C`rollback\*(C'\fR both issue warnings about being ineffective while
\&\f(CW\*(C`AutoCommit\*(C'\fR is in effect.
.Sp
\&\fB* Databases in which a transaction is always active\fR
.Sp
These are typically mainstream commercial relational databases with
\&\*(L"\s-1ANSI\s0 standard\*(R" transaction behaviour.
If \f(CW\*(C`AutoCommit\*(C'\fR is off, then changes to the database won't have any
lasting effect unless \*(L"commit\*(R" is called (but see also
\&\*(L"disconnect\*(R"). If \*(L"rollback\*(R" is called then any changes since the
last commit are undone.
.Sp
If \f(CW\*(C`AutoCommit\*(C'\fR is on, then the effect is the same as if the \s-1DBI\s0
called \f(CW\*(C`commit\*(C'\fR automatically after every successful database
operation. So calling \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR explicitly while
\&\f(CW\*(C`AutoCommit\*(C'\fR is on would be ineffective because the changes would
have already been commited.
.Sp
Changing \f(CW\*(C`AutoCommit\*(C'\fR from off to on will trigger a \*(L"commit\*(R".
.Sp
For databases which don't support a specific auto-commit mode, the
driver has to commit each statement automatically using an explicit
\&\f(CW\*(C`COMMIT\*(C'\fR after it completes successfully (and roll it back using an
explicit \f(CW\*(C`ROLLBACK\*(C'\fR 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.
.Sp
\&\fB* Databases in which a transaction must be explicitly started\fR
.Sp
For these databases, the intention is to have them act like databases in
which a transaction is always active (as described above).
.Sp
To do this, the driver will automatically begin an explicit transaction
when \f(CW\*(C`AutoCommit\*(C'\fR is turned off, or after a \*(L"commit\*(R" or
\&\*(L"rollback\*(R" (or when the application issues the next database
operation after one of those events).
.Sp
In this way, the application does not have to treat these databases
as a special case.
.Sp
See \*(L"commit\*(R", \*(L"disconnect\*(R" and \*(L"Transactions\*(R" for other important
notes about transactions.
.ie n .IP """Driver""  (handle)" 4
.el .IP "\f(CWDriver\fR  (handle)" 4
.IX Item "Driver  (handle)"
Holds the handle of the parent driver. The only recommended use for this
is to find the name of the driver using:
.Sp
.Vb 1
\&  $dbh->{Driver}->{Name}
.Ve
.ie n .IP """Name""  (string)" 4
.el .IP "\f(CWName\fR  (string)" 4
.IX Item "Name  (string)"
Holds the \*(L"name\*(R" of the database. Usually (and recommended to be) the
same as the "\f(CW\*(C`dbi:DriverName:...\*(C'\fR\*(L" string used to connect to the database,
but with the leading \*(R"\f(CW\*(C`dbi:DriverName:\*(C'\fR" removed.
.ie n .IP """Statement""  (string, read\-only)" 4
.el .IP "\f(CWStatement\fR  (string, read\-only)" 4
.IX Item "Statement  (string, read-only)"
Returns the statement string passed to the most recent \*(L"prepare\*(R" method
called in this database handle, even if that method failed. This is especially
useful where \f(CW\*(C`RaiseError\*(C'\fR is enabled and the exception handler checks $@
and sees that a 'prepare' method call failed.
.ie n .IP """RowCacheSize""  (integer)" 4
.el .IP "\f(CWRowCacheSize\fR  (integer)" 4
.IX Item "RowCacheSize  (integer)"
A hint to the driver indicating the size of the local row cache that the
application would like the driver to use for future \f(CW\*(C`SELECT\*(C'\fR statements.
If a row cache is not implemented, then setting \f(CW\*(C`RowCacheSize\*(C'\fR is ignored
and getting the value returns \f(CW\*(C`undef\*(C'\fR.
.Sp
Some \f(CW\*(C`RowCacheSize\*(C'\fR values have special meaning, as follows:
.Sp
.Vb 4
\&  0 - Automatically determine a reasonable cache size for each C<SELECT>
\&  1 - Disable the local row cache
\& >1 - Cache this many rows
\& <0 - Cache as many rows that will fit into this much memory for each C<SELECT>.
.Ve
.Sp
Note that large cache sizes may require a very large amount of memory
(\fIcached rows * maximum size of row\fR). Also, a large cache will cause
a longer delay not only for the first fetch, but also whenever the
cache needs refilling.
.Sp
See also the \*(L"RowsInCache\*(R" statement handle attribute.
.ie n .IP """Username""  (string)" 4
.el .IP "\f(CWUsername\fR  (string)" 4
.IX Item "Username  (string)"
Returns the username used to connect to the database.
.SH "DBI STATEMENT HANDLE OBJECTS"
.IX Header "DBI STATEMENT HANDLE OBJECTS"
This section lists the methods and attributes associated with \s-1DBI\s0
statement handles.
.Sh "Statement Handle Methods"
.IX Subsection "Statement Handle Methods"
The \s-1DBI\s0 defines the following methods for use on \s-1DBI\s0 statement handles:
.ie n .IP """bind_param""" 4
.el .IP "\f(CWbind_param\fR" 4
.IX Item "bind_param"
.Vb 3
\&  $sth->bind_param($p_num, $bind_value)
\&  $sth->bind_param($p_num, $bind_value, \e%attr)
\&  $sth->bind_param($p_num, $bind_value, $bind_type)
.Ve
.Sp
The \f(CW\*(C`bind_param\*(C'\fR method takes a copy of \f(CW$bind_value\fR and associates it
(binds it) with a placeholder, identified by \f(CW$p_num\fR, embedded in
the prepared statement. Placeholders are indicated with question
mark character (\f(CW\*(C`?\*(C'\fR). For example:
.Sp
.Vb 5
\&  $dbh->{RaiseError} = 1;        # save having to check each method call
\&  $sth = $dbh->prepare("SELECT name, age FROM people WHERE name LIKE ?");
\&  $sth->bind_param(1, "John%");  # placeholders are numbered from 1
\&  $sth->execute;
\&  DBI::dump_results($sth);
.Ve
.Sp
See \*(L"Placeholders and Bind Values\*(R" for more information.
.Sp
\&\fBData Types for Placeholders\fR
.Sp
The \f(CW\*(C`\e%attr\*(C'\fR parameter can be used to hint at the data type the
placeholder should have. This is rarely needed. Typically, the driver is only
interested in knowing if the placeholder should be bound as a number or a string.
.Sp
.Vb 1
\&  $sth->bind_param(1, $value, { TYPE => SQL_INTEGER });
.Ve
.Sp
As a short-cut for the common case, the data type can be passed
directly, in place of the \f(CW\*(C`\e%attr\*(C'\fR hash reference. This example is
equivalent to the one above:
.Sp
.Vb 1
\&  $sth->bind_param(1, $value, SQL_INTEGER);
.Ve
.Sp
The \f(CW\*(C`TYPE\*(C'\fR 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 \f(CW\*(C`{ ora_type => 97 }\*(C'\fR.
.Sp
The \s-1SQL_INTEGER\s0 and other related constants can be imported using
.Sp
.Vb 1
\&  use DBI qw(:sql_types);
.Ve
.Sp
See \*(L"\s-1DBI\s0 Constants\*(R" for more information.
.Sp
The data type for a placeholder cannot be changed after the first
\&\f(CW\*(C`bind_param\*(C'\fR call. In fact the whole \e%attr parameter is 'sticky'
in the sense that a driver only needs to consider the \e%attr parameter
for the first call, for a given \f(CW$sth\fR and parameter. After that the driver
may ignore the \e%attr parameter for that placeholder.
.Sp
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 except where the \fIbind_param()\fR \s-1TYPE\s0 attribute
specifies a type that implies a particular format. For example, given:
.Sp
.Vb 1
\&  $sth->bind_param(1, $value, SQL_DATETIME);
.Ve
.Sp
the driver should expect \f(CW$value\fR to be in the \s-1ODBC\s0 standard \s-1SQL_DATETIME\s0
format, which is '\s-1YYYY\-MM\-DD\s0 \s-1HH:MM:SS\s0'. Similarly for \s-1SQL_DATE\s0, \s-1SQL_TIME\s0 etc.
.Sp
As an alternative to specifying the data type in the \f(CW\*(C`bind_param\*(C'\fR call,
you can let the driver pass the value as the default type (\f(CW\*(C`VARCHAR\*(C'\fR).
You can then use an \s-1SQL\s0 function to convert the type within the statement.
For example:
.Sp
.Vb 1
\&  INSERT INTO price(code, price) VALUES (?, CONVERT(MONEY,?))
.Ve
.Sp
The \f(CW\*(C`CONVERT\*(C'\fR function used here is just an example. The actual function
and syntax will vary between different databases and is non\-portable.
.Sp
See also \*(L"Placeholders and Bind Values\*(R" for more information.
.ie n .IP """bind_param_inout""" 4
.el .IP "\f(CWbind_param_inout\fR" 4
.IX Item "bind_param_inout"
.Vb 3
\&  $rc = $sth->bind_param_inout($p_num, \e$bind_value, $max_len)  or die $sth->errstr;
\&  $rv = $sth->bind_param_inout($p_num, \e$bind_value, $max_len, \e%attr)     or ...
\&  $rv = $sth->bind_param_inout($p_num, \e$bind_value, $max_len, $bind_type) or ...
.Ve
.Sp
This method acts like \*(L"bind_param\*(R", but also enables values to be
updated by the statement. The statement is typically
a call to a stored procedure. The \f(CW$bind_value\fR must be passed as a
reference to the actual value to be used.
.Sp
Note that unlike \*(L"bind_param\*(R", the \f(CW$bind_value\fR variable is not
copied when \f(CW\*(C`bind_param_inout\*(C'\fR is called. Instead, the value in the
variable is read at the time \*(L"execute\*(R" is called.
.Sp
The additional \f(CW$max_len\fR parameter specifies the minimum amount of
memory to allocate to \f(CW$bind_value\fR 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.
.Sp
Undefined values or \f(CW\*(C`undef\*(C'\fR are used to indicate null values.
See also \*(L"Placeholders and Bind Values\*(R" for more information.
.ie n .IP """bind_param_array""" 4
.el .IP "\f(CWbind_param_array\fR" 4
.IX Item "bind_param_array"
.Vb 3
\&  $rc = $sth->bind_param_array($p_num, $array_ref_or_value)
\&  $rc = $sth->bind_param_array($p_num, $array_ref_or_value, \e%attr)
\&  $rc = $sth->bind_param_array($p_num, $array_ref_or_value, $bind_type)
.Ve
.Sp
The \f(CW\*(C`bind_param_array\*(C'\fR method is used to bind an array of values
to a placeholder embedded in the prepared statement which is to be executed
with \*(L"execute_array\*(R". For example:
.Sp
.Vb 6
\&  $dbh->{RaiseError} = 1;        # save having to check each method call
\&  $sth = $dbh->prepare("INSERT INTO staff (first_name, last_name, dept) VALUES(?, ?, ?)");
\&  $sth->bind_param_array(1, [ 'John', 'Mary', 'Tim' ]);
\&  $sth->bind_param_array(2, [ 'Booth', 'Todd', 'Robinson' ]);
\&  $sth->bind_param_array(3, "SALES"); # scalar will be reused for each row
\&  $sth->execute_array( { ArrayTupleStatus => \emy @tuple_status } );
.Ve
.Sp
The \f(CW%attr\fR ($bind_type) argument is the same as defined for \*(L"bind_param\*(R".
Refer to \*(L"bind_param\*(R" for general details on using placeholders.
.Sp
(Note that \fIbind_param_array()\fR can \fInot\fR be used to expand a
placeholder into a list of values for a statement like \*(L"\s-1SELECT\s0 foo
\&\s-1WHERE\s0 bar \s-1IN\s0 (?)\*(R".  A placeholder can only ever represent one value
per execution.)
.Sp
Scalar values, including \f(CW\*(C`undef\*(C'\fR, may also be bound by
\&\f(CW\*(C`bind_param_array\*(C'\fR. In which case the same value will be used for each
\&\*(L"execute\*(R" call. Driver-specific implementations may behave
differently, e.g., when binding to a stored procedure call, some
databases may permit mixing scalars and arrays as arguments.
.Sp
The default implementation provided by \s-1DBI\s0 (for drivers that have
not implemented array binding) is to iteratively call \*(L"execute\*(R" for
each parameter tuple provided in the bound arrays.  Drivers may
provide more optimized implementations using whatever bulk operation
support the database \s-1API\s0 provides. The default driver behaviour should 
match the default \s-1DBI\s0 behaviour, but always consult your driver
documentation as there may be driver specific issues to consider.
.Sp
Note that the default implementation currently only supports non-data
returning statements (\s-1INSERT\s0, \s-1UPDATE\s0, but not \s-1SELECT\s0). Also,
\&\f(CW\*(C`bind_param_array\*(C'\fR and \*(L"bind_param\*(R" cannot be mixed in the same
statement execution, and \f(CW\*(C`bind_param_array\*(C'\fR must be used with
\&\*(L"execute_array\*(R"; using \f(CW\*(C`bind_param_array\*(C'\fR will have no effect
for \*(L"execute\*(R".
.Sp
The \f(CW\*(C`bind_param_array\*(C'\fR method was added in \s-1DBI\s0 1.22.
.ie n .IP """execute""" 4
.el .IP "\f(CWexecute\fR" 4
.IX Item "execute"
.Vb 2
\&  $rv = $sth->execute                or die $sth->errstr;
\&  $rv = $sth->execute(@bind_values)  or die $sth->errstr;
.Ve
.Sp
Perform whatever processing is necessary to execute the prepared
statement.  An \f(CW\*(C`undef\*(C'\fR is returned if an error occurs.  A successful
\&\f(CW\*(C`execute\*(C'\fR 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 \f(CW\*(C`execute\*(C'\fR (and most other \s-1DBI\s0 methods) for errors
if you're not using \*(L"RaiseError\*(R".
.Sp
For a \fInon\fR\-\f(CW\*(C`SELECT\*(C'\fR statement, \f(CW\*(C`execute\*(C'\fR returns the number of rows
affected, if known. If no rows were affected, then \f(CW\*(C`execute\*(C'\fR returns
"\f(CW0E0\fR", which Perl will treat as 0 but will regard as true. Note that it
is \fInot\fR an error for no rows to be affected by a statement. If the
number of rows affected is not known, then \f(CW\*(C`execute\*(C'\fR returns \-1.
.Sp
For \f(CW\*(C`SELECT\*(C'\fR statements, execute simply \*(L"starts\*(R" the query within the
database engine. Use one of the fetch methods to retrieve the data after
calling \f(CW\*(C`execute\*(C'\fR.  The \f(CW\*(C`execute\*(C'\fR method does \fInot\fR 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.
.Sp
You can tell if the statement was a \f(CW\*(C`SELECT\*(C'\fR statement by checking if
\&\f(CW\*(C`$sth\->{NUM_OF_FIELDS}\*(C'\fR is greater than zero after calling \f(CW\*(C`execute\*(C'\fR.
.Sp
If any arguments are given, then \f(CW\*(C`execute\*(C'\fR will effectively call
\&\*(L"bind_param\*(R" for each value before executing the statement.  Values
bound in this way are usually treated as \f(CW\*(C`SQL_VARCHAR\*(C'\fR types unless
the driver can determine the correct type (which is rare), or unless
\&\f(CW\*(C`bind_param\*(C'\fR (or \f(CW\*(C`bind_param_inout\*(C'\fR) has already been used to
specify the type.
.Sp
If \fIexecute()\fR is called on a statement handle that's still active
($sth\->{Active} is true) then it should effectively call \fIfinish()\fR
to tidy up the previous execution results before starting this new
execution.
.ie n .IP """execute_array""" 4
.el .IP "\f(CWexecute_array\fR" 4
.IX Item "execute_array"
.Vb 2
\&  $tuples = $sth->execute_array(\e%attr) or die $sth->errstr;
\&  $tuples = $sth->execute_array(\e%attr, @bind_values) or die $sth->errstr;
.Ve
.Sp
.Vb 2
\&  ($tuples, $rows) = $sth->execute_array(\e%attr) or die $sth->errstr;
\&  ($tuples, $rows) = $sth->execute_array(\e%attr, @bind_values) or die $sth->errstr;
.Ve
.Sp
Execute the prepared statement once for each parameter tuple
(group of values) provided either in the \f(CW@bind_values\fR, or by prior
calls to \*(L"bind_param_array\*(R", or via a reference passed in \e%attr.
.Sp
When called in scalar context the \fIexecute_array()\fR method returns the
number of tuples executed, or \f(CW\*(C`undef\*(C'\fR if an error occured.  Like
\&\fIexecute()\fR, a successful \fIexecute_array()\fR always returns true regardless
of the number of tuples executed, even if it's zero. If there were any
errors the ArrayTupleStatus array can be used to discover which tuples
failed and with what errors.
.Sp
When called in list context the \fIexecute_array()\fR method returns two scalars;
\&\f(CW$tuples\fR is the same as calling \fIexecute_array()\fR in scalar context and \f(CW$rows\fR is
the sum of the number of rows affected for each tuple, if available or
\&\-1 if the driver cannot determine this.
If you are doing an update operation the returned rows affected may not be what
you expect if, for instance, one or more of the tuples affected the same row
multiple times.  Some drivers may not yet support list context, in which case
\&\f(CW$rows\fR will be undef, or may not be able to provide the number of rows affected
when performing this batch operation, in which case \f(CW$rows\fR will be \-1.
.Sp
Bind values for the tuples to be executed may be supplied row-wise
by an \f(CW\*(C`ArrayTupleFetch\*(C'\fR attribute, or else column-wise in the
\&\f(CW@bind_values\fR argument, or else column-wise by prior calls to
\&\*(L"bind_param_array\*(R".
.Sp
Where column-wise binding is used (via the \f(CW@bind_values\fR argument
or calls to \fIbind_param_array()\fR) the maximum number of elements in
any one of the bound value arrays determines the number of tuples
executed. Placeholders with fewer values in their parameter arrays
are treated as if padded with undef (\s-1NULL\s0) values.
.Sp
If a scalar value is bound, instead of an array reference, it is
treated as a \fIvariable\fR length array with all elements having the
same value. It's does not influence the number of tuples executed,
so if all bound arrays have zero elements then zero tuples will
be executed. If \fIall\fR bound values are scalars then one tuple
will be executed, making \fIexecute_array()\fR act just like \fIexecute()\fR.
.Sp
The \f(CW\*(C`ArrayTupleFetch\*(C'\fR attribute can be used to specify a reference
to a subroutine that will be called to provide the bind values for
each tuple execution. The subroutine should return an reference to
an array which contains the appropriate number of bind values, or
return an undef if there is no more data to execute.
.Sp
As a convienience, the \f(CW\*(C`ArrayTupleFetch\*(C'\fR attribute can also be
used to specify a statement handle. In which case the \fIfetchrow_arrayref()\fR
method will be called on the given statement handle in order to
provide the bind values for each tuple execution.
.Sp
The values specified via \fIbind_param_array()\fR or the \f(CW@bind_values\fR
parameter may be either scalars, or arrayrefs.  If any \f(CW@bind_values\fR
are given, then \f(CW\*(C`execute_array\*(C'\fR will effectively call \*(L"bind_param_array\*(R"
for each value before executing the statement.  Values bound in
this way are usually treated as \f(CW\*(C`SQL_VARCHAR\*(C'\fR types unless the
driver can determine the correct type (which is rare), or unless
\&\f(CW\*(C`bind_param\*(C'\fR, \f(CW\*(C`bind_param_inout\*(C'\fR, \f(CW\*(C`bind_param_array\*(C'\fR, or
\&\f(CW\*(C`bind_param_inout_array\*(C'\fR has already been used to specify the type.
See \*(L"bind_param_array\*(R" for details.
.Sp
The \f(CW\*(C`ArrayTupleStatus\*(C'\fR attribute can be used to specify a
reference to an array which will receive the execute status of each
executed parameter tuple. Note the \f(CW\*(C`ArrayTupleStatus\*(C'\fR attribute was
mandatory until \s-1DBI\s0 1.38.
.Sp
For tuples which are successfully executed, the element at the same
ordinal position in the status array is the resulting rowcount.
If the execution of a tuple causes an error, then the corresponding
status array element will be set to a reference to an array containing
the error code and error string set by the failed execution.
.Sp
If \fBany\fR tuple execution returns an error, \f(CW\*(C`execute_array\*(C'\fR will
return \f(CW\*(C`undef\*(C'\fR. In that case, the application should inspect the
status array to determine which parameter tuples failed.
Some databases may not continue executing tuples beyond the first
failure. In this case the status array will either hold fewer
elements, or the elements beyond the failure will be undef.
.Sp
If all parameter tuples are successfully executed, \f(CW\*(C`execute_array\*(C'\fR
returns the number tuples executed.  If no tuples were executed,
then \fIexecute_array()\fR returns "\f(CW0E0\fR", just like \fIexecute()\fR does,
which Perl will treat as 0 but will regard as true.
.Sp
For example:
.Sp
.Vb 18
\&  $sth = $dbh->prepare("INSERT INTO staff (first_name, last_name) VALUES (?, ?)");
\&  my $tuples = $sth->execute_array(
\&      { ArrayTupleStatus => \emy @tuple_status },
\&      \e@first_names,
\&      \e@last_names,
\&  );
\&  if ($tuples) {
\&      print "Successfully inserted $tuples records\en";
\&  }
\&  else {
\&      for my $tuple (0..@last_names-1) {
\&          my $status = $tuple_status[$tuple];
\&          $status = [0, "Skipped"] unless defined $status;
\&          next unless ref $status;
\&          printf "Failed to insert (%s, %s): %s\en",
\&              $first_names[$tuple], $last_names[$tuple], $status->[1];
\&      }
\&  }
.Ve
.Sp
Support for data returning statements such as \s-1SELECT\s0 is driver-specific
and subject to change. At present, the default implementation
provided by \s-1DBI\s0 only supports non-data returning statements.
.Sp
Transaction semantics when using array binding are driver and
database specific.  If \f(CW\*(C`AutoCommit\*(C'\fR is on, the default \s-1DBI\s0
implementation will cause each parameter tuple to be inidividually
committed (or rolled back in the event of an error). If \f(CW\*(C`AutoCommit\*(C'\fR
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 behaviours 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
behaviour.
.Sp
Note that, in general, performance will usually be better with
\&\f(CW\*(C`AutoCommit\*(C'\fR turned off, and using explicit \f(CW\*(C`commit\*(C'\fR after each
\&\f(CW\*(C`execute_array\*(C'\fR call.
.Sp
The \f(CW\*(C`execute_array\*(C'\fR method was added in \s-1DBI\s0 1.22, and ArrayTupleFetch
was added in 1.36.
.ie n .IP """execute_for_fetch""" 4
.el .IP "\f(CWexecute_for_fetch\fR" 4
.IX Item "execute_for_fetch"
.Vb 2
\&  $tuples = $sth->execute_for_fetch($fetch_tuple_sub);
\&  $tuples = $sth->execute_for_fetch($fetch_tuple_sub, \e@tuple_status);
.Ve
.Sp
.Vb 2
\&  ($tuples, $rows) = $sth->execute_for_fetch($fetch_tuple_sub);
\&  ($tuples, $rows) = $sth->execute_for_fetch($fetch_tuple_sub, \e@tuple_status);
.Ve
.Sp
The \fIexecute_for_fetch()\fR method is used to perform bulk operations
and is most often used via the \fIexecute_array()\fR method, not directly.
.Sp
The fetch subroutine, referenced by \f(CW$fetch_tuple_sub\fR, is expected
to return a reference to an array (known as a 'tuple') or undef.
.Sp
The \fIexecute_for_fetch()\fR method calls \f(CW$fetch_tuple_sub\fR, without any
parameters, until it returns a false value. Each tuple returned is
used to provide bind values for an \f(CW$sth\fR\->execute(@$tuple) call.
.Sp
In scalar context \fIexecute_for_fetch()\fR returns \f(CW\*(C`undef\*(C'\fR if there were any
errors and the number of tuples executed otherwise. Like \fIexecute()\fR and
\&\fIexecute_array()\fR a zero is returned as \*(L"0E0\*(R" so \fIexecute_for_fetch()\fR is
only false on error.  If there were any errors the \f(CW@tuple_status\fR array
can be used to discover which tuples failed and with what errors.
.Sp
When called in list context \fIexecute_for_fetch()\fR returns two scalars;
\&\f(CW$tuples\fR is the same as calling \fIexecute_for_fetch()\fR in scalar context and \f(CW$rows\fR is
the sum of the number of rows affected for each tuple, if available or \-1
if the driver cannot determine this.
If you are doing an update operation the returned rows affected may not be what
you expect if, for instance, one or more of the tuples affected the same row
multiple times.  Some drivers may not yet support list context, in which case
\&\f(CW$rows\fR will be undef, or may not be able to provide the number of rows affected
when performing this batch operation, in which case \f(CW$rows\fR will be \-1.
.Sp
If \e@tuple_status is passed then the execute_for_fetch method uses
it to return status information. The tuple_status array holds one
element per tuple. If the corresponding \fIexecute()\fR did not fail then
the element holds the return value from \fIexecute()\fR, which is typically
a row count. If the \fIexecute()\fR did fail then the element holds a
reference to an array containing ($sth\->err, \f(CW$sth\fR\->errstr, \f(CW$sth\fR\->state).
.Sp
If the driver detects an error that it knows means no further tuples can be
executed then it may return, with an error status, even though \f(CW$fetch_tuple_sub\fR
may still have more tuples to be executed.
.Sp
Although each tuple returned by \f(CW$fetch_tuple_sub\fR is effectively used
to call \f(CW$sth\fR\->execute(@$tuple_array_ref) the exact timing may vary.
Drivers are free to accumulate sets of tuples to pass to the
database server in bulk group operations for more efficient execution.
However, the \f(CW$fetch_tuple_sub\fR is specifically allowed to return
the same array reference each time (which is what \fIfetchrow_arrayref()\fR
usually does).
.Sp
For example:
.Sp
.Vb 2
\&  my $sel = $dbh1->prepare("select foo, bar from table1");
\&  $sel->execute;
.Ve
.Sp
.Vb 2
\&  my $ins = $dbh2->prepare("insert into table2 (foo, bar) values (?,?)");
\&  my $fetch_tuple_sub = sub { $sel->fetchrow_arrayref };
.Ve
.Sp
.Vb 3
\&  my @tuple_status;
\&  $rc = $ins->execute_for_fetch($fetch_tuple_sub, \e@tuple_status);
\&  my @errors = grep { ref $_ } @tuple_status;
.Ve
.Sp
Similarly, if you already have an array containing the data rows
to be processed you'd use a subroutine to shift off and return
each array ref in turn:
.Sp
.Vb 1
\&  $ins->execute_for_fetch( sub { shift @array_of_arrays }, \e@tuple_status);
.Ve
.Sp
The \f(CW\*(C`execute_for_fetch\*(C'\fR method was added in \s-1DBI\s0 1.38.
.ie n .IP """fetchrow_arrayref""" 4
.el .IP "\f(CWfetchrow_arrayref\fR" 4
.IX Item "fetchrow_arrayref"
.Vb 2
\&  $ary_ref = $sth->fetchrow_arrayref;
\&  $ary_ref = $sth->fetch;    # alias
.Ve
.Sp
Fetches the next row of data and returns a reference to an array
holding the field values.  Null fields are returned as \f(CW\*(C`undef\*(C'\fR
values in the array.
This is the fastest way to fetch data, particularly if used with
\&\f(CW\*(C`$sth\->bind_columns\*(C'\fR.
.Sp
If there are no more rows or if an error occurs, then \f(CW\*(C`fetchrow_arrayref\*(C'\fR
returns an \f(CW\*(C`undef\*(C'\fR. You should check \f(CW\*(C`$sth\->err\*(C'\fR afterwards (or use the
\&\f(CW\*(C`RaiseError\*(C'\fR attribute) to discover if the \f(CW\*(C`undef\*(C'\fR returned was due to an
error.
.Sp
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"bind_columns\*(R".
.ie n .IP """fetchrow_array""" 4
.el .IP "\f(CWfetchrow_array\fR" 4
.IX Item "fetchrow_array"
.Vb 1
\& @ary = $sth->fetchrow_array;
.Ve
.Sp
An alternative to \f(CW\*(C`fetchrow_arrayref\*(C'\fR. Fetches the next row of data
and returns it as a list containing the field values.  Null fields
are returned as \f(CW\*(C`undef\*(C'\fR values in the list.
.Sp
If there are no more rows or if an error occurs, then \f(CW\*(C`fetchrow_array\*(C'\fR
returns an empty list. You should check \f(CW\*(C`$sth\->err\*(C'\fR afterwards (or use
the \f(CW\*(C`RaiseError\*(C'\fR attribute) to discover if the empty list returned was
due to an error.
.Sp
If called in a scalar context for a statement handle that has more
than one column, it is undefined whether the driver will return
the value of the first column or the last. So don't do that.
Also, in a scalar context, an \f(CW\*(C`undef\*(C'\fR is returned if there are no
more rows or if an error occurred. That \f(CW\*(C`undef\*(C'\fR can't be distinguished
from an \f(CW\*(C`undef\*(C'\fR returned because the first field value was \s-1NULL\s0.
For these reasons you should exercise some caution if you use
\&\f(CW\*(C`fetchrow_array\*(C'\fR in a scalar context.
.ie n .IP """fetchrow_hashref""" 4
.el .IP "\f(CWfetchrow_hashref\fR" 4
.IX Item "fetchrow_hashref"
.Vb 2
\& $hash_ref = $sth->fetchrow_hashref;
\& $hash_ref = $sth->fetchrow_hashref($name);
.Ve
.Sp
An alternative to \f(CW\*(C`fetchrow_arrayref\*(C'\fR. 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 \f(CW\*(C`undef\*(C'\fR values in the hash.
.Sp
If there are no more rows or if an error occurs, then \f(CW\*(C`fetchrow_hashref\*(C'\fR
returns an \f(CW\*(C`undef\*(C'\fR. You should check \f(CW\*(C`$sth\->err\*(C'\fR afterwards (or use the
\&\f(CW\*(C`RaiseError\*(C'\fR attribute) to discover if the \f(CW\*(C`undef\*(C'\fR returned was due to an
error.
.Sp
The optional \f(CW$name\fR parameter specifies the name of the statement handle
attribute. For historical reasons it defaults to "\f(CW\*(C`NAME\*(C'\fR\*(L", however using either
\&\*(R"\f(CW\*(C`NAME_lc\*(C'\fR\*(L" or \*(R"\f(CW\*(C`NAME_uc\*(C'\fR" is recomended for portability.
.Sp
The keys of the hash are the same names returned by \f(CW\*(C`$sth\->{$name}\*(C'\fR. If
more than one field has the same name, there will only be one entry in
the returned hash for those fields.
.Sp
Because of the extra work \f(CW\*(C`fetchrow_hashref\*(C'\fR and Perl have to perform, it
is not as efficient as \f(CW\*(C`fetchrow_arrayref\*(C'\fR or \f(CW\*(C`fetchrow_array\*(C'\fR.
.Sp
By default a reference to a new hash is returned for each row.
It is likely that a future version of the \s-1DBI\s0 will support an
attribute which will enable the same hash to be reused for each
row. This will give a significant performance boost, but it won't
be enabled by default because of the risk of breaking old code.
.ie n .IP """fetchall_arrayref""" 4
.el .IP "\f(CWfetchall_arrayref\fR" 4
.IX Item "fetchall_arrayref"
.Vb 3
\&  $tbl_ary_ref = $sth->fetchall_arrayref;
\&  $tbl_ary_ref = $sth->fetchall_arrayref( $slice );
\&  $tbl_ary_ref = $sth->fetchall_arrayref( $slice, $max_rows  );
.Ve
.Sp
The \f(CW\*(C`fetchall_arrayref\*(C'\fR 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.
.Sp
If there are no rows to return, \f(CW\*(C`fetchall_arrayref\*(C'\fR returns a reference
to an empty array. If an error occurs, \f(CW\*(C`fetchall_arrayref\*(C'\fR returns the
data fetched thus far, which may be none.  You should check \f(CW\*(C`$sth\->err\*(C'\fR
afterwards (or use the \f(CW\*(C`RaiseError\*(C'\fR attribute) to discover if the data is
complete or was truncated due to an error.
.Sp
If \f(CW$slice\fR is an array reference, \f(CW\*(C`fetchall_arrayref\*(C'\fR uses \*(L"fetchrow_arrayref\*(R"
to fetch each row as an array ref. If the \f(CW$slice\fR 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).
.Sp
With no parameters, or if \f(CW$slice\fR is undefined, \f(CW\*(C`fetchall_arrayref\*(C'\fR
acts as if passed an empty array ref.
.Sp
If \f(CW$slice\fR is a hash reference, \f(CW\*(C`fetchall_arrayref\*(C'\fR uses \*(L"fetchrow_hashref\*(R"
to fetch each row as a hash reference. If the \f(CW$slice\fR hash is empty then
\&\fIfetchrow_hashref()\fR 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"FetchHashKeyName\*(R" attribute.) If the \f(CW$slice\fR 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"FetchHashKeyName\*(R" attribute.
.Sp
For example, to fetch just the first column of every row:
.Sp
.Vb 1
\&  $tbl_ary_ref = $sth->fetchall_arrayref([0]);
.Ve
.Sp
To fetch the second to last and last column of every row:
.Sp
.Vb 1
\&  $tbl_ary_ref = $sth->fetchall_arrayref([-2,-1]);
.Ve
.Sp
To fetch all fields of every row as a hash ref:
.Sp
.Vb 1
\&  $tbl_ary_ref = $sth->fetchall_arrayref({});
.Ve
.Sp
To fetch only the fields called \*(L"foo\*(R" and \*(L"bar\*(R" of every row as a hash ref
(with keys named \*(L"foo\*(R" and \*(L"\s-1BAR\s0\*(R"):
.Sp
.Vb 1
\&  $tbl_ary_ref = $sth->fetchall_arrayref({ foo=>1, BAR=>1 });
.Ve
.Sp
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.
.Sp
If \f(CW$max_rows\fR is defined and greater than or equal to zero then it
is used to limit the number of rows fetched before returning.
\&\fIfetchall_arrayref()\fR can then be called again to fetch more rows.
This is especially useful when you need the better performance of
\&\fIfetchall_arrayref()\fR but don't have enough memory to fetch and return
all the rows in one go. Here's an example:
.Sp
.Vb 6
\&  my $rows = []; # cache for batches of rows
\&  while( my $row = ( shift(@$rows) || # get row from cache, or reload cache:
\&                     shift(@{$rows=$sth->fetchall_arrayref(undef,10_000)||[]}) )
\&  ) {
\&    ...
\&  }
.Ve
.Sp
That can be the fastest way to fetch and process lots of rows using the \s-1DBI\s0,
but it depends on the relative cost of method calls vs memory allocation.
.Sp
A standard \f(CW\*(C`while\*(C'\fR loop with column binding is often faster because
the cost of allocating memory for the batch of rows is greater than
the saving by reducing method calls. It's possible that the \s-1DBI\s0 may
provide a way to reuse the memory of a previous batch in future, which
would then shift the balance back towards \fIfetchall_arrayref()\fR.
.ie n .IP """fetchall_hashref""" 4
.el .IP "\f(CWfetchall_hashref\fR" 4
.IX Item "fetchall_hashref"
.Vb 1
\&  $hash_ref = $sth->fetchall_hashref($key_field);
.Ve
.Sp
The \f(CW\*(C`fetchall_hashref\*(C'\fR 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 containing a key for each distinct value of the \f(CW$key_field\fR column
that was fetched. For each key the corresponding value is a reference to a hash
containing all the selected columns and their values, as returned by \fIfetchrow_hashref()\fR.
.Sp
If there are no rows to return, \f(CW\*(C`fetchall_hashref\*(C'\fR returns a reference
to an empty hash. If an error occurs, \f(CW\*(C`fetchall_hashref\*(C'\fR returns the
data fetched thus far, which may be none.  You should check
\&\f(CW\*(C`$sth\->err\*(C'\fR afterwards (or use the \f(CW\*(C`RaiseError\*(C'\fR attribute) to
discover if the data is complete or was truncated due to an error.
.Sp
The \f(CW$key_field\fR parameter provides the name of the field that holds the
value to be used for the key for the returned hash.  For example:
.Sp
.Vb 5
\&  $dbh->{FetchHashKeyName} = 'NAME_lc';
\&  $sth = $dbh->prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
\&  $sth->execute;
\&  $hash_ref = $sth->fetchall_hashref('id');
\&  print "Name for id 42 is $hash_ref->{42}->{name}\en";
.Ve
.Sp
The \f(CW$key_field\fR parameter can also be specified as an integer column
number (counting from 1).  If \f(CW$key_field\fR doesn't match any column in
the statement, as a name first then as a number, then an error is
returned.
.Sp
For queries returing more than one 'key' column, you can specify
multiple column names by passing \f(CW$key_field\fR as a reference to an
array containing one or more key column names (or index numbers).
For example:
.Sp
.Vb 4
\&  $sth = $dbh->prepare("SELECT foo, bar, baz FROM table");
\&  $sth->execute;
\&  $hash_ref = $sth->fetchall_hashref( [ qw(foo bar) ] );
\&  print "For foo 42 and bar 38, baz is $hash_ref->{42}->{38}->{baz}\en";
.Ve
.Sp
The \fIfetchall_hashref()\fR method is normally used only where the key
fields values for each row are unique.  If multiple rows are returned
with the same values for the key fields then later rows overwrite
earlier ones.
.ie n .IP """finish""" 4
.el .IP "\f(CWfinish\fR" 4
.IX Item "finish"
.Vb 1
\&  $rc  = $sth->finish;
.Ve
.Sp
Indicate that no more data will be fetched from this statement handle
before it is either executed again or destroyed.  The \f(CW\*(C`finish\*(C'\fR method
is rarely needed, and frequently overused, but can sometimes be
helpful in a few very specific situations to allow the server to free
up resources (such as sort buffers).
.Sp
When all the data has been fetched from a \f(CW\*(C`SELECT\*(C'\fR statement, the
driver should automatically call \f(CW\*(C`finish\*(C'\fR for you. So you should
\&\fInot\fR normally need to call it explicitly \fIexcept\fR 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 \f(CW\*(C`selectrow_*\*(C'\fR methods are usually better anyway.
Adding calls to \f(CW\*(C`finish\*(C'\fR after each fetch loop is a common mistake,
don't do it, it can mask genuine problems like uncaught fetch errors.
.Sp
Consider a query like:
.Sp
.Vb 1
\&  SELECT foo FROM table WHERE bar=? ORDER BY foo
.Ve
.Sp
where you want to select just the first (smallest) \*(L"foo\*(R" 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 \f(CW\*(C`finish\*(C'\fR method can be used to tell
the server that the buffer space can be freed.
.Sp
Calling \f(CW\*(C`finish\*(C'\fR resets the \*(L"Active\*(R" attribute for the statement.  It
may also make some statement handle attributes (such as \f(CW\*(C`NAME\*(C'\fR and \f(CW\*(C`TYPE\*(C'\fR)
unavailable if they have not already been accessed (and thus cached).
.Sp
The \f(CW\*(C`finish\*(C'\fR method does not affect the transaction status of the
database connection.  It has nothing to do with transactions. It's mostly an
internal \*(L"housekeeping\*(R" method that is rarely needed.
See also \*(L"disconnect\*(R" and the \*(L"Active\*(R" attribute.
.Sp
The \f(CW\*(C`finish\*(C'\fR method should have been called \f(CW\*(C`discard_pending_rows\*(C'\fR.
.ie n .IP """rows""" 4
.el .IP "\f(CWrows\fR" 4
.IX Item "rows"
.Vb 1
\&  $rv = $sth->rows;
.Ve
.Sp
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.
.Sp
Generally, you can only rely on a row count after a \fInon\fR\-\f(CW\*(C`SELECT\*(C'\fR
\&\f(CW\*(C`execute\*(C'\fR (for some specific operations like \f(CW\*(C`UPDATE\*(C'\fR and \f(CW\*(C`DELETE\*(C'\fR), or
after fetching all the rows of a \f(CW\*(C`SELECT\*(C'\fR statement.
.Sp
For \f(CW\*(C`SELECT\*(C'\fR 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
\&\f(CW\*(C`rows\*(C'\fR method or \f(CW$DBI::rows\fR with \f(CW\*(C`SELECT\*(C'\fR statements is not
recommended.
.Sp
One alternative method to get a row count for a \f(CW\*(C`SELECT\*(C'\fR is to execute a
\&\*(L"\s-1SELECT\s0 \s-1COUNT\s0(*) \s-1FROM\s0 ...\*(R" \s-1SQL\s0 statement with the same \*(L"...\*(R" as your
query and then fetch the row count from that.
.ie n .IP """bind_col""" 4
.el .IP "\f(CWbind_col\fR" 4
.IX Item "bind_col"
.Vb 3
\&  $rc = $sth->bind_col($column_number, \e$var_to_bind);
\&  $rc = $sth->bind_col($column_number, \e$var_to_bind, \e%attr );
\&  $rc = $sth->bind_col($column_number, \e$var_to_bind, $bind_type );
.Ve
.Sp
Binds a Perl variable and/or some attributes to an output column
(field) of a \f(CW\*(C`SELECT\*(C'\fR statement.  Column numbers count up from 1.
You do not need to bind output columns in order to fetch data.
For maximum portability between drivers, \fIbind_col()\fR should be called
after \fIexecute()\fR and not before.
See also \f(CW\*(C`bind_columns\*(C'\fR for an example.
.Sp
The binding is performed at a low level using Perl aliasing.
Whenever a row is fetched from the database \f(CW$var_to_bind\fR appears
to be automatically updated simply because it now refers to the same
memory location as the corresponding column value.  This makes using
bound variables very efficient.
Binding a tied variable doesn't work, currently.
.Sp
The \*(L"bind_param\*(R" method
performs a similar, but opposite, function for input variables.
.Sp
\&\fBData Types for Column Binding\fR
.Sp
The \f(CW\*(C`\e%attr\*(C'\fR parameter can be used to hint at the data type
formatting the column should have. For example, you can use:
.Sp
.Vb 1
\&  $sth->bind_col(1, undef, { TYPE => SQL_DATETIME });
.Ve
.Sp
to specify that you'd like the column (which presumably is some
kind of datetime type) to be returned in the standard format for
\&\s-1SQL_DATETIME\s0, which is '\s-1YYYY\-MM\-DD\s0 \s-1HH:MM:SS\s0', rather than the
native formatting the database would normally use.
.Sp
There's no \f(CW$var_to_bind\fR in that example to emphasize the point
that \fIbind_col()\fR works on the underlying column value and not just
a particular bound variable.
.Sp
As a short-cut for the common case, the data type can be passed
directly, in place of the \f(CW\*(C`\e%attr\*(C'\fR hash reference. This example is
equivalent to the one above:
.Sp
.Vb 1
\&  $sth->bind_col(1, undef, SQL_DATETIME);
.Ve
.Sp
The \f(CW\*(C`TYPE\*(C'\fR 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 \f(CW\*(C`{ ora_type => 97 }\*(C'\fR.
.Sp
The \s-1SQL_DATETIME\s0 and other related constants can be imported using
.Sp
.Vb 1
\&  use DBI qw(:sql_types);
.Ve
.Sp
See \*(L"\s-1DBI\s0 Constants\*(R" for more information.
.Sp
The data type for a bind variable cannot be changed after the first
\&\f(CW\*(C`bind_col\*(C'\fR call. In fact the whole \e%attr parameter is 'sticky'
in the sense that a driver only needs to consider the \e%attr parameter
for the first call for a given \f(CW$sth\fR and column.
.Sp
The \s-1TYPE\s0 attribute for \fIbind_col()\fR was first specified in \s-1DBI\s0 1.41.
.ie n .IP """bind_columns""" 4
.el .IP "\f(CWbind_columns\fR" 4
.IX Item "bind_columns"
.Vb 1
\&  $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
.Ve
.Sp
Calls \*(L"bind_col\*(R" for each column of the \f(CW\*(C`SELECT\*(C'\fR statement.
.Sp
The list of references should have the same number of elements as the number of
columns in the \f(CW\*(C`SELECT\*(C'\fR statement. If it doesn't then \f(CW\*(C`bind_columns\*(C'\fR will
bind the elements given, upto the number of columns, and then return an error.
.Sp
For maximum portability between drivers, \fIbind_columns()\fR should be called
after \fIexecute()\fR and not before.
.Sp
For example:
.Sp
.Vb 4
\&  $dbh->{RaiseError} = 1; # do this, or check every call for errors
\&  $sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region });
\&  $sth->execute;
\&  my ($region, $sales);
.Ve
.Sp
.Vb 2
\&  # Bind Perl variables to columns:
\&  $rv = $sth->bind_columns(\e$region, \e$sales);
.Ve
.Sp
.Vb 2
\&  # you can also use Perl's \e(...) syntax (see perlref docs):
\&  #     $sth->bind_columns(\e($region, $sales));
.Ve
.Sp
.Vb 4
\&  # Column binding is the most efficient way to fetch data
\&  while ($sth->fetch) {
\&      print "$region: $sales\en";
\&  }
.Ve
.Sp
For compatibility with old scripts, the first parameter will be
ignored if it is \f(CW\*(C`undef\*(C'\fR or a hash reference.
.Sp
Here's a more fancy example that binds columns to the values \fIinside\fR
a hash (thanks to H.Merijn Brand):
.Sp
.Vb 6
\&  $sth->execute;
\&  my %row;
\&  $sth->bind_columns( \e( @row{ @{$sth->{NAME_lc} } } ));
\&  while ($sth->fetch) {
\&      print "$row{region}: $row{sales}\en";
\&  }
.Ve
.ie n .IP """dump_results""" 4
.el .IP "\f(CWdump_results\fR" 4
.IX Item "dump_results"
.Vb 1
\&  $rows = $sth->dump_results($maxlen, $lsep, $fsep, $fh);
.Ve
.Sp
Fetches all the rows from \f(CW$sth\fR, calls \f(CW\*(C`DBI::neat_list\*(C'\fR for each row, and
prints the results to \f(CW$fh\fR (defaults to \f(CW\*(C`STDOUT\*(C'\fR) separated by \f(CW$lsep\fR
(default \f(CW"\en"\fR). \f(CW$fsep\fR defaults to \f(CW", "\fR and \f(CW$maxlen\fR defaults to 35.
.Sp
This method is designed as a handy utility for prototyping and
testing queries. Since it uses \*(L"neat_list\*(R" to
format and edit the string for reading by humans, it is not recomended
for data transfer applications.
.Sh "Statement Handle Attributes"
.IX Subsection "Statement Handle Attributes"
This section describes attributes specific to statement handles. Most
of these attributes are read\-only.
.PP
Changes to these statement handle attributes do not affect any other
existing or future statement handles.
.PP
Attempting to set or get the value of an unknown attribute generates a warning,
except for private driver specific attributes (which all have names
starting with a lowercase letter).
.PP
Example:
.PP
.Vb 1
\&  ... = $h->{NUM_OF_FIELDS};    # get/read
.Ve
.PP
Some drivers cannot provide valid values for some or all of these
attributes until after \f(CW\*(C`$sth\->execute\*(C'\fR has been successfully
called. Typically the attribute will be \f(CW\*(C`undef\*(C'\fR in these situations.
.PP
Some attributes, like \s-1NAME\s0, are not appropriate to some types of
statement, like \s-1SELECT\s0. Typically the attribute will be \f(CW\*(C`undef\*(C'\fR
in these situations.
.PP
See also \*(L"finish\*(R" to learn more about the effect it
may have on some attributes.
.ie n .IP """NUM_OF_FIELDS""  (integer, read\-only)" 4
.el .IP "\f(CWNUM_OF_FIELDS\fR  (integer, read\-only)" 4
.IX Item "NUM_OF_FIELDS  (integer, read-only)"
Number of fields (columns) in the data the prepared statement may return.
Statements that don't return rows of data, like \f(CW\*(C`DELETE\*(C'\fR and \f(CW\*(C`CREATE\*(C'\fR
set \f(CW\*(C`NUM_OF_FIELDS\*(C'\fR to 0 (though it may be undef in some drivers).
.ie n .IP """NUM_OF_PARAMS""  (integer, read\-only)" 4
.el .IP "\f(CWNUM_OF_PARAMS\fR  (integer, read\-only)" 4
.IX Item "NUM_OF_PARAMS  (integer, read-only)"
The number of parameters (placeholders) in the prepared statement.
See \s-1SUBSTITUTION\s0 \s-1VARIABLES\s0 below for more details.
.ie n .IP """NAME""  (array\-ref, read\-only)" 4
.el .IP "\f(CWNAME\fR  (array\-ref, read\-only)" 4
.IX Item "NAME  (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"NAME_lc\*(R" or \*(L"NAME_uc\*(R".
.Sp
.Vb 1
\&  print "First column name: $sth->{NAME}->[0]\en";
.Ve
.ie n .IP """NAME_lc""  (array\-ref, read\-only)" 4
.el .IP "\f(CWNAME_lc\fR  (array\-ref, read\-only)" 4
.IX Item "NAME_lc  (array-ref, read-only)"
Like \*(L"\s-1NAME\s0\*(R" but always returns lowercase names.
.ie n .IP """NAME_uc""  (array\-ref, read\-only)" 4
.el .IP "\f(CWNAME_uc\fR  (array\-ref, read\-only)" 4
.IX Item "NAME_uc  (array-ref, read-only)"
Like \*(L"\s-1NAME\s0\*(R" but always returns uppercase names.
.ie n .IP """NAME_hash""  (hash\-ref, read\-only)" 4
.el .IP "\f(CWNAME_hash\fR  (hash\-ref, read\-only)" 4
.IX Item "NAME_hash  (hash-ref, read-only)"
.PD 0
.ie n .IP """NAME_lc_hash""  (hash\-ref, read\-only)" 4
.el .IP "\f(CWNAME_lc_hash\fR  (hash\-ref, read\-only)" 4
.IX Item "NAME_lc_hash  (hash-ref, read-only)"
.ie n .IP """NAME_uc_hash""  (hash\-ref, read\-only)" 4
.el .IP "\f(CWNAME_uc_hash\fR  (hash\-ref, read\-only)" 4
.IX Item "NAME_uc_hash  (hash-ref, read-only)"
.PD
The \f(CW\*(C`NAME_hash\*(C'\fR, \f(CW\*(C`NAME_lc_hash\*(C'\fR, and \f(CW\*(C`NAME_uc_hash\*(C'\fR attributes
return column name information as a reference to a hash.
.Sp
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 \f(CW\*(C`NAME\*(C'\fR,
\&\f(CW\*(C`NAME_lc\*(C'\fR, and \f(CW\*(C`NAME_uc\*(C'\fR attributes respectively (as described above).
.Sp
The value of each hash entry is the perl index number of the
corresponding column (counting from 0). For example:
.Sp
.Vb 4
\&  $sth = $dbh->prepare("select Id, Name from table");
\&  $sth->execute;
\&  @row = $sth->fetchrow_array;
\&  print "Name $row[ $sth->{NAME_lc_hash}{name} ]\en";
.Ve
.ie n .IP """TYPE""  (array\-ref, read\-only)" 4
.el .IP "\f(CWTYPE\fR  (array\-ref, read\-only)" 4
.IX Item "TYPE  (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.
.Sp
The values correspond to the international standards (\s-1ANSI\s0 X3.135
and \s-1ISO/IEC\s0 9075) which, in general terms, means \s-1ODBC\s0. Driver-specific
types that don't exactly match standard types should generally return
the same values as an \s-1ODBC\s0 driver supplied by the makers of the
database. That might include private type numbers in ranges the vendor
has officially registered with the \s-1ISO\s0 working group:
.Sp
.Vb 1
\&  ftp://sqlstandards.org/SC32/SQL_Registry/
.Ve
.Sp
Where there's no vendor-supplied \s-1ODBC\s0 driver to be compatible with,
the \s-1DBI\s0 driver can use type numbers in the range that is now
officially reserved for use by the \s-1DBI:\s0 \-9999 to \-9000.
.Sp
All possible values for \f(CW\*(C`TYPE\*(C'\fR should have at least one entry in the
output of the \f(CW\*(C`type_info_all\*(C'\fR method (see \*(L"type_info_all\*(R").
.ie n .IP """PRECISION""  (array\-ref, read\-only)" 4
.el .IP "\f(CWPRECISION\fR  (array\-ref, read\-only)" 4
.IX Item "PRECISION  (array-ref, read-only)"
Returns a reference to an array of integer values for each column.
.Sp
For numeric columns, the value is the maximum number of digits
(without considering a sign character or decimal point). Note that
the \*(L"display size\*(R" for floating point types (\s-1REAL\s0, \s-1FLOAT\s0, \s-1DOUBLE\s0)
can be up to 7 characters greater than the precision (for the
sign + decimal point + the letter E + a sign + 2 or 3 digits).
.Sp
For any character type column the value is the \s-1OCTET_LENGTH\s0,
in other words the number of bytes, not characters.
.Sp
(More recent standards refer to this as \s-1COLUMN_SIZE\s0 but we stick
with \s-1PRECISION\s0 for backwards compatibility.)
.ie n .IP """SCALE""  (array\-ref, read\-only)" 4
.el .IP "\f(CWSCALE\fR  (array\-ref, read\-only)" 4
.IX Item "SCALE  (array-ref, read-only)"
Returns a reference to an array of integer values for each column.
\&\s-1NULL\s0 (\f(CW\*(C`undef\*(C'\fR) values indicate columns where scale is not applicable.
.ie n .IP """NULLABLE""  (array\-ref, read\-only)" 4
.el .IP "\f(CWNULLABLE\fR  (array\-ref, read\-only)" 4
.IX Item "NULLABLE  (array-ref, read-only)"
Returns a reference to an array indicating the possibility of each
column returning a null.  Possible values are \f(CW0\fR
(or an empty string) = no, \f(CW1\fR = yes, \f(CW2\fR = unknown.
.Sp
.Vb 1
\&  print "First column may return NULL\en" if $sth->{NULLABLE}->[0];
.Ve
.ie n .IP """CursorName""  (string, read\-only)" 4
.el .IP "\f(CWCursorName\fR  (string, read\-only)" 4
.IX Item "CursorName  (string, read-only)"
Returns the name of the cursor associated with the statement handle, if
available. If not available or if the database driver does not support the
\&\f(CW"where current of ..."\fR \s-1SQL\s0 syntax, then it returns \f(CW\*(C`undef\*(C'\fR.
.ie n .IP """Database""  (dbh, read\-only)" 4
.el .IP "\f(CWDatabase\fR  (dbh, read\-only)" 4
.IX Item "Database  (dbh, read-only)"
Returns the parent \f(CW$dbh\fR of the statement handle.
.ie n .IP """ParamValues""  (hash ref, read\-only)" 4
.el .IP "\f(CWParamValues\fR  (hash ref, read\-only)" 4
.IX Item "ParamValues  (hash ref, read-only)"
Returns a reference to a hash containing the values currently bound
to placeholders.  The keys of the hash are the 'names' of the
placeholders, typically integers starting at 1.  Returns undef if
not supported by the driver.
.Sp
See \*(L"ShowErrorStatement\*(R" for an example of how this is used.
.Sp
If the driver supports \f(CW\*(C`ParamValues\*(C'\fR but no values have been bound
yet then the driver should return a hash with placeholders names
in the keys but all the values undef, but some drivers may return
a ref to an empty hash.
.Sp
It is possible that the values in the hash returned by \f(CW\*(C`ParamValues\*(C'\fR
are not \fIexactly\fR the same as those passed to \fIbind_param()\fR or \fIexecute()\fR.
The driver may have slightly modified values in some way based on the
\&\s-1TYPE\s0 the value was bound with. For example a floating point value
bound as an \s-1SQL_INTEGER\s0 type may be returned as an integer.
The values returned by \f(CW\*(C`ParamValues\*(C'\fR can be passed to another
\&\fIbind_param()\fR method with the same \s-1TYPE\s0 and will be seen by the
database as the same value.
.Sp
It is also possible that the keys in the hash returned by \f(CW\*(C`ParamValues\*(C'\fR
are not exactly the same as those implied by the prepared statement.
For example, DBD::Oracle translates '\f(CW\*(C`?\*(C'\fR' placeholders into '\f(CW\*(C`:pN\*(C'\fR'
where N is a sequence number starting at 1.
.Sp
The \f(CW\*(C`ParamValues\*(C'\fR attribute was added in \s-1DBI\s0 1.28.
.ie n .IP """ParamArrays""  (hash ref, read\-only)" 4
.el .IP "\f(CWParamArrays\fR  (hash ref, read\-only)" 4
.IX Item "ParamArrays  (hash ref, read-only)"
Returns a reference to a hash containing the values currently bound to
placeholders with \*(L"execute_array\*(R" or \*(L"bind_param_array\*(R".  The
keys of the hash are the 'names' of the placeholders, typically
integers starting at 1.  Returns undef if not supported by the driver
or no arrays of parameters are bound.
.Sp
Each key value is an array reference containing a list of the bound
parameters for that column.
.Sp
For example:
.Sp
.Vb 8
\&  $sth = $dbh->prepare("INSERT INTO staff (id, name) values (?,?)");
\&  $sth->execute_array({},[1,2], ['fred','dave']);
\&  if ($sth->{ParamArrays}) {
\&      foreach $param (keys %{$sth->{ParamArrays}}) {
\&          printf "Parameters for %s : %s\en", $param,
\&          join(",", @{$sth->{ParamArrays}->{$param}});
\&      }
\&  }
.Ve
.Sp
It is possible that the values in the hash returned by \f(CW\*(C`ParamArrays\*(C'\fR
are not \fIexactly\fR the same as those passed to \*(L"bind_param_array\*(R" or
\&\*(L"execute_array\*(R".  The driver may have slightly modified values in some
way based on the \s-1TYPE\s0 the value was bound with. For example a floating
point value bound as an \s-1SQL_INTEGER\s0 type may be returned as an
integer.
.Sp
It is also possible that the keys in the hash returned by
\&\f(CW\*(C`ParamArrays\*(C'\fR are not exactly the same as those implied by the
prepared statement.  For example, DBD::Oracle translates '\f(CW\*(C`?\*(C'\fR'
placeholders into '\f(CW\*(C`:pN\*(C'\fR' where N is a sequence number starting at 1.
.ie n .IP """ParamTypes""  (hash ref, read\-only)" 4
.el .IP "\f(CWParamTypes\fR  (hash ref, read\-only)" 4
.IX Item "ParamTypes  (hash ref, read-only)"
Returns a reference to a hash containing the type information
currently bound to placeholders.  The keys of the hash are the
\&'names' of the placeholders: either integers starting at 1, or,
for drivers that support named placeholders, the actual parameter
name string. The hash values are hashrefs of type information in
the same form as that provided to the various \fIbind_param()\fR methods
(See \*(L"Data Types for Placeholders\*(R" for the format and values),
plus anything else that was passed as the third argument to \fIbind_param()\fR.
Returns undef if not supported by the driver.
.Sp
If the driver supports \f(CW\*(C`ParamTypes\*(C'\fR, but no values have been bound
yet, then the driver should return a hash with the placeholder name
keys, but all the values undef; however, some drivers may return
a ref to an empty hash, or, alternately, may provide type
information supplied by the database (only a few databases can do that).
.Sp
It is possible that the values in the hash returned by \f(CW\*(C`ParamTypes\*(C'\fR
are not \fIexactly\fR the same as those passed to \fIbind_param()\fR or \fIexecute()\fR.
The driver may have modified the type information in some way based
on the bound values, other hints provided by the \fIprepare()\fR'd
\&\s-1SQL\s0 statement, or alternate type mappings required by the driver or target
database system.
.Sp
It is also possible that the keys in the hash returned by \f(CW\*(C`ParamTypes\*(C'\fR
are not exactly the same as those implied by the prepared statement.
For example, DBD::Oracle translates '\f(CW\*(C`?\*(C'\fR' placeholders into '\f(CW\*(C`:pN\*(C'\fR'
where N is a sequence number starting at 1.
.Sp
The \f(CW\*(C`ParamTypes\*(C'\fR attribute was added in \s-1DBI\s0 1.49. Implementation
is the responsibility of individual drivers; the \s-1DBI\s0 layer default
implementation simply returns undef.
.ie n .IP """Statement""  (string, read\-only)" 4
.el .IP "\f(CWStatement\fR  (string, read\-only)" 4
.IX Item "Statement  (string, read-only)"
Returns the statement string passed to the \*(L"prepare\*(R" method.
.ie n .IP """RowsInCache""  (integer, read\-only)" 4
.el .IP "\f(CWRowsInCache\fR  (integer, read\-only)" 4
.IX Item "RowsInCache  (integer, read-only)"
If the driver supports a local row cache for \f(CW\*(C`SELECT\*(C'\fR statements, then
this attribute holds the number of un-fetched rows in the cache. If the
driver doesn't, then it returns \f(CW\*(C`undef\*(C'\fR. Note that some drivers pre-fetch
rows on execute, whereas others wait till the first fetch.
.Sp
See also the \*(L"RowCacheSize\*(R" database handle attribute.
.SH "OTHER METHODS"
.IX Header "OTHER METHODS"
.ie n .IP """install_method""" 4
.el .IP "\f(CWinstall_method\fR" 4
.IX Item "install_method"
.Vb 1
\&    DBD::Foo::db->install_method($method_name, \e%attr);
.Ve
.Sp
Installs the driver-private method named by \f(CW$method_name\fR into the
\&\s-1DBI\s0 method dispatcher so it can be called directly, avoiding the
need to use the \fIfunc()\fR method.
.Sp
It is called as a static method on the driver class to which the
method belongs. The method name must begin with the corresponding
registered driver-private prefix. For example, for DBD::Oracle
\&\f(CW$method_name\fR must being with '\f(CW\*(C`ora_\*(C'\fR', and for DBD::AnyData it
must begin with '\f(CW\*(C`ad_\*(C'\fR'.
.Sp
The attributes can be used to provide fine control over how the \s-1DBI\s0
dispatcher handles the dispatching of the method. However, at this
point, it's undocumented and very liable to change. (Volunteers to
polish up and document the interface are very welcome to get in
touch via dbi\-dev@perl.org)
.Sp
Methods installed using install_method default to the standard error
handling behaviour for \s-1DBI\s0 methods: clearing err and errstr before
calling the method, and checking for errors to trigger RaiseError
etc. on return. This differs from the default behaviour of \fIfunc()\fR.
.Sp
Note for driver authors: The DBD::Foo::xx\->install_method call won't
work until the class-hierarchy has been setup. Normally the \s-1DBI\s0
looks after that just after the driver is loaded. This means
\&\fIinstall_method()\fR can't be called at the time the driver is loaded
unless the class-hierarchy is set up first. The way to do that is
to call the \fIsetup_driver()\fR method:
.Sp
.Vb 1
\&    DBI->setup_driver('DBD::Foo');
.Ve
.Sp
before using \fIinstall_method()\fR.
.SH "FURTHER INFORMATION"
.IX Header "FURTHER INFORMATION"
.Sh "Catalog Methods"
.IX Subsection "Catalog Methods"
An application can retrieve metadata information from the \s-1DBMS\s0 by issuing
appropriate queries on the views of the Information Schema. Unfortunately,
\&\f(CW\*(C`INFORMATION_SCHEMA\*(C'\fR views are seldom supported by the \s-1DBMS\s0.
Special methods (catalog methods) are available to return result sets
for a small but important portion of that metadata:
.PP
.Vb 5
\&  column_info
\&  foreign_key_info
\&  primary_key_info
\&  table_info
\&  statistics_info
.Ve
.PP
All catalog methods accept arguments in order to restrict the result sets.
Passing \f(CW\*(C`undef\*(C'\fR 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.
.PP
\&\fBNote\fR: \s-1SQL/CLI\s0 and \s-1ODBC\s0 differ in the handling of empty strings. An
empty string will not restrict the result set in \s-1SQL/CLI\s0.
.PP
Most arguments in the catalog methods accept only \fIordinary values\fR, e.g.
the arguments of \f(CW\*(C`primary_key_info()\*(C'\fR.
Such arguments are treated as a literal string, i.e. the case is significant
and quote characters are taken literally.
.PP
Some arguments in the catalog methods accept \fIsearch patterns\fR (strings
containing '_' and/or '%'), e.g. the \f(CW$table\fR argument of \f(CW\*(C`column_info()\*(C'\fR.
Passing '%' is equivalent to leaving the argument \f(CW\*(C`undef\*(C'\fR.
.PP
\&\fBCaveat\fR: The underscore ('_') is valid and often used in \s-1SQL\s0 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
.PP
.Vb 2
\&  $esc = $dbh->get_info( 14 );  # SQL_SEARCH_PATTERN_ESCAPE
\&  $search_pattern =~ s/([_%])/$esc$1/g;
.Ve
.PP
The \s-1ODBC\s0 and \s-1SQL/CLI\s0 specifications define a way to change the default
behaviour described above: All arguments (except \fIlist value arguments\fR)
are treated as \fIidentifier\fR if the \f(CW\*(C`SQL_ATTR_METADATA_ID\*(C'\fR attribute is
set to \f(CW\*(C`SQL_TRUE\*(C'\fR.
\&\fIQuoted identifiers\fR are very similar to \fIordinary values\fR, i.e. their
body (the string within the quotes) is interpreted literally.
\&\fIUnquoted identifiers\fR are compared in \s-1UPPERCASE\s0.
.PP
The \s-1DBI\s0 (currently) does not support the \f(CW\*(C`SQL_ATTR_METADATA_ID\*(C'\fR attribute,
i.e. it behaves like an \s-1ODBC\s0 driver where \f(CW\*(C`SQL_ATTR_METADATA_ID\*(C'\fR is set to
\&\f(CW\*(C`SQL_FALSE\*(C'\fR.
.Sh "Transactions"
.IX Subsection "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.
.PP
This section applies to databases that support transactions and where
\&\f(CW\*(C`AutoCommit\*(C'\fR is off.  See \*(L"AutoCommit\*(R" for details of using \f(CW\*(C`AutoCommit\*(C'\fR
with various types of databases.
.PP
The recommended way to implement robust transactions in Perl
applications is to use \f(CW\*(C`RaiseError\*(C'\fR and \f(CW\*(C`eval\ {\ ...\ }\*(C'\fR
(which is very fast, unlike \f(CW\*(C`eval\ "..."\*(C'\fR). For example:
.PP
.Vb 15
\&  $dbh->{AutoCommit} = 0;  # enable transactions, if possible
\&  $dbh->{RaiseError} = 1;
\&  eval {
\&      foo(...)        # do lots of work here
\&      bar(...)        # including inserts
\&      baz(...)        # and updates
\&      $dbh->commit;   # commit the changes if we get this far
\&  };
\&  if ($@) {
\&      warn "Transaction aborted because $@";
\&      # now rollback to undo the incomplete changes
\&      # but do it in an eval{} as it may also fail
\&      eval { $dbh->rollback };
\&      # add other application on-error-clean-up code here
\&  }
.Ve
.PP
If the \f(CW\*(C`RaiseError\*(C'\fR attribute is not set, then \s-1DBI\s0 calls would need to be
manually checked for errors, typically like this:
.PP
.Vb 1
\&  $h->method(@args) or die $h->errstr;
.Ve
.PP
With \f(CW\*(C`RaiseError\*(C'\fR set, the \s-1DBI\s0 will automatically \f(CW\*(C`die\*(C'\fR if any \s-1DBI\s0 method
call on that handle (or a child handle) fails, so you don't have to
test the return value of each method call. See \*(L"RaiseError\*(R" for more
details.
.PP
A major advantage of the \f(CW\*(C`eval\*(C'\fR approach is that the transaction will be
properly rolled back if \fIany\fR code (not just \s-1DBI\s0 calls) in the inner
application dies for any reason. The major advantage of using the
\&\f(CW\*(C`$h\->{RaiseError}\*(C'\fR attribute is that all \s-1DBI\s0 calls will be checked
automatically. Both techniques are strongly recommended.
.PP
After calling \f(CW\*(C`commit\*(C'\fR or \f(CW\*(C`rollback\*(C'\fR many drivers will not let you
fetch from a previously active \f(CW\*(C`SELECT\*(C'\fR 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 \f(CW\*(C`SELECT\*(C'\fR statements.
.PP
See \*(L"AutoCommit\*(R" and \*(L"disconnect\*(R" for other important information
about transactions.
.Sh "Handling \s-1BLOB\s0 / \s-1LONG\s0 / Memo Fields"
.IX Subsection "Handling BLOB / LONG / Memo Fields"
Many databases support \*(L"blob\*(R" (binary large objects), \*(L"long\*(R", 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.
.PP
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 \f(CW\*(C`SELECT\*(C'\fR statement (unlike other data
types), some special handling is required.
.PP
In this situation, the value of the \f(CW\*(C`$h\->{LongReadLen}\*(C'\fR
attribute is used to determine how much buffer space to allocate
when fetching such fields.  The \f(CW\*(C`$h\->{LongTruncOk}\*(C'\fR attribute
is used to determine how to behave if a fetched value can't fit
into the buffer.
.PP
See the description of \*(L"LongReadLen\*(R" for more information.
.PP
When trying to insert long or binary values, placeholders should be used
since there are often limits on the maximum size of an \f(CW\*(C`INSERT\*(C'\fR
statement and the \*(L"quote\*(R" method generally can't cope with binary
data.  See \*(L"Placeholders and Bind Values\*(R".
.Sh "Simple Examples"
.IX Subsection "Simple Examples"
Here's a complete example program to select and fetch some data:
.PP
.Vb 3
\&  my $data_source = "dbi::DriverName:db_name";
\&  my $dbh = DBI->connect($data_source, $user, $password)
\&      or die "Can't connect to $data_source: $DBI::errstr";
.Ve
.PP
.Vb 4
\&  my $sth = $dbh->prepare( q{
\&          SELECT name, phone
\&          FROM mytelbook
\&  }) or die "Can't prepare statement: $DBI::errstr";
.Ve
.PP
.Vb 2
\&  my $rc = $sth->execute
\&      or die "Can't execute statement: $DBI::errstr";
.Ve
.PP
.Vb 2
\&  print "Query will return $sth->{NUM_OF_FIELDS} fields.\en\en";
\&  print "Field names: @{ $sth->{NAME} }\en";
.Ve
.PP
.Vb 5
\&  while (($name, $phone) = $sth->fetchrow_array) {
\&      print "$name: $phone\en";
\&  }
\&  # check for problems which may have terminated the fetch early
\&  die $sth->errstr if $sth->err;
.Ve
.PP
.Vb 1
\&  $dbh->disconnect;
.Ve
.PP
Here's a complete example program to insert some data from a file.
(This example uses \f(CW\*(C`RaiseError\*(C'\fR to avoid needing to check each call).
.PP
.Vb 3
\&  my $dbh = DBI->connect("dbi:DriverName:db_name", $user, $password, {
\&      RaiseError => 1, AutoCommit => 0
\&  });
.Ve
.PP
.Vb 3
\&  my $sth = $dbh->prepare( q{
\&      INSERT INTO table (name, phone) VALUES (?, ?)
\&  });
.Ve
.PP
.Vb 7
\&  open FH, "<phone.csv" or die "Unable to open phone.csv: $!";
\&  while (<FH>) {
\&      chomp;
\&      my ($name, $phone) = split /,/;
\&      $sth->execute($name, $phone);
\&  }
\&  close FH;
.Ve
.PP
.Vb 2
\&  $dbh->commit;
\&  $dbh->disconnect;
.Ve
.PP
Here's how to convert fetched NULLs (undefined values) into empty strings:
.PP
.Vb 5
\&  while($row = $sth->fetchrow_arrayref) {
\&    # this is a fast and simple way to deal with nulls:
\&    foreach (@$row) { $_ = '' unless defined }
\&    print "@$row\en";
\&  }
.Ve
.PP
The \f(CW\*(C`q{...}\*(C'\fR style quoting used in these examples avoids clashing with
quotes that may be used in the \s-1SQL\s0 statement. Use the double-quote like
\&\f(CW\*(C`qq{...}\*(C'\fR operator if you want to interpolate variables into the string.
See \*(L"Quote and Quote-like Operators\*(R" in perlop for more details.
.Sh "Threads and Thread Safety"
.IX Subsection "Threads and Thread Safety"
Perl 5.7 and later support a new threading model called iThreads.
(The old \*(L"5.005 style\*(R" threads are not supported by the \s-1DBI\s0.)
.PP
In the iThreads model each thread has it's own copy of the perl
interpreter.  When a new thread is created the original perl
interpreter is 'cloned' to create a new copy for the new thread.
.PP
If the \s-1DBI\s0 and drivers are loaded and handles created before the
thread is created then it will get a cloned copy of the \s-1DBI\s0, the
drivers and the handles.
.PP
However, the internal pointer data within the handles will refer
to the \s-1DBI\s0 and drivers in the original interpreter. Using those
handles in the new interpreter thread is not safe, so the \s-1DBI\s0 detects
this and croaks on any method call using handles that don't belong
to the current thread (except for \s-1DESTROY\s0).
.PP
Because of this (possibly temporary) restriction, newly created
threads must make their own connctions to the database. Handles
can't be shared across threads.
.PP
But \s-1BEWARE\s0, some underlying database APIs (the code the \s-1DBD\s0 driver
uses to talk to the database, often supplied by the database vendor)
are not thread safe. If it's not thread safe, then allowing more
than one thread to enter the code at the same time may cause
subtle/serious problems. In some cases allowing more than
one thread to enter the code, even if \fInot\fR at the same time,
can cause problems. You have been warned.
.PP
Using \s-1DBI\s0 with perl threads is not yet recommended for production
environments. For more information see
<http://www.perlmonks.org/index.pl?node_id=288022>
.PP
Note: There is a bug in perl 5.8.2 when configured with threads
and debugging enabled (bug #24463) which causes a \s-1DBI\s0 test to fail.
.Sh "Signal Handling and Canceling Operations"
.IX Subsection "Signal Handling and Canceling Operations"
[The following only applies to systems with unix-like signal handling.
I'd welcome additions for other systems, especially Windows.]
.PP
The first thing to say is that signal handling in Perl versions less
than 5.8 is \fInot\fR safe. There is always a small risk of Perl
crashing and/or core dumping when, or after, handling a signal
because the signal could arrive and be handled while internal data
structures are being changed. If the signal handling code
used those same internal data structures it could cause all manner
of subtle and not-so-subtle problems.  The risk was reduced with
5.4.4 but was still present in all perls up through 5.8.0.
.PP
Beginning in perl 5.8.0 perl implements 'safe' signal handling if
your system has the \s-1POSIX\s0 \fIsigaction()\fR routine. Now when a signal
is delivered perl just makes a note of it but does \fInot\fR run the
\&\f(CW%SIG\fR handler. The handling is 'defered' until a 'safe' moment.
.PP
Although this change made signal handling safe, it also lead to
a problem with signals being defered for longer than you'd like.
If a signal arrived while executing a system call, such as waiting
for data on a network connection, the signal is noted and then the
system call that was executing returns with an \s-1EINTR\s0 error code
to indicate that it was interrupted. All fine so far.
.PP
The problem comes when the code that made the system call sees the
\&\s-1EINTR\s0 code and decides it's going to call it again. Perl doesn't
do that, but database code sometimes does. If that happens then the
signal handler doesn't get called untill later. Maybe much later.
.PP
Fortunately there are ways around this which we'll discuss below.
Unfortunately they make signals unsafe again.
.PP
The two most common uses of signals in relation to the \s-1DBI\s0 are for
canceling operations when the user types Ctrl-C (interrupt), and for
implementing a timeout using \f(CW\*(C`alarm()\*(C'\fR and \f(CW$SIG{ALRM}\fR. 
.IP "Cancel" 4
.IX Item "Cancel"
The \s-1DBI\s0 provides a \f(CW\*(C`cancel\*(C'\fR method for statement handles. The
\&\f(CW\*(C`cancel\*(C'\fR method should abort the current operation and is designed
to be called from a signal handler.  For example:
.Sp
.Vb 1
\&  $SIG{INT} = sub { $sth->cancel };
.Ve
.Sp
However, few drivers implement this (the \s-1DBI\s0 provides a default
method that just returns \f(CW\*(C`undef\*(C'\fR) and, even if implemented, there
is still a possibility that the statement handle, and even the
parent database handle, will not be usable afterwards.
.Sp
If \f(CW\*(C`cancel\*(C'\fR returns true, then it has successfully
invoked the database engine's own cancel function.  If it returns false,
then \f(CW\*(C`cancel\*(C'\fR failed. If it returns \f(CW\*(C`undef\*(C'\fR, then the database
driver does not have cancel implemented.
.IP "Timeout" 4
.IX Item "Timeout"
The traditional way to implement a timeout is to set \f(CW$SIG{ALRM}\fR
to refer to some code that will be executed when an \s-1ALRM\s0 signal
arrives and then to call alarm($seconds) to schedule an \s-1ALRM\s0 signal
to be delivered \f(CW$seconds\fR in the future. For example:
.Sp
.Vb 8
\&  eval {
\&    local $SIG{ALRM} = sub { die "TIMEOUT\en" };
\&    alarm($seconds);
\&    ... code to execute with timeout here ...
\&    alarm(0);  # cancel alarm (if code ran fast)
\&  };
\&  alarm(0);    # cancel alarm (if eval failed)
\&  if ( $@ eq "TIMEOUT" ) { ... }
.Ve
.Sp
Unfortunately, as described above, this won't always work as expected,
depending on your perl version and the underlying database code.
.Sp
With Oracle for instance (DBD::Oracle), if the system which hosts
the database is down the \s-1DBI\-\s0>\fIconnect()\fR call will hang for several
minutes before returning an error.
.PP
The solution on these systems is to use the \f(CW\*(C`POSIX::sigaction()\*(C'\fR
routine to gain low level access to how the signal handler is installed.
.PP
The code would look something like this (for the DBD-Oracle \fIconnect()\fR):
.PP
.Vb 1
\&   use POSIX ':signal_h';
.Ve
.PP
.Vb 17
\&   my $mask = POSIX::SigSet->new( SIGALRM ); # signals to mask in the handler
\&   my $action = POSIX::SigAction->new( 
\&       sub { die "connect timeout" },        # the handler code ref
\&       $mask,
\&       # not using (perl 5.8.2 and later) 'safe' switch or sa_flags
\&   );
\&   my $oldaction = POSIX::SigAction->new();
\&   sigaction( 'ALRM', $action, $oldaction );
\&   my $dbh;
\&   eval {
\&      alarm(5); # seconds before time out
\&      $dbh = DBI->connect("dbi:Oracle:$dsn" ... );
\&      alarm(0); # cancel alarm (if connect worked fast)
\&   };
\&   alarm(0);    # cancel alarm (if eval failed)
\&   sigaction( 'ALRM', $oldaction );  # restore original signal handler
\&   if ( $@ ) ....
.Ve
.PP
Similar techniques can be used for canceling statement execution.
.PP
Unfortunately, this solution is somewhat messy, and it does \fInot\fR work with 
perl versions less than perl 5.8 where \f(CW\*(C`POSIX::sigaction()\*(C'\fR appears to be broken.  
.PP
For a cleaner implementation that works across perl versions, see Lincoln Baxter's
Sys::SigAction module at <http://search.cpan.org/~lbaxter/Sys\-SigAction/>.
The documentation for Sys::SigAction includes an longer discussion
of this problem, and a DBD::Oracle test script.
.PP
Be sure to read all the signal handling sections of the perlipc manual.
.PP
And finally, two more points to keep firmly in mind. Firstly,
remember that what we've done here is essentially revert to old
style \fIunsafe\fR handling of these signals. So do as little as
possible in the handler.  Ideally just \fIdie()\fR. Secondly, the handles
in use at the time the signal is handled may not be safe to use
afterwards.
.Sh "Subclassing the \s-1DBI\s0"
.IX Subsection "Subclassing the DBI"
\&\s-1DBI\s0 can be subclassed and extended just like any other object
oriented module.  Before we talk about how to do that, it's important
to be clear about the various \s-1DBI\s0 classes and how they work together.
.PP
By default \f(CW\*(C`$dbh = DBI\->connect(...)\*(C'\fR returns a \f(CW$dbh\fR blessed
into the \f(CW\*(C`DBI::db\*(C'\fR class.  And the \f(CW\*(C`$dbh\->prepare\*(C'\fR method
returns an \f(CW$sth\fR blessed into the \f(CW\*(C`DBI::st\*(C'\fR class (actually it
simply changes the last four characters of the calling handle class
to be \f(CW\*(C`::st\*(C'\fR).
.PP
The leading '\f(CW\*(C`DBI\*(C'\fR' is known as the 'root class' and the extra
\&'\f(CW\*(C`::db\*(C'\fR' or '\f(CW\*(C`::st\*(C'\fR' are the 'handle type suffixes'. If you want
to subclass the \s-1DBI\s0 you'll need to put your overriding methods into
the appropriate classes.  For example, if you want to use a root class
of \f(CW\*(C`MySubDBI\*(C'\fR and override the \fIdo()\fR, \fIprepare()\fR and \fIexecute()\fR methods,
then your \fIdo()\fR and \fIprepare()\fR methods should be in the \f(CW\*(C`MySubDBI::db\*(C'\fR
class and the \fIexecute()\fR method should be in the \f(CW\*(C`MySubDBI::st\*(C'\fR class.
.PP
To setup the inheritance hierarchy the \f(CW@ISA\fR variable in \f(CW\*(C`MySubDBI::db\*(C'\fR
should include \f(CW\*(C`DBI::db\*(C'\fR and the \f(CW@ISA\fR variable in \f(CW\*(C`MySubDBI::st\*(C'\fR
should include \f(CW\*(C`DBI::st\*(C'\fR.  The \f(CW\*(C`MySubDBI\*(C'\fR root class itself isn't
currently used for anything visible and so, apart from setting \f(CW@ISA\fR
to include \f(CW\*(C`DBI\*(C'\fR, it can be left empty.
.PP
So, having put your overriding methods into the right classes, and
setup the inheritance hierarchy, how do you get the \s-1DBI\s0 to use them?
You have two choices, either a static method call using the name
of your subclass:
.PP
.Vb 1
\&  $dbh = MySubDBI->connect(...);
.Ve
.PP
or specifying a \f(CW\*(C`RootClass\*(C'\fR attribute:
.PP
.Vb 1
\&  $dbh = DBI->connect(..., { RootClass => 'MySubDBI' });
.Ve
.PP
If both forms are used then the attribute takes precedence.
.PP
The only differences between the two are that using an explicit
RootClass attribute will a) make the \s-1DBI\s0 automatically attempt to load
a module by that name if the class doesn't exist, and b) won't call
your \fIMySubDBI::connect()\fR method, if you have one.
.PP
When subclassing is being used then, after a successful new
connect, the \s-1DBI\-\s0>connect method automatically calls:
.PP
.Vb 1
\&  $dbh->connected($dsn, $user, $pass, \e%attr);
.Ve
.PP
The default method does nothing. The call is made just to simplify
any post-connection setup that your subclass may want to perform.
The parameters are the same as passed to \s-1DBI\-\s0>connect.
If your subclass supplies a connected method, it should be part of the
MySubDBI::db package.
.PP
One more thing to note: you must let the \s-1DBI\s0 do the handle creation.  If you
want to override the \fIconnect()\fR method in your *::dr class then it must still
call SUPER::connect to get a \f(CW$dbh\fR to work with. Similarly, an overridden
\&\fIprepare()\fR method in *::db must still call SUPER::prepare to get a \f(CW$sth\fR.
If you try to create your own handles using \fIbless()\fR then you'll find the \s-1DBI\s0
will reject them with an \*(L"is not a \s-1DBI\s0 handle (has no magic)\*(R" error.
.PP
Here's a brief example of a \s-1DBI\s0 subclass.  A more thorough example
can be found in \fIt/subclass.t\fR in the \s-1DBI\s0 distribution.
.PP
.Vb 1
\&  package MySubDBI;
.Ve
.PP
.Vb 1
\&  use strict;
.Ve
.PP
.Vb 3
\&  use DBI;
\&  use vars qw(@ISA);
\&  @ISA = qw(DBI);
.Ve
.PP
.Vb 3
\&  package MySubDBI::db;
\&  use vars qw(@ISA);
\&  @ISA = qw(DBI::db);
.Ve
.PP
.Vb 7
\&  sub prepare {
\&    my ($dbh, @args) = @_;
\&    my $sth = $dbh->SUPER::prepare(@args)
\&        or return;
\&    $sth->{private_mysubdbi_info} = { foo => 'bar' };
\&    return $sth;
\&  }
.Ve
.PP
.Vb 3
\&  package MySubDBI::st;
\&  use vars qw(@ISA);
\&  @ISA = qw(DBI::st);
.Ve
.PP
.Vb 8
\&  sub fetch {
\&    my ($sth, @args) = @_;
\&    my $row = $sth->SUPER::fetch(@args)
\&        or return;
\&    do_something_magical_with_row_data($row)
\&        or return $sth->set_err(1234, "The magic failed", undef, "fetch");
\&    return $row;
\&  }
.Ve
.PP
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 like
the error \*(L"dbih_getcom handle \s-1HASH\s0(0xa4451a8) is not a \s-1DBI\s0 handle (has
no magic\*(R".  It's best to check right after the call and return undef
immediately on error, just like \s-1DBI\s0 would and just like the example
above.
.PP
If your method needs to record an error it should call the \fIset_err()\fR
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 \f(CW\*(C`$h\->err\*(C'\fR and \f(CW$DBI::errstr\fR etc.
The \fIset_err()\fR 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 \fIset_err()\fR returns, as shown in the example above.
.PP
If the handle has \f(CW\*(C`RaiseError\*(C'\fR, \f(CW\*(C`PrintError\*(C'\fR, or \f(CW\*(C`HandleError\*(C'\fR
etc. set then the \fIset_err()\fR method will honour them. This means
that if \f(CW\*(C`RaiseError\*(C'\fR is set then \fIset_err()\fR won't return in the
normal way but will 'throw an exception' that can be caught with
an \f(CW\*(C`eval\*(C'\fR block.
.PP
You can stash private data into \s-1DBI\s0 handles
via \f(CW\*(C`$h\->{private_..._*}\*(C'\fR.  See the entry under \*(L"\s-1ATTRIBUTES\s0 \s-1COMMON\s0 \s-1TO\s0 \s-1ALL\s0 \s-1HANDLES\s0\*(R" for info and important caveats.
.SH "TRACING"
.IX Header "TRACING"
The \s-1DBI\s0 has a powerful tracing mechanism built in. It enables you
to see what's going on 'behind the scenes', both within the \s-1DBI\s0 and
the drivers you're using.
.Sh "Trace Settings"
.IX Subsection "Trace Settings"
Which details are written to the trace output is controlled by a
combination of a \fItrace level\fR, an integer from 0 to 15, and a set
of \fItrace flags\fR that are either on or off. Together these are known
as the \fItrace settings\fR and are stored together in a single integer.
For normal use you only need to set the trace level, and generally
only to a value between 1 and 4.
.PP
Each handle has it's own trace settings, and so does the \s-1DBI\s0.
When you call a method the \s-1DBI\s0 merges the handles settings into its
own for the duration of the call: the trace flags of the handle are
\&\s-1OR\s0'd into the trace flags of the \s-1DBI\s0, and if the handle has a higher
trace level then the \s-1DBI\s0 trace level is raised to match it.
The previous \s-1DBI\s0 trace setings are restored when the called method
returns.
.Sh "Trace Levels"
.IX Subsection "Trace Levels"
Trace \fIlevels\fR are as follows:
.PP
.Vb 7
\&  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.
\&  5 to 15 - As above but with more and more obscure information.
.Ve
.PP
Trace level 1 is best for a simple overview of what's happening.
Trace level 2 is a good choice for general purpose tracing.
Levels 3 and above are best reserved for investigating a specific
problem, when you need to see \*(L"inside\*(R" the driver and \s-1DBI\s0.
.PP
The trace output is detailed and typically very useful. Much of the
trace output is formatted using the \*(L"neat\*(R" function, so strings
in the trace output may be edited and truncated by that function.
.Sh "Trace Flags"
.IX Subsection "Trace Flags"
Trace \fIflags\fR are used to enable tracing of specific activities
within the \s-1DBI\s0 and drivers. The \s-1DBI\s0 defines some trace flags and
drivers can define others. \s-1DBI\s0 trace flag names begin with a capital
letter and driver specific names begin with a lowercase letter, as
usual.
.PP
Curently the \s-1DBI\s0 only defines two trace flags:
.PP
.Vb 2
\&  ALL - turn on all DBI and driver flags (not recommended)
\&  SQL - trace SQL statements executed (not yet implemented)
.Ve
.PP
The \*(L"parse_trace_flags\*(R" and \*(L"parse_trace_flag\*(R" methods are used
to convert trace flag names into the coresponding integer bit flags.
.Sh "Enabling Trace"
.IX Subsection "Enabling Trace"
The \f(CW\*(C`$h\->trace\*(C'\fR method sets the trace settings for a handle
and \f(CW\*(C`DBI\->trace\*(C'\fR does the same for the \s-1DBI\s0.
.PP
In addition to the \*(L"trace\*(R" method, you can enable the same trace
information, and direct the output to a file, by setting the
\&\f(CW\*(C`DBI_TRACE\*(C'\fR environment variable before starting Perl.
See \*(L"\s-1DBI_TRACE\s0\*(R" for more information.
.PP
Finally, you can set, or get, the trace settings for a handle using
the \f(CW\*(C`TraceLevel\*(C'\fR attribute.
.PP
All of those methods use \fIparse_trace_flags()\fR and so allow you set
both the trace level and multiple trace flags by using a string
containing the trace level and/or flag names separated by vertical
bar ("\f(CW\*(C`|\*(C'\fR\*(L") or comma (\*(R"\f(CW\*(C`,\*(C'\fR") characters. For example:
.PP
.Vb 1
\&  local $h->{TraceLevel} = "3|SQL|foo";
.Ve
.Sh "Trace Output"
.IX Subsection "Trace Output"
Initially trace output is written to \f(CW\*(C`STDERR\*(C'\fR.  Both the
\&\f(CW\*(C`$h\->trace\*(C'\fR and \f(CW\*(C`DBI\->trace\*(C'\fR methods take an optional
\&\f(CW$trace_filename\fR parameter. If specified, and can be opened in
append mode, then \fIall\fR trace output (currently including that
from other handles) is redirected to that file.  A warning is
generated if the file can't be opened.
.PP
Further calls to \fItrace()\fR without a \f(CW$trace_filename\fR do not alter where
the trace output is sent. If \f(CW$trace_filename\fR is undefined, then
trace output is sent to \f(CW\*(C`STDERR\*(C'\fR and the previous trace file is closed.
.PP
Currently \f(CW$trace_filename\fR can't be a filehandle. But meanwhile you
can use the special strings \f(CW"STDERR"\fR and \f(CW"STDOUT"\fR to select
those filehandles.
.Sh "Trace Content"
.IX Subsection "Trace Content"
Many of the values embeded in trace output are formatted using the \fIneat()\fR
utility function. This means they may be quoted, sanitized, and possibly
truncated if longer than \f(CW$DBI::neat_maxlen\fR. See \*(L"neat\*(R" for more details.
.Sh "Tracing Tips"
.IX Subsection "Tracing Tips"
You can add tracing to your own application code using the
\&\*(L"trace_msg\*(R" method.
.PP
It can sometimes be handy to compare trace files from two different
runs of the same script. However using a tool like \f(CW\*(C`diff\*(C'\fR 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:
.PP
.Vb 1
\&  perl -pe 's/\eb0x[\eda-f]{6,}/0xNNNN/gi; s/\eb[\eda-f]{6,}/<long number>/gi'
.Ve
.SH "DBI ENVIRONMENT VARIABLES"
.IX Header "DBI ENVIRONMENT VARIABLES"
The \s-1DBI\s0 module recognizes a number of environment variables, but most of
them should not be used most of the time.
It is better to be explicit about what you are doing to avoid the need
for environment variables, especially in a web serving system where web
servers are stingy about which environment variables are available.
.Sh "\s-1DBI_DSN\s0"
.IX Subsection "DBI_DSN"
The \s-1DBI_DSN\s0 environment variable is used by \s-1DBI\-\s0>connect if you do not
specify a data source when you issue the connect.
It should have a format such as \*(L"dbi:Driver:databasename\*(R".
.Sh "\s-1DBI_DRIVER\s0"
.IX Subsection "DBI_DRIVER"
The \s-1DBI_DRIVER\s0 environment variable is used to fill in the database
driver name in \s-1DBI\-\s0>connect if the data source string starts \*(L"dbi::\*(R"
(thereby omitting the driver).
If \s-1DBI_DSN\s0 omits the driver name, \s-1DBI_DRIVER\s0 can fill the gap.
.Sh "\s-1DBI_AUTOPROXY\s0"
.IX Subsection "DBI_AUTOPROXY"
The \s-1DBI_AUTOPROXY\s0 environment variable takes a string value that starts
\&\*(L"dbi:Proxy:\*(R" and is typically followed by \*(L"hostname=...;port=...\*(R".
It is used to alter the behaviour of \s-1DBI\-\s0>connect.
For full details, see DBI::Proxy documentation.
.Sh "\s-1DBI_USER\s0"
.IX Subsection "DBI_USER"
The \s-1DBI_USER\s0 environment variable takes a string value that is used as
the user name if the \s-1DBI\-\s0>connect call is given undef (as distinct from
an empty string) as the username argument.
Be wary of the security implications of using this.
.Sh "\s-1DBI_PASS\s0"
.IX Subsection "DBI_PASS"
The \s-1DBI_PASS\s0 environment variable takes a string value that is used as
the password if the \s-1DBI\-\s0>connect call is given undef (as distinct from
an empty string) as the password argument.
Be extra wary of the security implications of using this.
.Sh "\s-1DBI_DBNAME\s0 (obsolete)"
.IX Subsection "DBI_DBNAME (obsolete)"
The \s-1DBI_DBNAME\s0 environment variable takes a string value that is used only when the
obsolescent style of \s-1DBI\-\s0>connect (with driver name as fourth parameter) is used, and
when no value is provided for the first (database name) argument.
.Sh "\s-1DBI_TRACE\s0"
.IX Subsection "DBI_TRACE"
The \s-1DBI_TRACE\s0 environment variable specifies the global default
trace settings for the \s-1DBI\s0 at startup. Can also be used to direct
trace output to a file. When the \s-1DBI\s0 is loaded it does:
.PP
.Vb 1
\&  DBI->trace(split /=/, $ENV{DBI_TRACE}, 2) if $ENV{DBI_TRACE};
.Ve
.PP
So if \f(CW\*(C`DBI_TRACE\*(C'\fR contains an "\f(CW\*(C`=\*(C'\fR" character then what follows
it is used as the name of the file to append the trace to.
.PP
output appended to that file. If the name begins with a number
followed by an equal sign (\f(CW\*(C`=\*(C'\fR), 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:
.PP
.Vb 1
\&  DBI_TRACE=1=dbitrace.log perl your_test_script.pl
.Ve
.PP
On Unix-like systems using a Bourne-like shell, you can do this easily
on the command line:
.PP
.Vb 1
\&  DBI_TRACE=2 perl your_test_script.pl
.Ve
.PP
See \*(L"\s-1TRACING\s0\*(R" for more information.
.Sh "\s-1PERL_DBI_DEBUG\s0 (obsolete)"
.IX Subsection "PERL_DBI_DEBUG (obsolete)"
An old variable that should no longer be used; equivalent to \s-1DBI_TRACE\s0.
.Sh "\s-1DBI_PROFILE\s0"
.IX Subsection "DBI_PROFILE"
The \s-1DBI_PROFILE\s0 environment variable can be used to enable profiling
of \s-1DBI\s0 method calls. See DBI::Profile for more information.
.Sh "\s-1DBI_PUREPERL\s0"
.IX Subsection "DBI_PUREPERL"
The \s-1DBI_PUREPERL\s0 environment variable can be used to enable the
use of DBI::PurePerl.  See DBI::PurePerl for more information.
.SH "WARNING AND ERROR MESSAGES"
.IX Header "WARNING AND ERROR MESSAGES"
.Sh "Fatal Errors"
.IX Subsection "Fatal Errors"
.ie n .IP "Can't call method ""prepare"" without a package or object reference" 4
.el .IP "Can't call method ``prepare'' without a package or object reference" 4
.IX Item "Can't call method prepare without a package or object reference"
The \f(CW$dbh\fR handle you're using to call \f(CW\*(C`prepare\*(C'\fR is probably undefined because
the preceding \f(CW\*(C`connect\*(C'\fR failed. You should always check the return status of
\&\s-1DBI\s0 methods, or use the \*(L"RaiseError\*(R" attribute.
.ie n .IP "Can't call method ""execute"" without a package or object reference" 4
.el .IP "Can't call method ``execute'' without a package or object reference" 4
.IX Item "Can't call method execute without a package or object reference"
The \f(CW$sth\fR handle you're using to call \f(CW\*(C`execute\*(C'\fR is probably undefined because
the preceeding \f(CW\*(C`prepare\*(C'\fR failed. You should always check the return status of
\&\s-1DBI\s0 methods, or use the \*(L"RaiseError\*(R" attribute.
.IP "\s-1DBI/DBD\s0 internal version mismatch" 4
.IX Item "DBI/DBD internal version mismatch"
The \s-1DBD\s0 driver module was built with a different version of \s-1DBI\s0 than
the one currently being used.  You should rebuild the \s-1DBD\s0 module under
the current version of \s-1DBI\s0.
.Sp
(Some rare platforms require \*(L"static linking\*(R". On those platforms, there
may be an old \s-1DBI\s0 or \s-1DBD\s0 driver version actually embedded in the Perl
executable being used.)
.IP "\s-1DBD\s0 driver has not implemented the AutoCommit attribute" 4
.IX Item "DBD driver has not implemented the AutoCommit attribute"
The \s-1DBD\s0 driver implementation is incomplete. Consult the author.
.ie n .IP "Can't [sg]et %s\->{%s}: unrecognised attribute" 4
.el .IP "Can't [sg]et \f(CW%s\fR\->{%s}: unrecognised attribute" 4
.IX Item "Can't [sg]et %s->{%s}: unrecognised attribute"
You attempted to set or get an unknown attribute of a handle.  Make
sure you have spelled the attribute name correctly; case is significant
(e.g., \*(L"Autocommit\*(R" is not the same as \*(L"AutoCommit\*(R").
.SH "Pure-Perl DBI"
.IX Header "Pure-Perl DBI"
A pure-perl emulation of the \s-1DBI\s0 is included in the distribution
for people using pure-perl drivers who, for whatever reason, can't
install the compiled \s-1DBI\s0. See DBI::PurePerl.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.Sh "Driver and Database Documentation"
.IX Subsection "Driver and Database Documentation"
Refer to the documentation for the \s-1DBD\s0 driver that you are using.
.PP
Refer to the \s-1SQL\s0 Language Reference Manual for the database engine that you are using.
.Sh "\s-1ODBC\s0 and \s-1SQL/CLI\s0 Standards Reference Information"
.IX Subsection "ODBC and SQL/CLI Standards Reference Information"
More detailed information about the semantics of certain \s-1DBI\s0 methods
that are based on \s-1ODBC\s0 and \s-1SQL/CLI\s0 standards is available on-line
via microsoft.com, for \s-1ODBC\s0, and www.jtc1sc32.org for the \s-1SQL/CLI\s0
standard:
.PP
.Vb 9
\& 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
\& statistics_info   SQLStatistics
.Ve
.PP
For example, for \s-1ODBC\s0 information on SQLColumns you'd visit:
.PP
.Vb 1
\&  http://msdn.microsoft.com/library/en-us/odbc/htm/odbcsqlcolumns.asp
.Ve
.PP
If that \s-1URL\s0 ceases to work then use the \s-1MSDN\s0 search facility at:
.PP
.Vb 1
\&  http://search.microsoft.com/us/dev/
.Ve
.PP
and search for \f(CW\*(C`SQLColumns returns\*(C'\fR using the exact phrase option.
The link you want will probably just be called \f(CW\*(C`SQLColumns\*(C'\fR and will
be part of the Data Access \s-1SDK\s0.
.PP
And for \s-1SQL/CLI\s0 standard information on SQLColumns you'd read page 124 of
the (very large) \s-1SQL/CLI\s0 Working Draft available from:
.PP
.Vb 1
\&  http://jtc1sc32.org/doc/N0701-0750/32N0744T.pdf
.Ve
.Sh "Standards Reference Information"
.IX Subsection "Standards Reference Information"
A hyperlinked, browsable version of the \s-1BNF\s0 syntax for \s-1SQL92\s0 (plus
Oracle 7 \s-1SQL\s0 and \s-1PL/SQL\s0) is available here:
.PP
.Vb 1
\&  http://cui.unige.ch/db-research/Enseignement/analyseinfo/SQL92/BNFindex.html
.Ve
.PP
A \s-1BNF\s0 syntax for \s-1SQL3\s0 is available here:
.PP
.Vb 1
\&  http://www.sqlstandards.org/SC32/WG3/Progression_Documents/Informal_working_drafts/iso-9075-2-1999.bnf
.Ve
.PP
The following links provide further useful information about \s-1SQL\s0.
Some of these are rather dated now but may still be useful.
.PP
.Vb 3
\&  http://www.jcc.com/SQLPages/jccs_sql.htm
\&  http://www.contrib.andrew.cmu.edu/~shadow/sql.html
\&  http://www.altavista.com/query?q=sql+tutorial
.Ve
.Sh "Books and Articles"
.IX Subsection "Books and Articles"
Programming the Perl \s-1DBI\s0, by Alligator Descartes and Tim Bunce.
<http://books.perl.org/book/154>
.PP
Programming Perl 3rd Ed. by Larry Wall, Tom Christiansen & Jon Orwant.
<http://books.perl.org/book/134>
.PP
Learning Perl by Randal Schwartz.
<http://books.perl.org/book/101>
.PP
Details of many other books related to perl can be found at <http://books.perl.org>
.Sh "Perl Modules"
.IX Subsection "Perl Modules"
Index of \s-1DBI\s0 related modules available from \s-1CPAN:\s0
.PP
.Vb 2
\& http://search.cpan.org/search?mode=module&query=DBIx%3A%3A
\& http://search.cpan.org/search?mode=doc&query=DBI
.Ve
.PP
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 \s-1SPOPS\s0 in the latter) see the Perl
Object-Oriented Persistence project pages at:
.PP
.Vb 1
\& http://poop.sourceforge.net
.Ve
.PP
A similar page for Java toolkits can be found at:
.PP
.Vb 1
\& http://c2.com/cgi-bin/wiki?ObjectRelationalToolComparison
.Ve
.Sh "Mailing List"
.IX Subsection "Mailing List"
The \fIdbi-users\fR mailing list is the primary means of communication among
users of the \s-1DBI\s0 and its related modules. For details send email to:
.PP
.Vb 1
\& dbi-users-help@perl.org
.Ve
.PP
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.
.PP
Mailing list archives (of variable quality) are held at:
.PP
.Vb 3
\& http://groups.google.com/groups?group=perl.dbi.users
\& http://www.xray.mpe.mpg.de/mailing-lists/dbi/
\& http://www.mail-archive.com/dbi-users%40perl.org/
.Ve
.Sh "Assorted Related \s-1WWW\s0 Links"
.IX Subsection "Assorted Related WWW Links"
The \s-1DBI\s0 \*(L"Home Page\*(R":
.PP
.Vb 1
\& http://dbi.perl.org/
.Ve
.PP
Other \s-1DBI\s0 related links:
.PP
.Vb 6
\& 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
\& http://gmax.oltrelinux.com/dbirecipes.html
.Ve
.PP
Other database related links:
.PP
.Vb 3
\& http://www.jcc.com/sql_stnd.html
\& http://cuiwww.unige.ch/OSG/info/FreeDB/FreeDB.home.html
\& http://www.connectionstrings.com/
.Ve
.PP
Security, especially the \*(L"\s-1SQL\s0 Injection\*(R" attack:
.PP
.Vb 7
\& http://www.ngssoftware.com/research/papers.html
\& http://www.ngssoftware.com/papers/advanced_sql_injection.pdf
\& http://www.ngssoftware.com/papers/more_advanced_sql_injection.pdf
\& http://www.esecurityplanet.com/trends/article.php/2243461
\& http://www.spidynamics.com/papers/SQLInjectionWhitePaper.pdf
\& http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html
\& http://online.securityfocus.com/infocus/1644
.Ve
.PP
Commercial and Data Warehouse Links
.PP
.Vb 6
\& 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
.Ve
.PP
Recommended Perl Programming Links
.PP
.Vb 1
\& http://language.perl.com/style/
.Ve
.Sh "\s-1FAQ\s0"
.IX Subsection "FAQ"
Please also read the \s-1DBI\s0 \s-1FAQ\s0 which is installed as a \s-1DBI::FAQ\s0 module.
You can use \fIperldoc\fR to read it by executing the \f(CW\*(C`perldoc DBI::FAQ\*(C'\fR command.
.SH "AUTHORS"
.IX Header "AUTHORS"
\&\s-1DBI\s0 by Tim Bunce.  This pod text by Tim Bunce, J. Douglas Dunlop,
Jonathan Leffler and others.  Perl by Larry Wall and the
\&\f(CW\*(C`perl5\-porters\*(C'\fR.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
The \s-1DBI\s0 module is Copyright (c) 1994\-2004 Tim Bunce. Ireland.
All rights reserved.
.PP
You may distribute under the terms of either the \s-1GNU\s0 General Public
License or the Artistic License, as specified in the Perl \s-1README\s0 file.
.SH "SUPPORT / WARRANTY"
.IX Header "SUPPORT / WARRANTY"
The \s-1DBI\s0 is free Open Source software. \s-1IT\s0 \s-1COMES\s0 \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0.
.Sh "Support"
.IX Subsection "Support"
My consulting company, Data Plan Services, offers annual and
multi-annual support contracts for the \s-1DBI\s0. These provide sustained
support for \s-1DBI\s0 development, and sustained value for you in return.
Contact me for details.
.Sh "Sponsor Enhancements"
.IX Subsection "Sponsor Enhancements"
The \s-1DBI\s0 Roadmap is available at <http://search.cpan.org/~timb/DBI/Roadmap.pod>
.PP
If your company would benefit from a specific new \s-1DBI\s0 feature,
please consider sponsoring its development.  Work is performed
rapidly, and usually on a fixed-price payment-on-delivery basis.
Contact me for details.
.PP
Using such targeted financing allows you to contribute to \s-1DBI\s0
development, and rapidly get something specific and valuable in return.
.SH "ACKNOWLEDGEMENTS"
.IX Header "ACKNOWLEDGEMENTS"
I would like to acknowledge the valuable contributions of the many
people I have worked with on the \s-1DBI\s0 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.
.PP
Then, of course, there are the poor souls who have struggled through
untold and undocumented obstacles to actually implement \s-1DBI\s0 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 \s-1DBI\s0 would
not be the practical reality it is today.  I'm also especially grateful
to Alligator Descartes for starting work on the first edition of the
\&\*(L"Programming the Perl \s-1DBI\s0\*(R" book and letting me jump on board.
.PP
The \s-1DBI\s0 and DBD::Oracle were originally developed while I was Technical
Director (\s-1CTO\s0) 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.
.SH "CONTRIBUTING"
.IX Header "CONTRIBUTING"
As you can see above, many people have contributed to the \s-1DBI\s0 and
drivers in many ways over many years.
.PP
If you'd like to help then see <http://dbi.perl.org/contributing>
and <http://search.cpan.org/~timb/DBI/Roadmap.pod>
.PP
If you'd like the \s-1DBI\s0 to do something new or different then a good way
to make that happen is to do it yourself and send me a patch to the
source code that shows the changes. (But read \*(L"Speak before you patch\*(R"
below.)
.Sh "Browsing the source code repository"
.IX Subsection "Browsing the source code repository"
Use http://svn.perl.org/modules/dbi/trunk (basic)
or  http://svn.perl.org/viewcvs/modules/ (more useful)
.Sh "How to create a patch using Subversion"
.IX Subsection "How to create a patch using Subversion"
The \s-1DBI\s0 source code is maintained using Subversion (a replacement
for \s-1CVS\s0, see <http://subversion.tigris.org/>). To access the source
you'll need to install a Subversion client. Then, to get the source
code, do:
.PP
.Vb 1
\&  svn checkout http://svn.perl.org/modules/dbi/trunk
.Ve
.PP
If it prompts for a username and password use your perl.org account
if you have one, else just 'guest' and 'guest'. The source code will
be in a new subdirectory called \f(CW\*(C`trunk\*(C'\fR.
.PP
To keep informed about changes to the source you can send an empty email
to svn\-commit\-modules\-dbi\-subscribe@perl.org after which you'll get an email
with the change log message and diff of each change checked-in to the source.
.PP
After making your changes you can generate a patch file, but before
you do, make sure your source is still upto date using:
.PP
.Vb 1
\&  svn update
.Ve
.PP
If you get any conflicts reported you'll need to fix them first.
Then generate the patch file from within the \f(CW\*(C`trunk\*(C'\fR directory using:
.PP
.Vb 1
\&  svn diff > foo.patch
.Ve
.PP
Read the patch file, as a sanity check, and then email it to dbi\-dev@perl.org.
.Sh "How to create a patch without Subversion"
.IX Subsection "How to create a patch without Subversion"
Unpack a fresh copy of the distribution:
.PP
.Vb 1
\&  tar xfz DBI-1.40.tar.gz
.Ve
.PP
Rename the newly created top level directory:
.PP
.Vb 1
\&  mv DBI-1.40 DBI-1.40.your_foo
.Ve
.PP
Edit the contents of \s-1DBI\-1\s0.40.your_foo/* till it does what you want.
.PP
Test your changes and then remove all temporary files:
.PP
.Vb 1
\&  make test && make distclean
.Ve
.PP
Go back to the directory you originally unpacked the distribution:
.PP
.Vb 1
\&  cd ..
.Ve
.PP
Unpack \fIanother\fR copy of the original distribution you started with:
.PP
.Vb 1
\&  tar xfz DBI-1.40.tar.gz
.Ve
.PP
Then create a patch file by performing a recursive \f(CW\*(C`diff\*(C'\fR on the two
top level directories:
.PP
.Vb 1
\&  diff -r -u DBI-1.40 DBI-1.40.your_foo > DBI-1.40.your_foo.patch
.Ve
.Sh "Speak before you patch"
.IX Subsection "Speak before you patch"
For anything non-trivial or possibly controversial it's a good idea
to discuss (on dbi\-dev@perl.org) the changes you propose before
actually spending time working on them. Otherwise you run the risk
of them being rejected because they don't fit into some larger plans
you may not be aware of.
.SH "TRANSLATIONS"
.IX Header "TRANSLATIONS"
A German translation of this manual (possibly slightly out of date) is
available, thanks to O'Reilly, at:
.PP
.Vb 1
\&  http://www.oreilly.de/catalog/perldbiger/
.Ve
.PP
Some other translations:
.PP
.Vb 2
\& http://cronopio.net/perl/                              - Spanish
\& http://member.nifty.ne.jp/hippo2000/dbimemo.htm        - Japanese
.Ve
.SH "TRAINING"
.IX Header "TRAINING"
References to \s-1DBI\s0 related training resources. No recommendation implied.
.PP
.Vb 2
\&  http://www.treepax.co.uk/
\&  http://www.keller.com/dbweb/
.Ve
.PP
(If you offer professional \s-1DBI\s0 related training services,
please send me your details so I can add them here.)
.SH "FREQUENTLY ASKED QUESTIONS"
.IX Header "FREQUENTLY ASKED QUESTIONS"
See the \s-1DBI\s0 \s-1FAQ\s0 for a more comprehensive list of FAQs. Use the
\&\f(CW\*(C`perldoc DBI::FAQ\*(C'\fR command to read it.
.Sh "Why doesn't my \s-1CGI\s0 script work right?"
.IX Subsection "Why doesn't my CGI script work right?"
Read the information in the references below.  Please do \fInot\fR post
\&\s-1CGI\s0 related questions to the \fIdbi-users\fR mailing list (or to me).
.PP
.Vb 5
\& 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/
.Ve
.Sh "How can I maintain a \s-1WWW\s0 connection to a database?"
.IX Subsection "How can I maintain a WWW connection to a database?"
For information on the Apache httpd server and the \f(CW\*(C`mod_perl\*(C'\fR module see
.PP
.Vb 1
\&  http://perl.apache.org/
.Ve
.SH "OTHER RELATED WORK AND PERL MODULES"
.IX Header "OTHER RELATED WORK AND PERL MODULES"
.IP "Apache::DBI by E.Mergl@bawue.de" 4
.IX Item "Apache::DBI by E.Mergl@bawue.de"
To be used with the Apache daemon together with an embedded Perl
interpreter like \f(CW\*(C`mod_perl\*(C'\fR. Establishes a database connection which
remains open for the lifetime of the \s-1HTTP\s0 daemon. This way the \s-1CGI\s0
connect and disconnect for every database access becomes superfluous.
.IP "\s-1JDBC\s0 Server by Stuart 'Zen' Bishop zen@bf.rmit.edu.au" 4
.IX 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 \s-1JDBC\s0 \s-1API\s0 with any database that has a \s-1DBI\s0 driver installed.
The \s-1URL\s0 used is in the form \f(CW\*(C`jdbc:dbi://host.domain.etc:999/Driver/DBName\*(C'\fR.
It seems to be very similar to some commercial products, such as jdbcKona.
.IP "Remote Proxy \s-1DBD\s0 support" 4
.IX Item "Remote Proxy DBD support"
As of \s-1DBI\s0 1.02, a complete implementation of a DBD::Proxy driver and the
DBI::ProxyServer are part of the \s-1DBI\s0 distribution.
.IP "\s-1SQL\s0 Parser" 4
.IX Item "SQL Parser"
See also the SQL::Statement module, \s-1SQL\s0 parser and engine.

Creat By MiNi SheLL
Email: devilkiller@gmail.com