Local databases with DBI

jdavidb on 2002-12-20T18:51:33

DBD backends are the neatest thing since sliced bread. If I want to write a Perl program to use an SQL database, but do not have an RDBMS, there are at least five options I can think of that will use local files as an SQL database. Three of these will give you files you can use elsewhere.

  • DBD::CSV The old standby
  • DBD::Sprite readers of the first edition of O'Reilly's CGI book will recognize Sprite, originally a Perl4 style library, if I remember correctly, now made into a module, enhanced, optimized, and packaged as a DBI backend.
  • DBD::Excel Why not use an Excel workbook as a database? Each worksheet is a table. Files are completely compatible, except you will no doubt be distressed to hear that last time I tried, this module worked on UNIX but not Win32.
  • DBD::XBase dBase files, FoxPro files, Codebase, and Clipper. I once wrote a C parser for this file format. It's not bad, except each table is a separate file. I've suffered through dBase IV for five years; as of next Monday I start a new job where I intend to never touch it again.
  • DBD::SQLite Handsome little devil of a module from Matt Sergeant, the XML wizard whose unsung non-XML accomplishments in the world of Perl have benefitted me greatly. Fast, reliable, atomic, amazing.

The more tools you learn, the better a job you can do picking the right tool for the job. You might even find yourself using DBD::Excel or DBD::XBase for something that will never interact with the associated applications. Someday I may benchmark all these.

Any others I left out?


DBD::ODBC to the rescue!

Buck on 2002-12-20T22:37:54

IIRC, an Excel spreadsheet can be set up as an ODBC datasource locally; the spreadsheet can be *anywhere*. Same with MS Access.