There's more than one way to do things | |
PerlMonks |
Metadata and DBI Abstractionby rob_au (Abbot) |
on Jun 08, 2001 at 17:43 UTC ( [id://86902]=perlquestion: print w/replies, xml ) | Need Help?? |
rob_au has asked for the wisdom of the Perl Monks concerning the following question:
Okay, here's what I'm working on at the moment - I am writing a DBI abstraction module which would allow me to reference the elements of the database in an object-orientated fashion. The reason for this is to reduce the coding overhead and hard-coded complexity (in the form of coded PREPARE and SELECT statements) of individual CGI scripts which interface and generate HTML pages for a medium-to-large scale web site.
Thus far, I have a working prototype which achieves this end, however involves a number of hard-coded subroutines for the interfacing of objects of each (table) type. This is an aspect of the module which I am wanting to remove, thus making it more universal and portable in usage. To this end, I have the following code for the creation of new database entry objects:
Now this works nicely - I will however be modifying the $self->{data}->{$sth->{NAME_lc}->[$index]} line to call a module subroutine in the same vein of CGI->param(-name => '', -value => ''). What I am wanting to achieve however and hence why I post this question for fellow monks is vetting of the values passed in the $args hash with the TYPE, PRECISION and NULLABLE field arguments from the $sth statement handle, in accordance with SQL data types recognised by the DBI module - That is, reject the passed data if it is not in the correct form, for example, a varchar-type argument is passed to be used for a int-type field. The standard values for common SQL data field types returned by TYPE are shown below for reference (from Programming the Perl DBI):
I ask though, what do my fellow monks feel would be the best way to implement this sort of functionality? I am quite loathe to large select-type block of code with a separate block of 'vetting' code for each of the 22 standard and common SQL types recognised by DBI, but fear this will be what I will have to resort to. Thanks in advance Ooohhh, Rob no beer function well without!
Back to
Seekers of Perl Wisdom
|
|