Closed (won't fix)
Project:
Drupal core
Version:
7.x-dev
Component:
database system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
8 Dec 2007 at 18:24 UTC
Updated:
21 Aug 2008 at 22:04 UTC
Jump to comment: Most recent file
1. use != instead of <>.
2. use %s for empty string.
3. use % in argument input, instead of inline %% (PDO style).
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | queries_cleanup-0.6.patch | 44.76 KB | hswong3i |
| #24 | queries_cleanup-0.5.patch | 44.68 KB | hswong3i |
| #18 | queries_cleanup-0.4.patch | 45.22 KB | hswong3i |
| #11 | queries_cleanup-0.3.patch | 23.08 KB | hswong3i |
| #8 | queries_cleanup-0.2.patch | 24.06 KB | hswong3i |
Comments
Comment #1
hswong3i commentedpatch file
Comment #2
lilou commentedThis patch (apply on drupal6-head) generate a crash on cache system :
Warning: require_once(./includes/cache.inc) [function.require-once]: failed to open stream: Permission denied in D:\Serveur\www\drupal-6-dev\includes\bootstrap.inc on line 898
Fatal error: require_once() [function.require]: Failed opening required './includes/cache.inc' (include_path='.;C:\php5\pear') in D:\Serveur\www\drupal-6-dev\includes\bootstrap.inc on line 898
Comment #3
hswong3i commented@lilou: Seems a bit strange... Your error message is all about permission denied, but not programming error nor conflict... Would you mind to check those patched files permission, if they are able to open/read by your web server owner? E.g. are they have permission 644? I test the patch once again, and it is function for both MySQL and PostgreSQL ;-)
Comment #4
mooffie commentedWhy?
Comment #5
hswong3i commented@mooffie: according to my personal research project progress, the correctly use of DB API can greatly improve cross database compatibility, even with PDO and Oracle supporting. For more detail, please refer to my recent blog post.
Comment #6
hswong3i commentedI mark this into my personal research project issue.
Comment #7
hswong3i commentedComment #8
hswong3i commentedPatch reroll via latest CVS HEAD. Test without ill effect. It should be able to handle within D6, in order to prepare for next generation development.
Comment #9
chx commentedAs Siren is not a project on Drupal.org but an unofficial fork, I am removing it from issue titles to avoid confusion.
Comment #10
birdmanx35 commentedThis fails against Drupal HEAD.
Comment #11
hswong3i commented@birdmanx35: thanks for review and pointing out. Some changes are already fixed in other issue. Here is the updated version.
Comment #12
hswong3i commentedComment #13
birdmanx35 commented@hswong3i, no problem, that's about the extent of my abilities. I'll review this later tonight.
Comment #14
birdmanx35 commented@hswong3i, no problem, that's about the extent of my abilities. I'll review this later tonight.
Comment #15
birdmanx35 commentedI got this error when testing it...
$ patch -p0 < queries_cleanup-0.3.patch
patch: **** Only garbage was found in the patch input.
Is that me, or the patch?
Comment #16
HorsePunchKid commentedAre you sure that
!=is really better? According to this tool, it's not valid SQL-92, -99, or -2003. I'm pretty sure that it won't work in MS SQL Server, for example, though I don't have an instance to test against at the moment.Comment #17
scoutbaker commentedAnd the Coder module's (beta) SQL checking also references replacing "!=" with "<>".
Comment #18
hswong3i commentedThanks for suggestion. I search out most core queries, and replace (most) "!=" as "<>". I just search with following simple script, so may still miss some out:
Comment #19
birdmanx35 commentedThis patch still applies cleanly, and has made the necessary revisions. I am marking it RTBC.
Comment #20
gábor hojtsyWell, this is a huge patch which needs more then a yes or no on whether it applies or not. Adhering to coding standards with replacing != with <> looks like possible in Drupal 6, but I would not pursue replacing %s usage all around especially that nothing is broken in the systems we support. The quoted http://drupal.org/node/194162 issue which makes sense out of that is for 7.x. Please understand that we are focusing on stabilization not rewriting stuff on grand scales.
Comment #21
birdmanx35 commentedAfter thinking and reading about this patch, I have come to the following conclusions:
1) The patch was created to change != to <>, amongst other things.
2) That change has proved, through review by more educated individuals, to be of no use.
3) The whole patch, therefore, is based upon a single incorrect change in thought.
4) If the other problems tackled by this patch are really problems, they should be moved to a new patch, one that hasn't been touched by the incorrect change.
Gabor also points out that we are focusing on stability at the moment: however, if these are truly problems that need to be solved (which I can't determine), they need to be handled in a new patch.
Comment #22
scoutbaker commented@birdmanx35: Your #2 is incorrect. The original patch was replacing "<>" with "!=", not the other way around. This replacement is the one that was mentioned as possibly not being valid (comments #16, #17). The updated patch is properly replacing "!=" with "<>". This eliminates your #3 and #4.
Gábor thought we might get the SQL query replacements in. I would suggest we move this whole issue to D7 since we're so late in the game. We know all of the current queries are working. Changing them now would require an additioanl major effort to check all of the affected functions.
Comment #23
birdmanx35 commentedYep, typo on the first, and you are right. hswong3i did say earlier he may have missed all of the switches though, so I guess I'd check those.
Moving to D7 as suggested.
Comment #24
hswong3i commentedSince Drupal 7.x is now open for public development, this patch is reroll via latest CVS HEAD. No special change since #18.
P.S. In case of PDO, we will still need to clean up the
'%s'syntax: change them into%s(with'') or else PDO placeholder replacement will not accept it. BTW, I will reactive this issue after the successful commit of this first stage clean up, as that will affect almost ALL core queries.Comment #25
chx commentedI was always and still against using placeholders for constants. Remember my tirade in the other issue about how not to burden the developer? Not to mention it's cruft.
Comment #26
hswong3i commentedchx: totally agree with you. Since I clone these handling from ADOdb (where ADOdb is a OOP implementation), they are handled as driver object method, etc. If we will revamp our drivers as OOP in 7.x, it is a good idea for giving a simple ADOdb-clone. But before that, I would like to handle these simple abstraction as constant temporarily, and so we will able to introduce other database drivers into core without any difficulties, e.g. SQLite, Oracle and DB2. These abstraction are always need, in whatever form of implementation :-)
Comment #27
chx commentedYou have not answered my problems.
Comment #28
hswong3i commented@chx: Hmmm... so answer it once again: we may use function to wrap the return string, we can use OOP as object method, we can use predefined constant, etc. I choose predefined constant right now since it is the most simple as strict forward solution. We may seems it as temporary and reroll to a better solution whenever it is suitable.
Or may I have your suggested answer? If you hope to reroll it as function callback style, I am please to do so :-)
Comment #29
cburschkaBut why are you using %s-placeholders for these constants? Sorry, but neither of your answers to chx made that clear to me.
Comment #30
chx commentedI still have absolutely no idea why we want this and why this is the best solution. What is your problem in the first that mandates us to write such ugly stuff?
Comment #31
hswong3i commentedThe detail of
'%s'stuff:%%syntax because this is the requirement of PDO prepare statement (see Example#11 for more detail). This idea also applied to the replace of'%s'as%s.%sfor empty string since some database will handle this incorrectly, says MSSQL, DB2 and Oracle.In case of MSSQL, PHP driver will return a space (
) for NULL value stored within database. This is a well know bug for PHP MSSQL driver, which due to the incorrect handling of MSSQL dll provided by Microsoft. In case of Oracle, empty string will seems as NULL in SQL level. This means Oracle will needIS NULLfor normal!= ''checking. The is a bug of Oracle by design.BTW, both of the above bug can be handled within database driver implementation internally. We can handle these edge case within db_escape_string(). So the use of %s for empty string is important, as this will trigger the call of db_escape_string() for further more special handling.
Wait! Up to this point, please forget those hidden and complicated reason, as that would belongs to the duty of database abstraction driver developers and designer. Normal developer only require to follow a simple guideline: always use placeholder correctly, for whatever case (even empty string). DB abstraction layer will handle all of the other crazy stuff :-)
Comment #32
chx commented*shrug* i have better things to do than battle this. Please do not set back to critical. Critical is when a) Drupal is fundamentally broken b) something we can't or don't want to release without. For those, see Dries' posts. I know that this is important to *you* but not to Drupal as a whole.
Comment #33
hswong3i commentedSO D7 *may* without PDO? I don't really think so, and so the
%%and'%s'must be clean up. Are they PDO related stuff?Comment #34
hswong3i commentedPatch via CVS HEAD.
Comment #35
Crell commentedNo longer applicable since DBTNG landed and doesn't use %.