Statement::execute

public Statement::execute($args = array(), $options = array())

Executes a prepared statement

Parameters

$args: An array of values with as many elements as there are bound parameters in the SQL statement being executed.

$options: An array of options for this query.

Return value

TRUE on success, or FALSE on failure.

Overrides StatementPrefetch::execute

File

core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php, line 88

Class

Statement
SQLite implementation of \Drupal\Core\Database\Statement.

Namespace

Drupal\Core\Database\Driver\sqlite

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public function execute($args = array(), $options = array()) {
  try {
    $return = parent::execute($args, $options);
  }
  catch (\PDOException $e) {
    if (!empty($e->errorInfo[1]) && $e->errorInfo[1] === 17) {
      // The schema has changed. SQLite specifies that we must resend the query.
      $return = parent::execute($args, $options);
    }
    else {
      // Rethrow the exception.
      throw $e;
    }
  }
 
  // In some weird cases, SQLite will prefix some column names by the name
  // of the table. We post-process the data, by renaming the column names
  // using the same convention as MySQL and PostgreSQL.
  $rename_columns = array();
  foreach ($this->columnNames as $k => $column) {
    // In some SQLite versions, SELECT DISTINCT(field) will return "(field)"
    // instead of "field".
    if (preg_match("/^\((.*)\)$/", $column, $matches)) {
      $rename_columns[$column] = $matches[1];
      $this->columnNames[$k] = $matches[1];
      $column = $matches[1];
    }
 
    // Remove "table." prefixes.
    if (preg_match("/^.*\.(.*)$/", $column, $matches)) {
      $rename_columns[$column] = $matches[1];
      $this->columnNames[$k] = $matches[1];
    }
  }
  if ($rename_columns) {
    // DatabaseStatementPrefetch already extracted the first row,
    // put it back into the result set.
    if (isset($this->currentRow)) {
      $this->data[0] = &$this->currentRow;
    }
 
    // Then rename all the columns across the result set.
    foreach ($this->data as $k => $row) {
      foreach ($rename_columns as $old_column => $new_column) {
        $this->data[$k][$new_column] = $this->data[$k][$old_column];
        unset($this->data[$k][$old_column]);
      }
    }
 
    // Finally, extract the first row again.
    $this->currentRow = $this->data[0];
    unset($this->data[0]);
  }
 
  return $return;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.