getStatement

  1. drupal
    1. drupal7
Versionen
drupal7 protected DatabaseStatement_sqlite::getStatement($query, &$args = array())

SQLite specific implementation of getStatement().

The PDO SQLite layer doesn't replace numeric placeholders in queries correctly, and this makes numeric expressions (such as COUNT(*) >= :count) fail. We replace numeric placeholders in the query ourselves to work around this bug.

See http://bugs.php.net/bug.php?id=45259 for more details.

Verwandte Themen

Code

includes/database/sqlite/database.inc, line 182

<?php
protected function getStatement($query, &$args = array()) {
  if (count($args)) {
    // Check if $args is a simple numeric array.
    if (range(0, count($args) - 1) === array_keys($args)) {
      // In that case, we have unnamed placeholders.
      $count = 0;
      $new_args = array();
      foreach ($args as $value) {
        if (is_numeric($value)) {
          $query = substr_replace($query, $value, strpos($query, '?'), 1);
        }
        else {
          $placeholder = ':db_statement_placeholder_' . $count++;
          $query = substr_replace($query, $placeholder, strpos($query, '?'), 1);
          $new_args[$placeholder] = $value;
        }
      }
      $args = $new_args;
    }
    else {
      // Else, this is using named placeholders.
      foreach ($args as $placeholder => $value) {
        if (is_numeric($value)) {
          // We will remove this placeholder from the query and PDO throws an
          // exception if the number of placeholders in the query and the
          // arguments does not match.
          unset($args[$placeholder]);
          // PDO allows placeholders to not be prefixed by a colon. See
          // http://marc.info/?l=php-internals&m=111234321827149&w=2 for
          // more.
          if ($placeholder[0] != ':') {
            $placeholder = ":$placeholder";
          }
          // When replacing the placeholders, make sure we search for the
          // exact placeholder. For example, if searching for
          // ':db_placeholder_1', do not replace ':db_placeholder_11'.
          $query = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $query);
        }
      }
    }
  }

  return $this->dbh->PDOPrepare($query);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen