March 5, 2021
Hot Topics:

Programming the Perl DBI

  • By Developer.com Staff
  • Send Email »
  • More Articles »


1. Few methods actually need to be implemented since the DBI provides suitable defaults for most of them. The DBI::DBD module contains documentation for any intrepid driver writers.

2. In reality, the number of concurrent statement handles is dependent on the underlying database. For information on how many concurrent statement handles your database can support, see Appendix B.

3. The actual definition of "installed driver" is a little loose. The DBI simply searches the directories in @INC looking for any DBD subdirectories that contain .pm files. Those are assumed to be drivers. It does not verify that the modules are completely and correctly installed. In practice, this process is fast and works well.

4. Note that not necessarily every data source that is reachable via the driver is returned. Similarly, the inclusion of a data source does not imply that it is actually currently available for connection.

5. An excellent example of an application that figures out data source names at runtime is dbish, discussed more fully in Chapter 8.

6. In general, this is true. However, some database systems, such as MySQL, support different users but only one schema.

7. Actually, the error message will be displayed twice for reasons that will be explained in the "Error Handling" section later in this chapter.

8. The exact behavior when both attributes are set may change in future versions. This is something to consider if the code is inside an eval.

9. If the Perl you are using was built with threading enabled, then each method entry line also shows the thread number, e.g., thr0. The DBI implements a per-driver mutex so that each DBD driver may only be entered by one thread at a time. Trace levels 4 and above show this in action.

10. Note that internal quotes are not escaped. That's because neat() is designed to produce output for human readers, and to do so quickly since it's used by the internal trace mechanisms. If you wish quote escaping to occur, you could use the quote() method instead.

11. 400 characters is the default value for the $DBI::neat_maxlen variable, which defines the default maximum length for the neat() function.

About the Authors

Alligator Descartes has been an itinerant fiddler with computers from a very early age, which was ruined only by obtaining a BSc in computer science from the University of Strathclyde, Glasgow. His computing credits include several years of Oracle DBA work, multi-user Virtual Reality servers, high-performance 3D graphics programming, and several Perl modules. He spends his spare time trudging around Scotland looking for stone circles and Pictish symbol stones to photograph. Alligator Descartes is not his real name.

Tim Bunce has been a perl5 porter since 1994, contributing to the development of the Perl language and many of its core modules. He is the author and maintainer of the DBI, DBD::Oracle,and Oracle::OCI modules, and author and co-maintainer of The Perl Module List. Tim is the founder and CTO of Data-Plan Services, a perl, database, and performance consultancy with an international client base. Prior to that we was Technical Director (CTO) of IG in the UK where he was awarded by British Telecom for his role in the rapid development of their Call Management Information service, a system implemented in Perl. He is co-author, along with Alligator Descartes, of Programming the Perl DBI, the definitive book on DBI, published by O'Reilly & Associates in February 2000.

Source of this material

This is Chapter 4: Programming the Perl DBI from the book Perl DBI (ISBN:1-56592-699-4) written by Alligator Descartes & Tim Bunce, published by O'Reilly & Associates.

To access the full Table of Contents for the book

Page 8 of 8

This article was originally published on April 10, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date