Chapter 61. Beyond Hardcoded Database Applications with DBIx::Recordset

Terrence Brannon

Perl has been dubbed “The Duct Tape of the Internet,” providing a comfortable interface to an ever-growing number of external technologies. In this article, I provide an introduction to one of the most convenient and powerful Perl interfaces to relational databases: DBIx::Recordset.

CRUD Without SQL

By and large, when using databases from a programming language, you are creating, reading, updating, or deleting data—CRUD, for short. If you use the DBI module directly, you have to write SQL for these operations. In contrast, DBIx::Recordset supports CRUD through the four simple functions Insert, Search, Update, and Delete.

Under the hood, DBIx::Recordset generates SQL and ensures that it is syntactically correct for whatever database you are using. There are large applications written using DBIx::Recordset that require no code changes to run on MySQL, Microsoft Access, or Oracle. This lets you ship database code off-site knowing that it will run with whichever database your users have. It also future-proofs internal applications against unforeseen changes in database systems.

Sample Usage

This article demonstrates how I used DBIx::Recordset to solve a real task I had during a contracting job. The company had a user registration table that contained basic information about a client: name, email address, phone number, and so on. However, a new table was developed to store demographic information about ...

Get Computer Science & Perl Programming 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.