Dear monks,

while working on Dancer app I try to use placeholders for the SQL queries. The first code gives a good result but it is without placeholders. The second with placeholders doesn't show the result I had expected. To my idea the problem is with the third placeholder $link. Can't find out what am I doing wrong?

Thanks,

Gert

First code without placeholders but it works

prefix '/en/collections' => sub { get '/:link' => sub { my $link = params->{'link'}; my $sql = "SELECT imgf, long_i, status_prod, name_prod, name_cat, name_col FROM products, categories, collections WHERE products.fk_cat = categories.id_cat AND products.fk_col = collections.id_col AND link_col= '$link'"; my $sth = database->prepare($sql); $sth->execute; template 'col-m', { have_text_markdown => $have_text_markdown, bigprodlist => $sth->fetchall_arrayref( {} ) }, { layout => 'pin' }; }; };

Second code without placeholders but does not work?

prefix '/en/collections' => sub { get '/:link' => sub { my $link = params->{'link'}; #print Dumper $link; my $sql = <<'SQL'; SELECT imgf, long_i, status_prod, name_prod, name_cat, name_col FROM products, categories, collections WHERE products.fk_cat = ? AND products.fk_col = ? AND link_col = ? SQL my $sth = database->prepare($sql); #print Dumper $link; # is okay $sth->execute( 'categories.id_cat', 'collections.id_col', $link ); template 'col-m', { have_text_markdown => $have_text_markdown, bigprodlist => $sth->fetchall_arrayref( {} ) }, { layout => 'pin' }; }; };

In reply to Avoid embedding variables in SQL - Dancer App by GertMT

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.