Have you even tried it yet? Look ... like i said before, whether you pass the SQL around or you pass the resulting data structure around ... it's all going to be spaghetti code unless you take care for it not to be. Here were i work, we use something like this to create a select box:
select_prep takes a 2 dimensional array and returns a datastructure suitable for HTML::Template.my $fields = [ qw(id name) ]; my $table = $dbh->selectall_arrayref(' select id, name from some_table '); my $select = $self->select_prep($fields, $table, $selected_id); # now "send" $select to HTML::Template
However, i have had much maintainability success by using Class::Phrasebook::SQL in some of my past personal projects. I store the SQL queries in an XML file that is parsed into a hash. The user passes in the key as a query parameter:
Where make_table is a thin wrapper for my DBIx::XHTML_Table module, which takes a SQL query string and returns the results already wrapped in an XHTML table. Here is an entry from the XML Phrasebook:# param might contain go_director=42 (id for the director) # or maybe go_genre=72 or go_writer=150 if (my ($choice) = grep /^go_/, param()) { my $query = $BOOK->get($choice); print make_table($dbh, $query, param($choice)); }
The SQL is tucked away in an XML file (i can pretend they are stored procedures ;)) and my code is free of SQL. What's not maintainable about that? Now, my design of what i do with the SQL could be improved, but that's my doing ... not the technique itself.<phrase name="go_director"> select movie.id,movie.title,movie.year,movie.id as img from movie inner join director_xref on movie.id=director_xref.movi +e_id inner join director on director_xref.director_id = director.id where director.id= ? order by movie.year </phrase>
Why are we having this conversation ... go ... experiment! Try new things. Even if your gut tells you it won't work, it's all good experience. :)
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re^7: abstraction -- level up!
by jeffa
in thread abstraction -- level up!
by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |