techcode has asked for the wisdom of the Perl Monks concerning the following question:
For my own needs I wrote a modules that is used as some sort of Database abstraction. Sort of, as it doesn't do all the bells and whistles that SQL::Abstract and DBIx::Abstract do. But on the other hand, it's much simpler and it does a little bit more in some areas.
It can generate following SQL statements:
- insert - you send it hash/hashref that you get from say CGI.pm or similar, and tell it in which table to insert it. It's "smart" enough to generate SQL that contains only fields that are in both places (in data you sent it, and table).
- update - same as previous. Only thing that you send it too, is the primary key filed name. But I believe I can change that so that modules itself determines the primary key field.
- select - but only a simple one, "SELECT _what_ FROM _table_ WHERE _key_field_ = ?". I seem to either need that simple queries, or much more complicated (several tables) that I dont know how to generate with *::Abstract modules - but I may add a little bit more functionality (to be able to specify more after WHERE)
It was all written with MySQL in mind. But I'm now thinking to get it "in shape" and publish it on CPAN - so naturally I want it done that way so that it can be use with other RDBMS's and not just MySQL ...
So finally we got to the question : When you use DBI - are queries like insert/update/select always the same, no matter what DB you are using? And what about things like describe query which I plan to use to get primary key field name ...
Because if it's not - I have a little extra work. My plan is to make a "sub-module", say Module::MyModule is base one, and then Module::MyModule::mysql would be for mysql specific.
A suggestion of name for the module is also welcome. I was thinking of DBIx::Handy?
O and any suggestion on how to ensure that you can easily make an extension in the future. First thing that comes to my mind is that it can return results of SQL query in a form that is suited for HTML::Template LOOP as I need that often. I know that I can write something like DBIx::Handy::HtmlTemplate that would 'use base qw(DBIx::Handy);' and just add such a method - but I don't know how can I ensure that it would be possible to have several of those "plug-ins" at the same time ...
THANK YOU! PS. I already have the book : "Sam Tregar - Writing Perl Modules for CPAN"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Differences in SQL syntax when using DBI (are there any)? And help on publishing module on CPAN.
by anonymized user 468275 (Curate) on Jul 15, 2005 at 10:19 UTC | |
by Xaositect (Friar) on Jul 15, 2005 at 18:00 UTC | |
by techcode (Hermit) on Jul 15, 2005 at 19:23 UTC | |
by itub (Priest) on Jul 15, 2005 at 18:15 UTC | |
by techcode (Hermit) on Jul 15, 2005 at 11:54 UTC | |
by simonm (Vicar) on Jul 15, 2005 at 21:45 UTC |