How to use use db_rewrite_sql() with db_query() in D7? I read article where it was written to use db_rewrite_sql($query). In Drupal 7, you need to use addTag('node_access') along with `db_select().

I have  a query with 8 columns and 4 conditions; for simplicity I am using db_query().

How can I use db_rewrite_sql() with db_query()?
You have to use db_select() with the addTag() modifier.

The query you mention doesn't sound too crazy so it should be fine for db_select().
The only downside is it can be a bit slower.

As per the db_query() api docs:


  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.