[drupal-devel] [feature] generalizing node_rewrite_sql

moshe weitzman drupal-devel at drupal.org
Mon Jan 24 22:43:35 UTC 2005

 Project:      Drupal
 Version:      cvs
 Component:    database system
 Category:     feature requests
 Priority:     normal
 Assigned to:  chx
 Reported by:  chx
 Updated by:   moshe weitzman
 Status:       patch

I'm confusd about who is responsible for calling the rewrite function.
Does it not make sense to run every query through this system (and thus
insert a call into db_query). We already do this for prefixes. perhaps
the hook is too performance draining?

Note that the rewrite sql() hook is not documented on the hooks page:
http://drupaldocs.org/api/head/group/hooks. One would document it by

moshe weitzman

Previous comments:

January 24, 2005 - 13:58 : chx

Attachment: http://drupal.org/files/issues/db_rewrite_sql.patch (7.66 KB)

As I was thinking on the various usages of node_rewrite_sql , it came to
my mind that with very little changes it can be generalized so that any
queries against any table -- not just node -- can be rewritten. I have
moved node_rewrite_sql to database.inc, renamed it db_rewrite_sql,
introduced another necessary parameter, which does not affect the
current (light) usage of node_rewrite_sql. I think the usage is even
clearer now, 'cos I think nid_alias caused some confusion. Now it is
called $primary_table , while the new parameter is called

What this would be good for? One may want to have permission and
languages for taxonomy terms and vocabularies.


January 24, 2005 - 17:08 : Dries

I guess it makes sense to go with a generic approach, though it is
difficult to predict how many queries will end up being wrapped in a
call to db_rewrite_sql() ...  Comments?


January 24, 2005 - 17:28 : Jose A Reyero

I like it!, though I still miss some more info about what the query is
about -the 'hints' stuff- , but it's fine... :-)

But also think there should be some kind of 'guidelines' about wrapping
specific queries or not. For the moment, my candidates are:

- node queries, which means 'queries that select lists of nodes', not
any query which contains 'node'
- taxonomy queries, same here, 'queries that select lists of

Both types of queries above are good candidates for joining permissions
conditions, and maybe language conditions (i18n).

And maybe more in the future.... we'll see.


January 24, 2005 - 17:41 : chx

Attachment: http://drupal.org/files/issues/db_rewrite_sql_0.patch (7.68 KB)

A through test showed that introducing the $primary_key parameter was
done incorrectly, thus the new version. 

View: http://drupal.org/node/16111
Edit: http://drupal.org/project/comments/add/16111

More information about the drupal-devel mailing list