Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

Querying
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).

Documentation
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.

Disconnecting
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.

Conclusion
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).


In reply to EZDBI by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-18 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found