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
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

Pasqualle - June 16, 2008 - 13:35
Title:constant vaues in db_query» constant values in db_query

#2

gpk - June 17, 2008 - 11:51
Status:active» active (needs more info)

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

Pasqualle - June 17, 2008 - 13:01

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

gpk - June 17, 2008 - 14:22

>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

Pasqualle - June 17, 2008 - 15:25

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

Pasqualle - June 17, 2008 - 15:22

#7

Pasqualle - June 17, 2008 - 15:28
Status:active (needs more info)» active

#8

add1sun - June 17, 2008 - 16:01

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

catch - July 1, 2008 - 12:05
Status:active» fixed

Removed.

#10

gpk - July 1, 2008 - 12:19
Status:fixed» active

Should this also be fixed (http://drupal.org/node/2497):

User-supplied arguments should be moved out of the query body and passed in as separate parameters to db_query(), db_query_range(), and db_query_temporary(), etc. The query body should only contain placeholders specifying the type of the arguments (%d|%s|%%|%f|%b). This ensures that the data will be properly escaped and avoids SQL injection attacks.

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

catch - July 1, 2008 - 12:54

@gpk - looks like it. More stuff added by hswong3i - revision diff here: http://drupal.org/node/2497/revisions/view/190378/190800

#12

gpk - July 4, 2008 - 10:12
Status:active» patch (code needs review)

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

Pasqualle - July 4, 2008 - 11:37

the db_query example is still incorrect on that page (2479)
should be changed to a real example from drupal core

#14

gpk - July 4, 2008 - 11:58

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:

<?php
db_query
("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'php', 0, 0)", $format);
?>

#15

Pasqualle - July 4, 2008 - 12:59

yes, that's better

#16

gpk - July 4, 2008 - 13:03

#17

catch - July 4, 2008 - 13:47
Status:patch (code needs review)» fixed

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

gpk - July 4, 2008 - 14:17

OK great :)

#19

Pasqualle - July 4, 2008 - 14:40

thanks Giles

#20

Anonymous (not verified) - July 23, 2008 - 10:56
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.