_log_query method raises a warning when query contains "%"
kaemu opened this issue · 3 comments
Issue
When logging is on:
ORM::configure('logging', true);
Queries containing the "%":
$many = Model::factory('user')->where("active",1)->where_raw('username like "ben%"')->find_many();
Raise PHP warning:
Warning: vsprintf() : Too few arguments in idiorm.php on line 267
Because % must be escaped in the query for vsprintf.
Fix
In idiorm.php, line 264:
$query = str_replace("?", "%s", $query);
should be:
$query = str_replace("?", "%s", str_replace("%","%%",$query));
This fixes the problem for the "%" chars.
Second issue
The problem remains with the "?" char inside the query:
$many = Model::factory('book')->where("active",1)->where_raw('comments like "has been released?%"')->find_many();
vsprintf raises the same error.
— Ben
This is partially fixed in commit 84bd58f but I am not so sure how to handle the ? chars at this point as they are being converted as though they are PDO placeholders.
I will look through the code and see if this can be solved.
This will require a change to the code to ensure that question marks enclosed in quotes ("
) and apostrophes ('
) are not replaced with %s
for the vsprintf()
command to come along and process. PDO will only replace question marks outside of quotes so this logging function should emulate this.
http://stackoverflow.com/a/10929115/461813 might be a possible solution here.