[CDBI] how to use variable as column name in set _sql

pangaoyong pangaoyong at 126.com
Fri Jun 9 03:54:52 BST 2006


  the code like this,

 __PACKAGE__->set_sql(distinctByProduct => qq{
    SELECT DISTINCT %s
    FROM   __TABLE__
    WHERE  product = ? order by %s
}); 
sub distinctCol
{
    my ($class, $col, $productName) = @_;
    return $class->sql_distinctByProduct($col)->select_col($productName);
}

when method distinctCol is called it throw the error like this,

DBD::mysql::st execute failed: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [for Statement "<br><br>    SELECT DISTINCT price<br>    FROM   product<br>    WHERE  name = ? order by<br><br>you could see that the second %s is not passed in, the first %s is ok, could someone give me a clue?<br><br>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/pipermail/classdbi/attachments/20060609/d9f4e848/attachment.htm


More information about the ClassDBI mailing list