function _db_query_callback

6.x database.inc _db_query_callback($match, $init = FALSE)

Helper function for db_query().

Related topics

8 calls to _db_query_callback()
db_query in drupal-6.x/includes/database.pgsql.inc
Runs a basic query in the active database.
db_query in drupal-6.x/includes/database.mysql-common.inc
Runs a basic query in the active database.
db_query_range in drupal-6.x/includes/database.pgsql.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysqli.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysql.inc
Runs a limited-range query in the active database.

... See full list

8 string references to '_db_query_callback'
db_query in drupal-6.x/includes/database.pgsql.inc
Runs a basic query in the active database.
db_query in drupal-6.x/includes/database.mysql-common.inc
Runs a basic query in the active database.
db_query_range in drupal-6.x/includes/database.pgsql.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysqli.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysql.inc
Runs a limited-range query in the active database.

... See full list

File

drupal-6.x/includes/database.inc, line 202
Wrapper for database interface code.

Code

function _db_query_callback($match, $init = FALSE) {
  static $args = NULL;
  if ($init) {
    $args = $match;
    return;
  }

  switch ($match[1]) {
    case '%d': // We must use type casting to int to convert FALSE/NULL/(TRUE?)
      $value = array_shift($args);
      // Do we need special bigint handling?
      if ($value > PHP_INT_MAX) {
        $precision = ini_get('precision');
        @ini_set('precision', 16);
        $value = sprintf('%.0f', $value);
        @ini_set('precision', $precision);
      }
      else {
        $value = (int) $value;
      }
      // We don't need db_escape_string as numbers are db-safe.
      return $value;
    case '%s':
      return db_escape_string(array_shift($args));
    case '%n':
      // Numeric values have arbitrary precision, so can't be treated as float.
      // is_numeric() allows hex values (0xFF), but they are not valid.
      $value = trim(array_shift($args));
      return is_numeric($value) && !preg_match('/x/i', $value) ? $value : '0';
    case '%%':
      return '%';
    case '%f':
      return (float) array_shift($args);
    case '%b': // binary data
      return db_encode_blob(array_shift($args));
  }
}