Programming the Perl DBI
Review No. 1: chromatic
The Scoop At some point in your programming life, you'll run into the idea of persistence. Whether data mining or storing customer information gathered from Web forms, data will end up shelved somewhere. Luckily for the Perl monks among us, we have the excellent DBI (DataBase Independent) module to provide a layer of abstraction and compatibility for multiple database systems. This book makes a great introduction and reference for the DBI.
Newcomers will quickly come up to workable knowledge on database concepts like basic SQL and relational models as well as Perlish constructs like object storage. Experienced users can use the included DBI specification as a reference and Appendix B for particular DBD quirks and caveats.
What's to Like? The writing is exceptionally crisp and clean. A DBI novice could absorb the knowledge of masters in just three hours, simply by reading the chapters. It's hard to imagine a better explanation of most concepts. The quality is consistent, as is the data being manipulated. As soon as the relational database concept comes on stage, so does the sample database used throughout: a list of locations and descriptions of megalithic sites in the UK.
The real meat starts in chapter four, with a discussion of the DBI architecture. Get used to manipulating statement handles -- you'll be doing a lot of that. Be sure to follow the recommendations for quoting and error checking, to save yourself hours of tedious debugging! Chapter five continues the tutorial, exhaustively covering database interactions. As usual for O'Reilly books, the authors take pains to point out benefits and drawbacks of different approaches. As there are multiple ways to pull rows from a completed query, and which fetch method is most efficient, or more flexible? The Advanced DBI chapter talks about database attributes and metadata -- ways to communicate with underlying DB and to massage data there. There's also good information about optimizations and transactions.
The material covered doesn't stop at the title. Chapter 7 talks about ODBC -- which may be preferable in some cases. Along the same lines, chapter 2 introduces all of the most important database concepts (Storing, Updating, Fetching, and Deleting) by looking at non-SQL means for storing data. These include Data::Dumper, Storable, flat files, and the Berkeley Database Manager. Though DBI receives its due for flexibility, portability, and power, the more tricks in your toolbag, the better you'll program. If you're new to the concept of persistent data storage, it also serves as a good introduction.
Porters and rogue programmers will appreciate Appendix B: an analysis of 13 database systems and their DBI drivers. Information on special syntax, SQL flavors, and supported DBI operations is included. Be sure to catch the gotchas and issues of your particular database. Administrators will appreciate chapter 8, which discusses the DBI shell (useful for testing SQL statements and connections) and the DBD::Proxy modules (providing compression and encryption as well as query forwarding).
What's to Consider? Perhaps due to the clarity and simplicity of the writing, the tutorial-esque DBI feature section, is rather short. Of 186 pages, 46 cover non-DBI mechanisms (chapter 2). That's not to say that there's anything missing, but that you might reach chapter six and ask, "Oh, is that all?" Adding another example database might flesh out some illustrations -- demonstrating how to solve two different problems would reinforce the important concepts. The Summary With its clear explanations and concise reference value, serious Perl programmers ought to make room on their shelves for the Cheetah. When you're knee deep in your first serious Web project, or bundling information from one database to another, you'll happily reach for Programming the Perl DBI.Review No. 2: PotPieMan
The Scoop
Programming the Perl DBI starts with the basics: flat-file databases (like /etc/passwd) and DBM file libraries. Most of us have implemented some type of database system using tab- or comma-delimited files, and the authors use these flat-file databases as a starting point for the rest of their discussion. First, they give an overview of the various functions that a programmer might want to perform on data that is placed in a database. This leads them into an organized explanation of the DBI and the advantages and disadvantages of using the DBI.
What's Bad?My main gripe about this book is that the DBI programming examples seem very basic. Granted, the book is specifically written about DBI programming, not manipulation of data retrieved by the DBI. Depending on one's perspective, this can be bad. If you are a CGI programmer expecting to find all the answers on designing a database-driven Web site, you will be slightly disappointed.
What's Good?On the other hand, if you have any skill as a programmer, you would be able to use this book as a great starting point for database-driven Web sites. It gives a great overview of all the important functions of a relational database and the structured query language. At first, the authors give examples of SQL statements, without any actual Perl code. They move slowly through the query language so as to make sure that the reader understands, and include a few tables to structure the discussion of the SQL operators. The authors then discuss queries over multiple tables, along with primary and foreign keys. Next, the authors discuss SQL statements to modify (insert, delete, and update) data.
The actual DBI programming sections begin with an explanation of the DBI architecture, which allows them to introduce all the elements of a Perl program that would interface with a database and grab data. The authors begin with a very basic program and then expand on it to include error checking, parameter binding, atomic fetching, and so on. (The parameter binding section is particularly informative.)
For the most part, programmers looking to get into database programming would be set after the first five chapters. The sixth chapter is concerned with advanced DBI programming, and does not seem absolutely necessary to read the first time through. However, its explanation of transactions will most likely be important. There is also a chapter that discusses ODBC and the DBI, which might be important if you have to deal with Windows machines or other ODBC data sources. The chapter gives a comparison between the DBD::ODBC and Win32::ODBC modules, which is nice. Finally, the eighth chapter concerns the DBI shell (dbish) and database proxying, which might be important to some.
The appendices are quite comprehensive. The authors (using man pages as a reference) go through all the nuts and bolts of the DBI and the various DBD drivers. Overall, Programming the Perl DBI gives a substantial explanation of utilizing the DBI.
So What's In It For Me?On the one hand, if you already have Perl experience and are new to database programming, you should consider picking up this book. To be honest, I did not know much about the DBI until I read this book. Now, I am relatively confident in my ability to implement databases in my programming. If you already have experience in programming with the DBI, though, you might not need this book. The last few chapters might be helpful, but it would be good to flip through the book before buying it.
Purchase this book from ThinkGeek.
Table of Contents
- Introduction
- Basic Non-DBI Databases
- SQL and Relational Databases
- Programming with the DBI
- Interacting with the Database
- Advanced DBI
- ODBC and the DBI
- DBI Shell and Database Proxying
- DBI Specification
- Driver and Database Characteristics
- ASLaN Sacred Site Charter
I learned the perl DBI from Mark Jason-Dominus' Article on Perl.com.
It's quite a good intro, and I'd recommend it to anybody who knows perl fairly well. You don't even have to know much about RDBMS.
That article, paired with the perldoc information on the DBI is fairly decent to at least get started. The perl DBI book reviewed here though is good too if you want to go a bit deeper.
-- Truth goes out the door when rumor comes innuendo. -- Groucho Marx
Further, in addition to being about as negative as advertising copy [that is, not at all], they're also uniformly shallow. I guess there isn't anything deep to be said about a lot of this material (though a review of the existential angst and ennui in a data patterns book could be pretty funny), still a lot of these just feel like a rehash of the table of contents. Surely we can do a little better than that.
I know, I know, the "right" thing to do, if I'm so disappointed in the reviews, would be to offer some myself (or encourage others to do so -- I'm not saying I'm necessarily the one that can fix the problem). Fair point, but the one thing I give you is that you consistently read the books before I get a chance so that doesn't feel like an option here.
I dunno. I guess I'm just asking for some variety. I love O'Reilly books too, and think well of most of the many I've read (but not all! e.g. the MySQL one... damn that was lousy), but it's hard to take the reviewers opinions seriously when they like *everything* they write about. Maybe we can run some reviews of "...For Dummies" books as counterpoint or something, or get multiple *contrasting* reviews each time around. As it is, the reviews are barely worth reading -- I could just thumb through an ORA catalog of upcoming titles to see for myself what you're going to love next...
DO NOT LEAVE IT IS NOT REAL