constant values in db_query
Pasqualle - June 16, 2008 - 13:29
| Project: | Documentation |
| Component: | Coding standards |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Point 4 in this part of the document does not comply with drupal 6 coding standards, and should not be enforced.
http://drupal.org/node/114774#db-query-standard

#1
#2
Can you clarify in what way point 4 does not comply with D6 coding standards http://drupal.org/node/2497#formatting? I can't see the discrepancy :-?
#3
Because as I see drupal 6 core does not follow this standard. I will try to count all the examples in drupal core, and all issues where such modification in core was rejected..
#4
>as I see drupal 6 core does not follow this standard.
Ahhhh...!
>count all the examples in drupal core, and all issues where such modification in core was rejected.
Hmmm curious..!
#5
counts in drupal core
rule broken vs compliance with the rule
includes dir:
13:8
modules dir:
20:1
I just stopped counting, the one was for better visibility not because the developer wanted to follow this rule. You can hardly find any occurrence in modules directory where this rule applies..
So, this rule is not a coding standard for drupal 6, never was..
#6
quick search for rejected issues
#175704: SQL cleanup: /includes
#175825: SQL cleanup: aggregator
#175826: SQL cleanup: block
#7
#8
This was added to the page by hswong who was also the one trying to get the cleanup patches in. See the revision diff here: http://drupal.org/node/114774/revisions/view/189503/190765
It looks like even though he conceded this did not need to change (http://drupal.org/node/175704#comment-605038) he never went back and cleaned up the handbook page edits he made.
So basically yes, his changes didn't go in and that info needs to be removed from the page since it never really belonged there. I don't have time to do this myself right now.
#9
Removed.
#10
Should this also be fixed (http://drupal.org/node/2497):
Avoiding SQL injection is one thing, but I think we are saying that it's currently OK to have literal values *in* the query body?
#11
@gpk - looks like it. More stuff added by hswong3i - revision diff here: http://drupal.org/node/2497/revisions/view/190378/190800
#12
Well it's not a patch but I'd be grateful if someone could check that my edits make sense!
http://drupal.org/node/2497/revisions/view/303850/320192
Ta.
#13
the db_query example is still incorrect on that page (2479)
should be changed to a real example from drupal core
#14
From a quick grep I'd say core is not 100% consistent about whether or when literals should be included in the body vs. substituted in via placeholders.
Maybe this example from php.install is a more useful illustration:
<?phpdb_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'php', 0, 0)", $format);
?>
#15
yes, that's better
#16
OK try now http://drupal.org/node/2497.
#17
Looks good to me. In general that page reads a bit abruptly, but that's not one for this issue (and wasn't introduced by it either).
#18
OK great :)
#19
thanks Giles
#20
Automatically closed -- issue fixed for two weeks with no activity.