Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_log_query method raises a warning when query contains "%" #57

Closed
kaemu opened this issue Apr 30, 2012 · 3 comments
Closed

_log_query method raises a warning when query contains "%" #57

kaemu opened this issue Apr 30, 2012 · 3 comments
Assignees
Milestone

Comments

@kaemu
Copy link

kaemu commented Apr 30, 2012

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

@treffynnon
Copy link
Collaborator

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.

@ghost ghost assigned treffynnon Nov 8, 2012
@treffynnon
Copy link
Collaborator

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.

@treffynnon
Copy link
Collaborator

http://stackoverflow.com/a/10929115/461813 might be a possible solution here.

treffynnon added a commit that referenced this issue Nov 14, 2012
Thanks to Jeff Roberson <ridgerunner@fluxbb.org> for his regex skills.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants