Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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()?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
is there no alternative to db_select() ? can I not write a query using db_query. –  harshal Aug 16 '13 at 12:55
1  
Not for a db_rewrite_sql() equivalent. –  rooby Aug 16 '13 at 13:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.