This section lists the attribute keys and values that can be
given in many Perl DBI methods, as indicated in the previous section with
%attri in each method’s syntax. The basic
syntax to set an attribute is
$handle->attribute=>'setting‘.
Attribute key/value pairs are separated by commas and are all contained
within a pair of curly braces. For example, to instruct DBI not to return
error messages for a database handle, you would do the following when it’s
created:
my $dbh = DBI->connect('DBI:mysql:bookstore:localhost',
'paola','caporalle1017', {RaiseError=>0});To retrieve a setting, use
$handle->{attribute}. This can be stored to
a variable or printed:
print "dbh->{RaiseError=>" . $dbh->{RaiseError} . "}";If you try this simple line of code, keep in mind that an attribute set to 0 will return an empty value.
You can use the following attributes with both database handles and statement handles:
Active (boolean, read-only)This attribute indicates that the handle is active. In the
case of a database handle, it indicates that the connection is
open. The disconnect() method sets this
attribute to 0 in a database handle;
finish() sets it to 0 in a statement
handle.
ActiveKids (integer, read-only)This attribute provides the number of active handles under the handle that employed the attribute. If called by a driver handle, the number of database handles will be returned. If called by a database handle, the number of active statement handles will be returned.
CacheKids (hash ref)This attribute returns a reference to a hash containing
child handles for a driver or for a database handle that was
created by the connect_cached() or
prepare_cached()
methods, respectively.
ChildHandles (array ref)This attribute returns a reference to an array to all accessible handles created by the handle that called this method. These are weak references and the referenced arrays may not be dependably available.
ChopBlanks (boolean, inherited)This attribute trims trailing spaces from fixed-width
character fields (i.e., CHAR fields of results
sets).
CompatMode (boolean, inherited)This attribute makes emulation layers compatible with a driver handle. It is not normally used in applications.
ErrCount (unsigned integer)This attribute keeps a count of the number of errors logged
by set_err().
Executed (boolean)This attribute determines whether a handle or one of its children has been executed.
FetchHashKeyName (string, inherited)This attribute instructs
fetchrow_hashref() calls to convert
column names to either all lowercase (NAME_lc)
or all uppercase (NAME_uc) letters. The default
is NAME, which indicates no conversion should
be performed.
HandleError (code ref, inherited)This attribute customizes the response to an error caused by the handle. You could use this attribute to run a subroutine in the event of an error:
$dbh->{HandleError=> \&my_sub_routine });HandleSetErr (code ref, inherited)This attribute customizes the settings for
err, errstr, and
state values of an error caused by the handle.
It’s similar to the HandleError attribute, but
it relates to set_err().
InactiveDestroy (boolean)This attribute prevents the server from destroying a handle
that is out of scope, unless it is closed intentionally with a
function such as finish() or disconnect().
Kids (integer, read-only)This attribute provides the number of all handles (active and inactive) under the handle that employed the attribute. If it’s called by a database handle, the number of statement handles will be returned. If it’s called by a driver handle, the number of database handles will be returned.
LongReadLen (unsigned integer,
inherited)This attribute sets the maximum length of data retrieved
from long data type columns (i.e., BLOB and
TEXT).
LongTruncOK (boolean, inherited)If this attribute is set to true, it may prevent a fetch
method from failing if a column’s data length exceeds the maximum
length set by the LongReadLen attribute.
PrintError (boolean, inherited)If this attribute is set to 1, error codes and error messages associated with the handle will be logged. If it’s set to 0, they won’t be logged.
PrintWarn (boolean, inherited)Setting this attribute to 1 will instruct DBI to log warning messages for the handle. Setting it to 0 will instruct it not to log them.
private_*This attribute stores information on the handle as a private
attribute with a customized name starting with
private_.
Profile (inherited)This attribute enables the logging of method call timing statistics.
RaiseError (boolean, inherited)This attribute instructs DBI to raises exceptions when
errors are associated with the handle. By default it’s set to 0.
If set to 1, any DBI error will cause the program to die. If you
set this attribute to true, you should also set PrintError to true.
ReadOnly (boolean, inherited)Setting this attribute on a handle to true indicates that all actions with the handle afterward will be read-only activities—data won’t be changed using the handle.
ShowErrorStatement (boolean,
inherited)If set to true, this attribute specifies that the SQL
statement text of a statement handle should be appended to error
messages stemming from the PrintError,
PrintWarn, and RaiseError
attributes being set to true.
Taint (boolean, inherited)This attribute combines TaintIn and
TaintOut attributes. Whatever value you set
with this attribute will be set for the other two
attributes.
TaintIn (boolean, inherited)This attribute instructs DBI to check whether method calls are tainted, when Perl is running in taint mode.
TaintOut (boolean, inherited)This attribute instructs DBI to assume that data fetched is tainted, when Perl is running in taint mode.
TraceLevel (integer, inherited)This attribute sets trace levels and flags for a handle.
It’s an alternative to the trace()
method.
Type (scalar, read-only)This attribute is used to determine the type of handle. It
returns dr for a driver handle,
db for a database handle, and
st for a statement handle.
Warn (boolean, inherited)This attribute enables or disables warning messages for poor database procedures.
AutoCommit (boolean)This attribute allows the
rollback() function to be used if the
attribute is set to 0. At the time of this writing, a bug
sometimes produces an error when using this attribute.
Driver (handle)This attribute provides the name of the parent driver:
$dbh->{Driver}->{Name}.
Name (string)This attribute provides the name of the database for the database handle.
RowCacheSize (integer)This attribute is used to suggest a cache size for rows
generated for SELECT statements. If it’s 0, DBI
automatically determines the cache size. A value of 1 disables
local row caching.
Statement (string, read-only)This attribute provides the last SQL statement prepared with the database handle, regardless of whether it succeeded.
Username (string)This attribute provides the name of the user for the database handle.
CursorName (string, read-only)This attribute returns the name of the cursor for the statement handle.
Database (dbh, read-only)This attribute returns the database handle of the statement handle.
NAME (array-ref, read-only)This attribute contains a reference to an array containing the names of the columns of the SQL statement from the statement handle.
NAME_hash (hash-ref, read-only)This attribute returns a reference to a hash containing column name information.
NAME_lc (array-ref, read-only)This attribute returns a reference to an array containing column name information. The keys are the column names in lowercase letters.
NAME_lc_hash (hash-ref, read-only)This attribute returns a reference to a hash containing column name information. The keys are the column names in lowercase letters.
NAME_uc (array-ref, read-only)This attribute returns a reference to an array containing column name information. The keys are the column names in uppercase letters.
NAME_uc_hash (hash-ref, read-only)This attribute returns a reference to a hash containing column name information. The keys are the column names in uppercase letters.
NULLABLE (array-ref, read-only)This attribute returns a reference to an array indicating whether each column in the SQL statement of the handle may contain a NULL value.
NUM_OF_FIELDS (integer, read-only)This attribute returns the number of columns in the SQL statement of the handle.
NUM_OF_PARAMS (integer, read-only)This attribute returns the number of placeholders in the SQL statement of the handle.
ParamArrays (hash ref, read-only)This attribute returns a reference to a hash containing the
names of placeholders as keys and their associated values for
calls made to bind_param_array() and
execute_array().
ParamTypes (hash ref, read-only)This attribute returns a reference to a hash containing
information about placeholders that are bound by calls
made to bind_param(). The placeholder
names are used as the keys of the hash.
ParamValues (hash ref, read-only)This attribute returns a reference to a hash of bound parameters and their values.
RowsInCache (integer, read-only)This attribute returns the number of unfetched rows in the cache if the driver supports row-level caching.
Statement (string, read-only)This attribute is the SQL statement passed to
prepare().
TYPE (array-ref, read-only)This attribute contains a reference to an array of codes for
international standard values for data types (e.g., 1 for
SQL_CHAR, 4 for
SQL_INTEGER).
PRECISION (array-ref, read-only)This attribute contains a reference to an array containing the length of columns (as set in the table definition) in the SQL statement of the handle.
SCALE (array-ref, read-only)This attribute contains a reference to an array containing the number of decimal places for columns in the SQL statement of the handle.