Problem/Motivation

Drupal 7 runs with multiple allowed database types, and moreover theses types can be extended by contrib modules.
Some queries within this module are hardcoded with MySQL.

Proposed resolution

Use DatabaseAPI instead of hardcoded SQL for queries.

Comments

Dom. created an issue. See original summary.

gisle’s picture

How do I spot queries that are hardcoded for SQL?

Is there a page pointing out MYSQLisms for Drupal 7 - similar to this one (which focuses on Druapal 6).

dom.’s picture

I'm not aware of such a page for D7. But you should use the DB statement from database API everywhere (see result, insert, update and delete exemples here):
https://www.drupal.org/developing/api/database

In your module, any ligns using db_query("some sql") for insert, update and delete woud not fit any other DB then MySQL. As per said in doc:

 * Use this function for SELECT queries if it is just a simple query string.
 * If the caller or other modules need to change the query, use db_select()
 * instead.
 * Do not use this function for INSERT, UPDATE, or DELETE queries. Those should
 * be handled via db_insert(), db_update() and db_delete() respectively.

  • gisle committed 77cb3ad on 7.x-1.x
    Issue #2678068 by gisle: Removed MYSQLisms
    
gisle’s picture

Status: Needs work » Needs review

In your module, any lines using db_query("some sql") for insert, update and delete would not fit any other DB then MySQL.

Agreed, but there AFAIK no such db_query-calls in the project. As per the doc you cite I only use db_query for simple SELECT statements.

At least, when I grep for this using the following sequence of CLI commands, nothing is found.

grep -E -i 'update|insert|delete' | fgrep db_query
cd modules
grep -E -i 'update|insert|delete' | fgrep db_query
cd ../tests
grep -E -i 'update|insert|delete' | fgrep db_query

However, I found some instances of != (replaced with ANSI compliant <>) and some instances of LIMIT (replaced db_query with db_query_range). As far as I am able to tell, there are no other MySQLisms in the project.

Please review.

gisle’s picture

Status: Needs review » Fixed

This is in release 7.x-1.1.

Status: Fixed » Closed (fixed)

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