contao/test — Issue #1085: In Database_Statement::execute %c clashes with %c usage in MySQL
Author: importer
Created: 2011-11-29 07:19:52+00:00
State: open
Labels: Defect, framework

Hi Team ,
When I use the DATE_FORMAT() MySQL function in an SQL statement, Database_Statement::execute() trows:
"Too few arguments to build the query string"
Example:

```
SELECT pid
FROM tl_my_table
WHERE year = DATE_FORMAT( NOW( ) , "%Y" )
AND MONTH = DATE_FORMAT( NOW( ) , "%c" )
ORDER BY amount DESC
LIMIT 0 , 5
```

Please note that MySQL uses % to format dates. Here is the complete list of used characters to be escaped
http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format

Maybe another way of binding variables should be used(not using sprintf).

My quick and dirty solution was to remove 'c' from

```
$this->strQuery = preg_replace('/%([^bcdufosxX])/', '%%$1', $this->strQuery);
```

but I am not sure what else this will brake.

Thanks.

Related issues: #1220

--- _Originally created by kberov on October 11th, 2009, at 06:27pm (ID 1085)_