The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

MySQL UPDATE and Drupal 7

Submitted by nk on Mon, 2010-08-23 12:31

Let's say you have an UPDATE query which uses old values to calculate new ones. The best example for now is swapping two columns: UPDATE table SET f1 = f2, f2 = f1. There is one SQL engine as far as I am aware where this breaks: MySQL (it works on PostgreSQL, SQLite and MS SQL). On MySQL, f1 and f2 both will have the old value of f2 instead of swapping. With the Drupal 7 database layer, you use expressions to create such a query and they are executed in the same order as the methods are called so you can take care of this problem.

Also note that fields are executed after expressions but if you need to interleave the two then it's possible to convert fields to expressions: instead of fields(array('f1' => $f1)) you can write expression('f1', ':placeholder_f1', array(':placeholder_f1' => $f1) (the name of the placeholder can be just :f1 or anything else).

An example can be found in _menu_link_move_children.

Commenting on this Story is closed.

Submitted by Island Usurper (not verified) on Mon, 2010-08-23 16:12.

So, _menu_link_move_children() makes sense because the values are being updated so that the further-right columns get their neighbor's old value before that neighbor is changed. But if MySQL can't just swap column values, there isn't much that Drupal 7 can do about it, right?

Is this article proposing a solution to that and I've just missed it, or is it giving advice to query writers to be particularly careful with this kind of query?

Submitted by nk on Mon, 2010-08-23 17:17.

Use expression() calls in order and you will be fine (but you need to be aware that you need to call in order).

Submitted by chanel (not verified) on Thu, 2010-09-16 08:16.

It’s nice! Thanks for sharing.

Submitted by pollo on Sat, 2010-10-16 13:17.

mi diverto molto con tutti i giochi di lotterie come i gratta e vinci aams ed i giochi aams online con bonus sul deposito