Home » Database » DB » Bug #6315
SQL comments before query confuse isManip()
Details
| Submitted | 2005-12-21 16:20 UTC |
|---|---|
| From | pear-bugs-2005 at ryandesign dot com |
| Assigned | danielc |
| Status | Wont fix |
| Package | DB |
| PHP Version | 5.1.1 |
| OS | N/A |
| Roadmaps | (Not assigned) |
Comments
[2005-12-21 16:20 UTC] pear-bugs-2005 at ryandesign dot com
Description:
------------
I'm using DB 1.7.6. Its isManip() functions tells you if the
query manipulates data, by checking whether the first word
is INSERT, UPDATE, and so forth, skipping any preceding
whitespace.
In our project, we installed a wrapper such that for every
SQL query, a comment gets prepended with the formatted
contents of debug_backtrace(). The idea is that when a query
shows up in for example the slow query log, the backtrace in
the comment will show us exactly where the query is in the
code and why we got there.
It's easy to see that when we prepend these comments, the
isManip() function doesn't work.
The fix, which is attached, is to first remove comments from
the query before checking for one of the special statement
types.
Test script:
---------------
--- DB.bak.php 2005-12-21 16:12:21.000000000 +0100
+++ DB.php 2005-12-21 16:36:48.000000000 +0100
@@ -628,6 +628,7 @@
. 'LOAD DATA|SELECT .* INTO|COPY|'
. 'ALTER|GRANT|REVOKE|'
. 'LOCK|UNLOCK';
+ $query = preg_replace(array('%/\*.*\*/%s', '%(?<=\s|^)--.*%'), '', $query);
if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
return true;
}
[2005-12-22 11:48 UTC] pear-bugs-2005 at ryandesign dot com
I don't think I follow... Are you saying that DB is
obsolete? End-of-life? Won't be updated anymore? That would
come as a considerable surprise to me. The package's main
page certainly doesn't mention it.
When you say "It can't be fixed in a completely reliable
way" are you talking about this specific bug or the various
other reported isManip() bugs? I'm not concerned with other
bugs right now, just this one: that it doesn't handle SQL
comments before the query, which we want to use. As far as I
am able to determine, my patch fixes that completely and
safely. Or have you found a recipe where my patch doesn't do
the right thing? If not, I don't see why the patch shouldn't
be applied.
[2005-12-22 12:02 UTC] pear-bugs-2005 at ryandesign dot com
I maintain that my patch does fix this specific issue in a
reliable way. I also can't see how anyone would rely on
isManip() returning false for queries that do manipulate data
but which begin with comments. Do you have a specific example
of an SQL query or application which is adversely affected by
my patch? If so, I'd like to know about it so that I can
either improve my solution or at least understand why it
cannot be improved. Thanks.