DBI::FAQ (3)
Leading comments
Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) Standard preamble: ========================================================================
NAME
DBI::FAQ -- The Frequently Asked Questions for the Perl5 Database InterfaceSYNOPSIS
perldoc DBI::FAQ
VERSION
This document is currently at version 0.38, as of February 8th, 2000.That's very old. A newer
Neither this document nor that web site are actively maintained. Volunteers are welcome.
DESCRIPTION
This document serves to answer the most frequently asked questions on both theBasic Information & Information Sources
1.1 What is DBI, DBperl, Oraperl and *perl?
To quote Tim Bunce, the architect and author of
DBI is a database access Application Programming Interface (API) for the Perl Language. The DBI API Specification defines a set of functions, variables and conventions that provide a consistent database interface independent of the actual database being used.
In simple language, the
A similar benefit is gained by the ability to connect to two different databases of different vendor within the one perl script, ie, I want to read data from an Oracle database and insert it back into an Informix database all within one program. The
DBperl is the old name for the interface specification. It's usually now used to denote perl4 modules on database interfacing, such as, oraperl, isqlperl, ingperl and so on. These interfaces didn't have a standard
Here's a list of DBperl modules, their corresponding
Module Name Database Required Author DBI ----------- ----------------- ------ --- Sybperl Sybase Michael Peppler DBD::Sybase <mpeppler@itf.ch> Oraperl Oracle 6 & 7 Kevin Stock DBD::Oracle <dbi-users@perl.org> Ingperl Ingres Tim Bunce & DBD::Ingres Ted Lemon <dbi-users@perl.org> Interperl Interbase Buzz Moschetti DBD::Interbase <buzz@bear.com> Uniperl Unify 5.0 Rick Wargo None <rickers@coe.drexel.edu> Pgperl Postgres Igor Metz DBD::Pg <metz@iam.unibe.ch> Btreeperl NDBM John Conover SDBM? <john@johncon.com> Ctreeperl C-Tree John Conover None <john@johncon.com> Cisamperl Informix C-ISAM Mathias Koerber None <mathias@unicorn.swi.com.sg> Duaperl X.500 Directory Eric Douglas None User Agent
However, some
Here's a table of emulation layer information:
Module Emulation Layer Status ------ --------------- ------ DBD::Oracle Oraperl Complete DBD::Informix Isqlperl Under development DBD::Ingres Ingperl Complete? DBD::Sybase Sybperl Working? ( Needs verification ) DBD::mSQL Msqlperl Experimentally released with DBD::mSQL-0.61
The Msqlperl emulation is a special case. Msqlperl is a perl5 driver for mSQL databases, but does not conform to the
www.perl.com/cgi-bin/cpan_mod?module=Msqlperl
1.2. Where can I get it from?
The Comprehensive Perl Archive Network resources should be used for retrieving up-to-date versions of the
www.perl.com/CPAN
For more specific version information and exact URLs of drivers, please see the
dbi.perl.org
This list is automatically generated on a nightly basis from
1.3. Where can I get more information?
There are a few information sources on- Programming the Perl DBI
-
``Programming the Perl DBI''is the official book on theDBIwritten by Alligator Descartes and Tim Bunce and published by O'Reilly & Associates. The book was released on February 9th, 2000.
The table of contents is:
Preface 1. Introduction From Mainframes to Workstations Perl DBI in the Real World A Historical Interlude and Standing Stones 2. Basic Non-DBI Databases Storage Managers and Layers Query Languages and Data Functions Standing Stones and the Sample Database Flat-File Databases Putting Complex Data into Flat Files Concurrent Database Access and Locking DBM Files and the Berkeley Database Manager The MLDBM Module Summary 3. SQL and Relational Databases The Relational Database Methodology Datatypes and NULL Values Querying Data Modifying Data Within Tables Creating and Destroying Tables 4. Programming with the DBI DBI Architecture Handles Data Source Names Connection and Disconnection Error Handling Utility Methods and Functions 5. Interacting with the Database Issuing Simple Queries Executing Non-SELECT Statements Binding Parameters to Statements Binding Output Columns do() Versus prepare() Atomic and Batch Fetching 6. Advanced DBI Handle Attributes and Metadata Handling LONG/LOB Data Transactions, Locking, and Isolation 7. ODBC and the DBI ODBC -- Embraced and Extended DBI -- Thrashed and Mutated The Nuts and Bolts of ODBC ODBC from Perl The Marriage of DBI and ODBC Questions and Choices Moving Between Win32::ODBC and the DBI And What About ADO? 8. DBI Shell and Database Proxying dbish -- The DBI Shell Database Proxying A. DBI Specification B. Driver and Database Characteristics C. ASLaN Sacred Site Charter Index
The book should be available from all good bookshops and can be ordered online either <I>via</I> O'Reilly & Associates
www.oreilly.com/catalog/perldbi
or Amazon
www.amazon.com/exec/obidos/ASIN/1565926994/dbi
- PODdocumentation
-
PODs are chunks of documentation usually embedded within perl programs that document the code ``in place'', providing a useful resource for programmers and users of modules.PODforDBIand drivers is beginning to become more commonplace, and documentation for these modules can be read with the "perldoc" program included with Perl.
-
- The DBISpecification
-
The PODfor theDBISpecification can be read with the:
perldoc DBI
command. The Specification also forms Appendix A of ``Programming the Perl
DBI''. - Oraperl
-
Users of the Oraperl emulation layer bundled with DBD::Oracle, may read
up on how to program with the Oraperl interface by typing:
perldoc Oraperl
This will produce an updated copy of the original oraperl man page written by Kevin Stock for perl4. The oraperl
APIis fully listed and described there. - Drivers
-
Users of the DBDmodules may read about some of the private functions and quirks of that driver by typing:
perldoc <driver>
For example, the DBD::mSQL driver is bundled with driver-specific documentation that can be accessed by typing
perldoc DBD::mSQL
- Frequently Asked Questions
-
This document, the Frequently Asked Questions is also available as PODdocumentation! You can read this on your own system by typing:
perldoc DBI::FAQ
This may be more convenient to persons not permanently, or conveniently, connected to the Internet. The
DBI::FAQmodule should be downloaded and installed for the more up-to-date version.The version of
DBI::FAQshipped with the "DBI" module may be slightly out of date. - PODin general
-
Information on writing POD,and on the philosophy ofPODin general, can be read by typing:
perldoc perlpod
Users with the Tk module installed may be interested to learn there is a Tk-based
PODreader available called "tkpod", which formatsPODin a convenient and readable way. This is available viaCPANas the module called Tk::POD and is highly recommended.
- The
-
- Driver and Database Characteristics
-
The driver summaries that were produced for Appendix B of ``Programming the
Perl DBI''are available online at:
dbi.perl.org
in the driver information table. These summaries contain standardised information on each driver and database which should aid you in selecting a database to use. It will also inform you quickly of any issues within drivers or whether a driver is not fully compliant with the
DBISpecification. - Rambles, Tidbits and Observations
-
dbi.perl.org/tidbits
There are a series of occasional rambles from various people on the
DBImailing lists who, in an attempt to clear up a simple point, end up drafting fairly comprehensive documents. These are quite often varying in quality, but do provide some insights into the workings of the interfaces. - Articles
-
A list of articles discussing the DBIcan be found on theDBI WWWpage at:
dbi.perl.org
These articles are of varying quality and age, from the original Perl Journal article written by Alligator and Tim, to more recent debacles published online from about.com.
- READMEfiles
-
The READMEfiles included with each driver occasionally contains some useful information ( no, really! ) that may be pertinent to the user. Please read them. It makes our worthless existences more bearable. These can all be read from the mainDBI WWWpage at:
dbi.perl.org
- Mailing Lists
-
There are three mailing lists for DBI:
dbi-announce@perl.org -- for announcements, very low traffic dbi-users@perl.org -- general user support dbi-dev@perl.org -- for driver developers (no user support)
For information on how to subscribe, set digest mode etc, and unsubscribe, send an email message (the content will be ignored) to:
dbi-announce-help@perl.org dbi-users-help@perl.org dbi-dev-help@perl.org
- Mailing List Archives
-
-
- USMailing List Archives
-
outside.organic.com/mail-archives/dbi-users
Searchable hypermail archives of the three mailing lists, and some of the much older traffic have been set up for users to browse.
- European Mailing List Archives
-
www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest
As per the
USarchive above.
-
Compilation Problems
2.1. Compilation problems or It fails the test!
First off, consult the
dbi.perl.org
If it's a known problem, you'll probably have to wait till it gets fixed. If you're really needing it fixed, try the following:
- Attempt to fix it yourself
-
This technique is generally not recommended to the faint-hearted.
If you do think you have managed to fix it, then, send a patch file
( context diff ) to the author with an explanation of:
-
- *
- What the problem was, and test cases, if possible.
- *
- What you needed to do to fix it. Please make sure you mention everything.
- *
-
Platform information, database version, perl version, module version and
DBIversion.
-
- Email the author Do NOTwhinge!
-
Please email the address listed in the WWWpages for whichever driver you are having problems with. Do not directly email the author at a known address unless it corresponds with the one listed.
We tend to have real jobs to do, and we do read the mailing lists for problems. Besides, we may not have access to <insert your favourite brain-damaged platform here> and couldn't be of any assistance anyway! Apologies for sounding harsh, but that's the way of it!
However, you might catch one of these creative genii at 3am when we're doing this sort of stuff anyway, and get a patch within 5 minutes. The atmosphere in the
DBIcircle is that we do appreciate the users' problems, since we work in similar environments.If you are planning to email the author, please furnish as much information as possible, ie:
-
- *
-
ALLthe information asked for in theREADMEfile in the problematic module. And we meanALLof it. We don't put lines like that in documentation for the good of our health, or to meet obscureREADMEfile standards of length.
- *
-
If you have a core dump, try the Devel::CoreStack module for
generating a stack trace from the core dump. Send us that too.
Devel::CoreStack can be found on CPANat:
www.perl.com/cgi-bin/cpan_mod?module=Devel::CoreStack
- *
- Module versions, perl version, test cases, operating system versions and any other pertinent information.
-
Remember, the more information you send us, the quicker we can track problems down. If you send us no useful information, expect nothing back.
Finally, please be aware that some authors, including Tim Bunce, specifically request that you do not mail them directly. Please respect their wishes and use the email addresses listed in the appropriate module "README" file.
-
- Email the dbi-users Mailing List
- It's usually a fairly intelligent idea to cc the mailing list anyway with problems. The authors all read the lists, so you lose nothing by mailing there.
Platform and Driver Issues
3.1 What's the difference between ODBC and DBI?
In terms of architecture - not much: Both define programming
interfaces. Both allow multiple drivers to be loaded to do the
actual work.
In terms of ease of use - much: The
Now there's an
Chapter 7 of ``Programming the Perl
3.2 What's the difference between Win32::ODBC and DBD::ODBC?
The The Win32::ODBC module is a 'thin' layer over the low-level
The Win32::ODBC module gives you access to more of the
The Win32::ODBC module only works on Win32 systems. The
The
Scripts written with the
The
The current
To summarise: The Win32::ODBC module is your best choice if you need access to more of the
Chapter 7 of ``Programming the Perl
3.3 Is DBI supported under Windows 95 / NT platforms?
Finally, yes! Jeff Urlwin has been working diligently on building
The
3.4 Can I access Microsoft Access or SQL-Server databases with DBI?
Yes, use the 3.5 Is there a DBD for <insert favourite database here>?
First check if a driver is available on Here's a general query that'll match all distributions:
search.cpan.org/search?query=DBD&mode=dist
If you can't find a driver that way, you could check if the database supports
search.cpan.org/dist/DBD-ODBC
If not, then try asking on the dbi-users mailing list.
3.6 What's DBM? And why should I use DBI instead?
Extracted from ``
``UNIX was originally blessed with simple file-based ``databases'', namely the dbm system. dbm lets you store data in files, and retrieve that data quickly. However, it also has serious drawbacks. File Locking The dbm systems did not allow particularly robust file locking capabilities, nor any capability for correcting problems arising through simultaneous writes [ to the database ]. Arbitrary Data Structures The dbm systems only allows a single fixed data structure: key-value pairs. That value could be a complex object, such as a [ C ] struct, but the key had to be unique. This was a large limitation on the usefulness of dbm systems. However, dbm systems still provide a useful function for users with simple datasets and limited resources, since they are fast, robust and extremely well-tested. Perl modules to access dbm systems have now been integrated into the core Perl distribution via the AnyDBM_File module.''
To sum up,
Chapter 2 of ``Programming the Perl
3.7 What database do you recommend me using?
This is a particularly thorny area in which an objective answer is difficult to come by, since each dataset, proposed usage and system configuration differs from person to person.From the current author's point of view, if the dataset is relatively small, being tables of less than 1 million rows, and less than 1000 tables in a given database, then mSQL is a perfectly acceptable solution to your problem. This database is extremely cheap, is wonderfully robust and has excellent support. More information is available on the Hughes Technology
www.hughes.com.au
You may also wish to look at MySQL which is a more powerful database engine that has a similar feel to mSQL.
www.tcx.se
If the dataset is larger than 1 million row tables or 1000 tables, or if you have either more money, or larger machines, I would recommend Oracle
www.oracle.com
Informix is another high-end
www.informix.com
In the case of
These views are not necessarily representative of anyone else's opinions, and do not reflect any corporate sponsorship or views. They are provided as-is.
3.8 Is <insert feature here> supported in DBI?
Given that we're making the assumption that the feature you have requested
is a non-standard database-specific feature, then the answer will be no.
However, driver authors may, if they so desire, include hooks to database-specific functionality through the "func()" method defined in the
Programming Questions
4.1 Is DBI any use for CGI programming?
In a word, yes!
4.2 How do I get faster connection times with DBD::Oracle and CGI?
Contributed by John D. Groenveld
The Apache "httpd" maintains a pool of "httpd" children to service client requests.
Using the Apache mod_perl module by Doug MacEachern, the perl interpreter is embedded with the "httpd" children. The
For more information on Apache, see the Apache Project's
www.apache.org
The mod_perl module can be downloaded from
www.perl.com/cgi-bin/cpan_mod?module=Apache
4.3 How do I get persistent connections with DBI and CGI?
Contributed by John D. Groenveld
Using Edmund Mergl's Apache::DBI module, database logins are stored in a hash with each of these "httpd" child. If your application is based on a single database user, this connection can be started with each child. Currently, database connections cannot be shared between "httpd" children.
Apache::DBI can be downloaded from
www.perl.com/cgi-bin/cpan_mod?module=Apache::DBI
4.4 ``When I run a perl script from the command line, it works, but, when I run it under the httpd, it fails!'' Why?
Basically, a good chance this is occurring is due to the fact that the user that you ran it from the command line as has a correctly configured set of environment variables, in the case of DBD::Oracle, variables like "ORACLE_HOME", "ORACLE_SID" or "TWO_TASK".The "httpd" process usually runs under the user id of "nobody", which implies there is no configured environment. Any scripts attempting to execute in this situation will correctly fail.
One way to solve this problem is to set the environment for your database in a "BEGIN { }" block at the top of your script. Another technique is to configure your
Similarly, you should check your "httpd" error logfile for any clues, as well as the ``Idiot's Guide To Solving Perl /
The ``Idiot's Guide To Solving Perl /
www.perl.com/perl/faq/index.html
as can the ``Perl
4.5 How do I get the number of rows returned from a SELECT statement?
Count them. Read theMiscellaneous Questions
5.1 Can I do multi-threading with DBI?
Perl version 5.005 and later can be built to support multi-threading.
The It is expected that some future version of the
5.2 How do I handle BLOB data with DBI?
Handling For example:
### $dbh is a connected database handle $sth = $dbh->prepare( "SELECT blob_column FROM blobby_table" ); $sth->execute;
would fail.
### $dbh is a connected database handle ### Set the maximum BLOB size... $dbh->{LongReadLen} = 16384; ### 16Kb...Not much of a BLOB! $sth = $dbh->prepare( "..." );
would succeed <I>provided no column values were larger than the specified value</I>.
If the
This behaviour is regulated by the "LongTruncOk" attribute which is set to a false value by default ( thus making overlong
### Set BLOB handling such that it's 16Kb and can be truncated $dbh->{LongReadLen} = 16384; $dbh->{LongTruncOk} = 1;
Truncation of
5.3 How can I invoke stored procedures with DBI?
The However, most database that support them also provide a way to call them from
So, assuming that you have created a stored procedure within the target database, eg, an Oracle database, you can use $dbh->"do()" to immediately execute the procedure. For example,
$dbh->do( "BEGIN someProcedure; END;" ); # Oracle-specific
You should also be able to "prepare" and "execute", which is the recommended way if you'll be calling the procedure often.
5.4 How can I get return values from stored procedures with DBI?
Contributed by Jeff Urlwin $sth = $dbh->prepare( "BEGIN foo(:1, :2, :3); END;" ); $sth->bind_param(1, $a); $sth->bind_param_inout(2, \$path, 2000); $sth->bind_param_inout(3, \$success, 2000); $sth->execute;
Remember to perform error checking, though! ( Or use the "RaiseError" attribute ).
5.5 How can I create or drop a database with DBI?
Database creation and deletion are concepts that are entirely too abstract
to be adequately supported by Some drivers, therefore, support database creation and deletion through the private "func()" methods. You should check the documentation for the drivers you are using to see if they support this mechanism.
5.6 How can I commit or rollback a statement with DBI?
See the "commit()" and "rollback()" methods in the Chapter 6 of ``Programming the Perl
5.7 How are NULL values handled by DBI?
"NULL" values in
$rv = $dbh->do( "INSERT INTO table VALUES( NULL )" );
but when queried back, the "NULL"s should be tested against "undef". This is standard across all drivers.
5.8 What are these func() methods all about?
The "func()" method is defined within
$rv =$dbh->func( 'argument', 'createDatabase' );
Software developers should note that the "func()" methods are non-portable between databases.
5.9 Is DBI Year 2000 Compliant?
You may also wish to read the ``Does Perl have a Year 2000 problem?'' section of the Perl
www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html
Support and Training
The Perl5 Database Interface isHowever, some organizations are providing either technical support or training programs on
Commercial Support
- The Perl Clinic
-
The Perl Clinic provides commercial support for Perl and Perl
related problems, including the DBIand its drivers. Support is provided by the company with whom Tim Bunce, author ofDBIand DBD::Oracle, works and ActiveState. For more information on their services, please see:
www.perlclinic.com
Training
- Westlake Solutions
-
A hands-on class for experienced Perl CGIdevelopers that teaches how to write database-connectedCGIscripts using Perl andDBI.pm. This course, along with four other courses onCGIscripting with Perl, is taught in Washington,DC; Arlington, Virginia; and on-site worldwide upon request.
See:
www.westlake.com/training
for more details.
Other References
In this section, we present some miscellaneous
www-ccs.cs.umass.edu/db.html www.odmg.org/odmg93/updates_dbarry.html www.jcc.com/sql_stnd.html
AUTHOR
Alligator Descartes. Portions are Copyright their original stated authors.COPYRIGHT
This document is Copyright (c)1994-2000 Alligator Descartes, with portions Copyright (c)1994-2000 their original authors. This module is released under the 'Artistic' license which you can find in the perl distribution.This document is Copyright (c)1997-2000 Alligator Descartes. All rights reserved. Permission to distribute this document, in full or in part, via email, Usenet, ftp archives or http is granted providing that no charges are involved, reasonable attempt is made to use the most current version and all credits and copyright notices are retained ( the