Statement Handle Attributes or Statement Metadata
Statement handle attributes are specific to statement handles, and inherit any inheritable attributes from their parent database handle. Many statement handle attributes are defined as being read-only because they simply describe the prepared statement or its results.
In theoretical terms, these attributes should be defined when the
statement handle is prepared, but in practical terms, you should only
rely on the attribute values after the statement handle has been both
prepared and executed. Similarly, with a few
drivers, fetching all the data from a SELECT
statement or explicitly invoking the finish()
method against a statement handle may cause the values of the
statement handle attributes to be no longer available.
The DBI specification in Appendix A provides a complete list of all the statement handle attributes defined within the DBI.
-
Statement
This attribute contains the statement string passed to the
prepare()
method.-
NUM_OF_FIELDS
This attribute is set to contain the number of columns that will be returned by a
SELECT
statement. For example:$sth = $dbh->prepare( " SELECT name, location, mapref FROM megaliths " ); $sth->execute(); print "SQL statement contains $sth->{NUM_OF_FIELDS} columns\n";
Non-
SELECT
statements will contain the attribute value of zero. This allows you to quickly determine whether or not the statement is aSELECT
statement.-
NAME
NAME_uc
NAME_lc
The
NAME
attribute contains the names of the selected ...
Get Programming the Perl DBI now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.