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.
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?
Use expression() calls in order and you will be fine (but you need to be aware that you need to call in order).
It’s nice! Thanks for sharing.
mi diverto molto con tutti i giochi di lotterie come i gratta e vinci aams ed i giochi aams online con bonus sul deposito