_db_query_process_args

Definition

_db_query_process_args($query, $args, $options)
drupal/includes/database/database.inc, line 2239

Description

Backward-compatibility utility.

This function should be removed after all queries have been converted to the new API. It is temporary only.

@todo Remove this once the query conversion is complete.

Related topics

Namesort iconDescription
Database abstraction layerAllow the use of different database servers using the same code base.

Code

function _db_query_process_args($query, $args, $options) {

  if (!is_array($options)) {
    $options = array();
  }
  if (empty($options['target'])) {
    $options['target'] = 'default';
  }

  // Temporary backward-compatibliity hacks.  Remove later.
  $old_query = $query;
  $query = str_replace(array('%n', '%d', '%f', '%b', "'%s'", '%s'), '?', $old_query);
  if ($old_query !== $query) {
    $args = array_values($args);  // The old system allowed named arrays, but PDO doesn't if you use ?.
  }

  // A large number of queries pass FALSE or empty-string for
  // int/float fields because the previous version of db_query()
  // casted them to int/float, resulting in 0.  MySQL PDO happily
  // accepts these values as zero but PostgreSQL PDO does not, and I
  // do not feel like tracking down and fixing every such query at
  // this time.
  if (preg_match_all('/%([dsfb])/', $old_query, $m) > 0) {
    foreach ($m[1] as $idx => $char) {
      switch ($char) {
        case 'd':
          $args[$idx] = (int) $args[$idx];
          break;
        case 'f':
          $args[$idx] = (float) $args[$idx];
          break;
      }
    }
  }

  return array($query, $args, $options);
}