views:

78

answers:

1

I've happened to develop a module in Drupal and due to some seeming View limitations had to use custom SQL. This ran me into some problems with node revisions and I came to conclusion that in Drupal it's best to use its native methods for working with any data. Otherwise, data integrity problems may arise.

And even with desire to optimize SQL queries in Drupal apparently this should be done in rare cases for real bottlenecks.

What are you experiences related to this dilemma - direct sql queries vs. Drupal modules/functions ?

+3  A: 

When updating data you should always use the Drupal default, even if you need to do other queries afterwards for custom tables etc. It is not obvious (without digging into the code) what Drupal does on various actions and if you copy the code for an action and put it in your function you will have to watch for changes in the core from then on.

One trick with views which may help you, is if views has got you almost what you want you can see the query generated by views copy that and put it in your own code. This removes the rest of the overhead of views and can be a big performance boost.

Jeremy French
+1 for always using drupal functions when updating/inserting data - even if you follow the behavior of core modules, you can easily miss stuff that other modules do on the multitude of hook operations. Reading directly from the database is usually ok, but be aware that you might miss data that other modules would add via a hook as well.
Henrik Opel