Thanks for your reply!

but dispatch table seems not to shorten code. I still have to write a_query,b_query,c_query... respectly. In my brain, a_query_builder, b_query_builder ... and x_query_builder sub are all much similar like:
sub a_query_builder{ my ($table_name, $display_cols_ref, $where_cols_ref) = @_; if ($where_cols_ref->{'year_min'}) { push @clauses, "Year >= $wher +e_cols_ref->{'year_min'}" } if ($where_cols_ref->{'year_max'}) { push @clauses, "Year <= $wher +e_cols_ref->{'year_max'}" } # ... $clause = join(" AND ", @clauses); $display_cols = join(",", @$display_cols_ref); $sth = $dbh->prepare("SELECT $display_cols FROM $table_name WHERE $cla +use"); }

I'm not sure the above treatment correct or not, but I hope to create a general code to handle all kinds of query statement building. Is creating a query class a good idea?





I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction


In reply to Re^2: How treat query elegantly and more? by xiaoyafeng
in thread How treat query elegantly and more? by xiaoyafeng

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.