Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling


by Juerd (Abbot)
on Jun 12, 2002 at 23:09 UTC ( #174059=modulereview: print w/replies, xml ) Need Help??

Item Description: Easy interface to SQL database

Review Synopsis:

This review was requested by one of the module's authors, belg4mit. A while ago, we discussed some easier ways of using DBI, and of course his EZDBI and my DBIx::Simple were mentioned. I will not discuss DBIx::Simple in this review. If anyone wants to review it, please do so.

What is EZDBI?
EZDBI (Easy DBI) is a module that provides functions for database connections, using DBI as its backend. Many people find DBI either too hard or too much work (why fetchrow_arrayref if you can have something shorter?), and several modules try to end that problem. EZDBI uses no object orientation, so anyone without too much programming experience can install and use the module immediately. I review version 0.1.

Its name
Normally, modules in CPAN have some sort of hierarchy. It isn't always consistent or well-chosen, but most modules are grouped in top-level namespaces. DBI extensions should be in the DBIx:: namespace (that's right, not even DBI::), but this one uses a top-level namespace of its own. It is hard to find when searching CPAN: when using keywords like 'Easy' and 'Simple' in a module-name search, EZDBI is not one of the results. Even when you look for modules with 'DBI' in the name, EZDBI is unclear until you pronounce it letter by letter in English (which may not be a natural thing to do for those who don't natively speak English). There is a module called EasyDB, one called DBIx::Easy and one called EZDBI. That isn't very handy.

Connecting to a database
The connecting function is simply called Connect. It's a straightforward function call that takes either a DBI DSN or named arguments.

Of course, the most important thing you will want to do with a database module is sending queries to the database and getting results. EZDBI provides a function for each of the most used SQL commands: Select, Insert, Update, Delete. If you have a normal database select like SELECT foo FROM bar, you would put the Select part outside of the quotes and have Select 'foo From bar';. I changed FROM to From to match the ucfirsted Select.

The Select function is rather intelligent. By default, it fetches everything and returns it, but it can also return an object that can be used to fetch one row at a time. Insert has a nice ??L shortcut that is turned into (?, ?, ?, ...) with as many question marks as the number of remaining arguments.

There is Sql for when the given functions cannot execute the SQL you want it to. Unfortunately, this uses DBI's do, so don't expect to be able to get information out of it (For example with mysql's SHOW TABLES command).

Every module needs documentation. Without the documentation, I wouldn't be able to write this review, as I didn't actually test the module thoroughly. I did not have to, as the manual provided almost everything I wanted to know, and the source gave me the rest of the clues. Although the programming style itself is not the one I like, the manual is very clear and easy to read. It is written with beginning programmers in mind, so the EZ is worth its bits. I especially like the vivid examples.

However, I found something in the documentation that bothers me. EZDBI's manual states that EZDBI takes care of ? placeholders, but this module only expands its special ??L placeholder (which is in turn only for Insert). Placeholder substitution is performed by DBI's execute(), but up to three times, EZDBI takes credit for what DBI does.

Multiple databases
This is quite a hassle with EZDBI. You can have multiple databases, but you'll have to use Use, which can be compared to Perl's own select that selects a filehandle. This way, copying data from one database to another (which is not uncommon: a lot of people migrate from MySQL to Postgres, for example) has to be done using temporary variables and a lot of Use calls. I don't think this is EZ, object orientation would be so much better for this.

When the Perl interpreter ends, it will destroy all variables, including the DBI object that is stored inside of EZDBI. That way, database connections are properly terminated. If the end of the interpreter never happens (i.e. when using PPerl or mod_perl), you're stuck with the database connection even after your script ends. You will have to explicitly call Disconnect. EZDBI is not object oriented, so there is no object to destroy automatically when it goes out of scope. This is potentially very dangerous.

I wouldn't use EZDBI myself, but not because the module is bad. It's a very good module, but I happen to like object orientation, and I prefer raw SQL to semi-abstracted SQL. Maybe I'll steal the ??L idea one day, though. If object orientation is too hard for you, or if you want to do things the easiest way, EZDBI is perfect for you. Don't forget to Disconnect explicitly when using EZDBI in mod_perl, because otherwise someone else might be able to access to your database!

This is the very first module review I've ever written. Please tell me if I did anything wrong (reply).

Replies are listed 'Best First'.
by belg4mit (Prior) on Jun 12, 2002 at 23:50 UTC
    Thanks Juerd. I asked Juerd to take a second look at the module as he had been one of the most vocal critics. Many of the criticisms prompted me to add several the features I have. I asked if he might review the module while re-viewing the module, as I hoped it would gain additional exposure, code review, and prodding :-D

    A few clarifications...

    As far as ? this is all handled in the private _substitute function. It does a bit more than just expand ??L, but yes the wording of the documentation does "take credit" for the actual placeholder substitution done by DBI. I believe the intent here was to not provide the user with more information than they needed to know, I will look into rewording it to keep the details hidden but not take undue credit.

    You don't actually *have* to use Use to handle multiple databases, you can actually just write the appropriate SQL e.g. Select('From BAR.barfle') even though you are "Connected" to FOO. This is just a convenience function in this case, and should probably be clarified. It is actually more pertinent to connecting to multiple RDBMS, say on hosts fred and barney. At which point I think there will be lots of context switching no matter what interface you use.

    There is a currently undocumented "feature"/side-effect that I have been wondering if I should in fact document. It is the fact that the object returned by Connect and passed to Use is in fact the DBI object. I am not sure if this could be useful information...

    UPDATE: I have addressed your documentation concerns, as well as fixed a compile-time error under 5.005 reported by gav^ and just uploaded the result as 0.11 Until it reaches your local CPAN mirror it is available at

    perl -pew "s/\b;([mnst])/'$1/g"

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: modulereview [id://174059]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2023-03-22 15:16 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.