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:

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
select_prep takes a 2 dimensional array and returns a datastructure suitable for 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:

# 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)); }
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:
<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>
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.

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.