[support] Better a node_save or a db_query for a single field ?

Gordon Heydon gordon at heydon.com.au
Wed Apr 7 14:49:31 UTC 2010


Hi,

mIf you can I would always recommend using node_save() since it means that you can have this trigger things or allow other developers to expand on your module without you needing to do anything.

I have had this where I have needed to extend an operation when a db_query() is used where as if they had used a node_save() all I would need to add a hook_nodeapi() or even it is was not as complex I could use the the rules module to trigger other things to happen.

I know that it is not as efficient to do a node_save() but it does allow alot more extendability.

Gordon.

On 07/04/2010, at 8:23 PM, Shawn(Xiangyu) Meng wrote:

> I think db_query is better, but make sure to clear the cache after the db update.
> 
> cache_clear_all('content:'.$node->nid ,'cache_content', TRUE);
> 
> 
> 孟祥宇
> Shawn Meng
> 
> blog: http://mengxy.net
> twitter: @mengxy
> 
> 
> On Wed, Apr 7, 2010 at 5:42 PM, Michel Morelli <michel at ziobuddalabs.it> wrote:
> Hi all. I have a content type with a cck integer field and I need to
> increment it when user click on a link (user is redirect to another
> page, or similar).
> 
> To do this I have two option:
> 1) node_save
> 2) db_query
> 
> This node type has a total of 5 cck fields. Other fields does not change
> when user click on that link.
> My site would be a trafficated site so I could have 10 or 100 clicks on
> that link in a single moment.
> 
> I think to this code (for sql query solution):
> 
> db_query("LOCK TABLES {content_type_gf_product} WRITE,{watchdog} WRITE");
> db_query("UPDATE {content_type_my_type}  set  field_download_stats_value
> = field_download_stats_value+1 where nid = %d and vid = %d",
> $node->nid,$node->vid);
> db_query("UNLOCK TABLES");
> 
> Tnx.
> 
> --
> Michel 'ZioBudda' Morelli                       michel at ziobuddalabs.it
> Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
> Telefono: 0200619074
> Telefono Cell: +39-3939890025 --  Fax: +39-0291390660
> 
> http://www.ziobudda.net                         ICQ: 58351764
> http://www.ziobuddalabs.it                      Skype: zio_budda
> http://www.ziodrupal.net                        MSN: michel at ziobuddalabs.it
>                                                JABBER: michel at ziobuddalabs.it
> 
> --
> [ Drupal support list | http://lists.drupal.org/ ]
> 
> -- 
> [ Drupal support list | http://lists.drupal.org/ ]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20100408/29e30869/attachment.html 


More information about the support mailing list