I am wondering how best to change update_sql commands for Drupal 6 modules. I know that update_sql does not to %-placeholder substitution (although previous patches suggest that it was considered and rejected -- eg http://drupal.org/node/36324), but now we also need to remove literals from db_query (http://drupal.org/node/114774#db-query-standard) and so in effect from update_sql as well. This seems to make update_sql much less useful. I looked through how the core modules deal with this and they do not seem consistent to me, and also do not seem to be following the dq_query change either. Some examples from system.install: $ret[] = update_sql("UPDATE {profile_fields} SET category = 'Account settings' WHERE LOWER(category) = 'account'"); $ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid"); In many other cases the update is done using db_query and then something like: $ret[] = array('success' => TRUE, 'query' => "My query"); is used. But if the db_query failed this will still appear as a success and the only error message will be in the normal error message (which presumably may only be logged and not displayed in some cases). What is the best way to deal with this? Thanks, Kieran
Quoting Kieran Parsons <kp.0987@gmail.com>:
I am wondering how best to change update_sql commands for Drupal 6 modules. I know that update_sql does not to %-placeholder substitution (although previous patches suggest that it was considered and rejected -- eg http://drupal.org/node/36324), but now we also need to remove literals from db_query (http://drupal.org/node/114774#db-query-standard) and so in effect from update_sql as well.
This seems to make update_sql much less useful. I looked through how the core modules deal with this and they do not seem consistent to me, and also do not seem to be following the dq_query change either. Some examples from system.install:
$ret[] = update_sql("UPDATE {profile_fields} SET category = 'Account settings' WHERE LOWER(category) = 'account'");
$sql[] = "UPDATE {profile_files} SET category = '%s' WHERE LOWER(category) = '%s'"; $sql[] = 'Account settings'; $sql[] = 'account'; $ret[] = update_sql($sql);
$ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid");
Ditto.
In many other cases the update is done using db_query and then something like: $ret[] = array('success' => TRUE, 'query' => "My query");
The update_sql returns an array with the result like this but uses !== FALSE for the success value.
is used. But if the db_query failed this will still appear as a success and the only error message will be in the normal error message (which presumably may only be logged and not displayed in some cases).
What is the best way to deal with this?
I'm not sure. Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
On Fri, Feb 29, 2008 at 8:01 AM, Earnie Boyd <earnie@users.sourceforge.net> wrote:
$sql[] = "UPDATE {profile_files} SET category = '%s' WHERE LOWER(category) = '%s'"; $sql[] = 'Account settings'; $sql[] = 'account'; $ret[] = update_sql($sql);
I guess this was an example of how it could work but doesn't? update_sql and db_query need a string as their argument and first argument, respectively. --mark
Quoting mark burdett <mfburdett@gmail.com>:
On Fri, Feb 29, 2008 at 8:01 AM, Earnie Boyd <earnie@users.sourceforge.net> wrote:
$sql[] = "UPDATE {profile_files} SET category = '%s' WHERE LOWER(category) = '%s'"; $sql[] = 'Account settings'; $sql[] = 'account'; $ret[] = update_sql($sql);
I guess this was an example of how it could work but doesn't? update_sql and db_query need a string as their argument and first argument, respectively.
Sorry, yes, I misread db_query. What good is update_sql then? Hmm... I find a two plus years old ticket for this [1]. [1] http://drupal.org/node/36324 Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
Moreover, update_sql() does not accept % arguments. It only accepts one argument with is the SQL, so you have to concatenate what you need apriori. On Fri, Feb 29, 2008 at 3:05 PM, Earnie Boyd <earnie@users.sourceforge.net> wrote:
Quoting mark burdett <mfburdett@gmail.com>:
On Fri, Feb 29, 2008 at 8:01 AM, Earnie Boyd <earnie@users.sourceforge.net> wrote:
$sql[] = "UPDATE {profile_files} SET category = '%s' WHERE LOWER(category) = '%s'"; $sql[] = 'Account settings'; $sql[] = 'account'; $ret[] = update_sql($sql);
I guess this was an example of how it could work but doesn't? update_sql and db_query need a string as their argument and first argument, respectively.
Sorry, yes, I misread db_query. What good is update_sql then? Hmm... I find a two plus years old ticket for this [1].
-- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting.
participants (4)
-
Earnie Boyd -
Khalid Baheyeldin -
Kieran Parsons -
mark burdett