If this is not worth doing, feel free to say so.
I just encountered a module that is using back ticks in the SQL code. While this is okay, it's not exactly standard Drupal practice (I haven't checked the standards on this). Should this be checked.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | coder_188975.patch | 1.73 KB | stella |
Comments
Comment #1
douggreen commentedIt's not against coding standards and there's no performance reason not to do it. The only reason I can think not to use back ticks is if it's not ANSI SQL. I suggest that you check the drupal-devel list archives and see if there has been a discussion on this yet, and if not, maybe start one, then report back.
Comment #2
stella commentedI think back ticks are used in MySQL to quote column names, usually for tables where some of the column names are reserved words. So
select * from foo where a=`b`;is essentially equivalent toselect * from foo where a=b;(assuming column name isn't a reserved word).However, doing the same in postgres, gives me the error:
I tried various SQL queries with back ticks in each of the 3 ANSI validators at http://developer.mimer.se/validator/index.htm and they failed with syntax errors in each case. So it's not ANSI SQL. However, there is nothing in the coding standards that says developers have to use ANSI SQL (as far as I'm aware), but it may be a good idea.
If you decide that we should be checking for non-ANSI compliant SQL, then the attached patch should help check for back tick usage in SQL statements. If people could review / test it, that would be great.
However, there are lots of other ANSI compliant checks that could be added too. Perhaps start a discussion on the drupal development mailing list as Doug suggested to see what the community thinks.
Cheers,
Stella
Comment #3
douggreen commentedWhile I'm leaning towards adding this, I think that this is now a 5.x specific problem. Do we care about this with schema api and 6.x?
Comment #4
nancydruThe code I saw it in was not replaceable by schema.
Comment #5
douggreen commentedOh, I see now. I think that were talking about SQL in the .module rather than CREATE statements in the .install file. Of course, if they really needed backticks, they'd also need them in the install file, and those would be replaced by schema. However, I can see where we'd then still have them in the .module SQL.
If testing shows it works, let's commit it.
Comment #6
stella commentedCommitted.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.