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

Fix autoExecute failed UPDATE if placeholders presents in WHERE (bug #21217) #3

Merged
merged 1 commit into from
Apr 19, 2020

Conversation

Enyby
Copy link
Contributor

@Enyby Enyby commented Jun 2, 2017

autoExecute failed UPDATE if placeholders presents in WHERE

See bug #21217: https://pear.php.net/bugs/bug.php?id=21217

Description:

If you call autoExecute() and in WHERE present any of '!?&' query simple fails. Does not matter where these symbols appear - inside string literal or in query (for example 'a != b').
This happens because inside autoExecute() where used for catch placeholders. For example you send to autoExecute() array with $data of 3 items and $where with 'a != b'. On autoPrepare() inside autoExecute() will be collected FOUR placeholders. 3 from $data and '!' inside $where as 4 placeholder.
After that will be called execute() with $data array. But it have only 3 values. It cause error because parsed statement required 4 values for 4 placeholders.

Solution: make replace in $where before send it to autoPrepare() inside autoExecute():

if ($where) {
    $where = strtr($where, array('?' => '\?', '!' => '\!', '&' => '\&',));
}

Test script:

$data = array('a' => 'a', 'b' => 'b', 'c' => 'c');
$ret = $db->autoExecute('table', $data, DB_AUTOQUERY_UPDATE, 'a != b');
var_dump($ret);

Expected result:

DB_OK

Actual result:

DB_ERROR: DB_ERROR_MISMATCH raised from executeEmulateQuery()

autoExecute failed UPDATE if placeholders presents in WHERE

See bug #21217:

Description: ------------ If you call autoExecute() and in WHERE present any of '!?&' query simple fails. Does not matter where these symbols appear - inside string literal or in query (for example 'a != b'). This happens because inside autoExecute() where used for catch placeholders. For example you send to autoExecute() array with $data of 3 items and $where with 'a != b'. On autoPrepare() inside autoExecute() will be collected FOUR placeholders. 3 from $data and '!' inside $where as 4 placeholder. After that will be called execute() with $data array. But it have only 3 values. It cause error because parsed statement required 4 values for 4 placeholders. Solution: make replace in $where before send it to autoPrepare() inside autoExecute(): if ($where) { $where = strtr($where, array('?' => '\?', '!' => '\!', '&' => '\&',)); } Test script: --------------- $data = array('a' => 'a', 'b' => 'b', 'c' => 'c'); $ret = $db->autoExecute('table', $data, DB_AUTOQUERY_UPDATE, 'a != b'); var_dump($ret); Expected result: ---------------- DB_OK Actual result: -------------- DB_ERROR: DB_ERROR_MISMATCH raised from executeEmulateQuery()
DB/common.php Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

2 participants