DBI
view release on metacpan or search on metacpan
lib/DBI/DBD.pm view on Meta::CPAN
sometimes be used if there are no parameters.
=item $h->errstr()
=item $h->err()
=item $h->state()
=item $h->trace()
The B<DBD> driver does not need to worry about these routines at all.
=item $h->{ChopBlanks}
This attribute needs to be honored during C<fetch()> operations, but does
not need to be handled by the attribute handling code.
=item $h->{RaiseError}
The B<DBD> driver does not need to worry about this attribute at all.
=item $h->{PrintError}
The B<DBD> driver does not need to worry about this attribute at all.
=item $sth->bind_col()
Assuming the driver uses the C<DBIc_DBISTATE(imp_xxh)-E<gt>get_fbav()>
function (C drivers, see below), or the C<$sth-E<gt>_set_fbav($data)>
method (Perl drivers) the driver does not need to do anything about this
routine.
=item $sth->bind_columns()
Regardless of whether the driver uses
C<DBIc_DBISTATE(imp_xxh)-E<gt>get_fbav()>, the driver does not need
to do anything about this routine as it simply iteratively calls
C<$sth-E<gt>bind_col()>.
=back
The B<DBI> code implements a default implementation of the following
functions which do not need to be written by the B<DBD> driver writer
unless the default implementation is incorrect for the Driver.
=over 4
=item $dbh->quote()
This should only be written if the database does not accept the ANSI
SQL standard for quoting strings, with the string enclosed in single
quotes and any embedded single quotes replaced by two consecutive
single quotes.
For the two argument form of quote, you need to implement the
C<type_info()> method to provide the information that quote needs.
=item $dbh->ping()
This should be implemented as a simple efficient way to determine
whether the connection to the database is still alive. Typically
code like this:
sub ping {
my $dbh = shift;
$sth = $dbh->prepare_cached(q{
select * from A_TABLE_NAME where 1=0
}) or return 0;
$sth->execute or return 0;
$sth->finish;
return 1;
}
where I<A_TABLE_NAME> is the name of a table that always exists (such as a
database system catalogue).
=item $drh->default_user
The default implementation of default_user will get the database
username and password fields from C<$ENV{DBI_USER}> and
C<$ENV{DBI_PASS}>. You can override this method. It is called as
follows:
($user, $pass) = $drh->default_user($user, $pass, $attr)
=back
=head1 METADATA METHODS
The exposition above ignores the B<DBI> MetaData methods.
The metadata methods are all associated with a database handle.
=head2 Using DBI::DBD::Metadata
The B<DBI::DBD::Metadata> module is a good semi-automatic way for the
developer of a B<DBD> module to write the C<get_info()> and C<type_info()>
functions quickly and accurately.
=head3 Generating the get_info method
Prior to B<DBI> v1.33, this existed as the method C<write_getinfo_pm()>
in the B<DBI::DBD> module. From B<DBI> v1.33, it exists as the method
C<write_getinfo_pm()> in the B<DBI::DBD::Metadata> module. This
discussion assumes you have B<DBI> v1.33 or later.
You examine the documentation for C<write_getinfo_pm()> using:
perldoc DBI::DBD::Metadata
To use it, you need a Perl B<DBI> driver for your database which implements
the C<get_info()> method. In practice, this means you need to install
B<DBD::ODBC>, an ODBC driver manager, and an ODBC driver for your
database.
With the pre-requisites in place, you might type:
perl -MDBI::DBD::Metadata -we \
"write_getinfo_pm (qw{ dbi:ODBC:foo_db username password Driver })"
The procedure writes to standard output the code that should be added to
your F<Driver.pm> file and the code that should be written to
( run in 0.730 second using v1.01-cache-2.11-cpan-5837b0d9d2c )