Code coverage for /20081101/includes/database/mysql/database.inc

Line #Times calledCode
1
<?php
2
// $Id: database.inc,v 1.4 2008/10/25 02:03:55 webchick Exp $
3
4
/**
5
 * @file
6
 * Database interface code for MySQL database servers.
7
 */
8
9
/**
10
 * @ingroup database
11
 * @{
12
 */
13
142367
class DatabaseConnection_mysql extends DatabaseConnection {
15
16
  protected $transactionSupport;
17
18
  public function __construct(Array $connection_options = array()) {
19
20
    $connection_options += array(
212369
      'transactions' => FALSE,
222369
      'port' => 3306,
230
    );
242369
    $this->transactionSupport = $connection_options['transactions'];
25
262369
    $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' .
$connection_options['port'] . ';dbname=' . $connection_options['database'];
272369
    parent::__construct($dsn, $connection_options['username'],
$connection_options['password'], array(
28
      // So we don't have to mess around with cursors and unbuffered
queries by default.
292369
      PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
30
      // Because MySQL's prepared statements skip the query cache, because
it's dumb.
312369
      PDO::ATTR_EMULATE_PREPARES => TRUE,
322369
    ));
33
34
    // Force MySQL to use the UTF-8 character set by default.
352369
    $this->exec('SET NAMES "utf8"');
36
37
    // Enable MySQL's "strict mode", which removes most of MySQL's
38
    // "just be lazy" behaviors that end up causing more trouble than
they're worth.
392369
    $this->exec('SET sql_mode=STRICT_ALL_TABLES');
402369
  }
41
42
  public function queryRange($query, Array $args, $from, $count, Array
$options) {
43
    // Backward compatibility hack, temporary.
442477
    $query = str_replace(array('%d' , '%f' , '%b' , "'%s'"), '?', $query);
45
462477
    return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args,
$options);
470
  }
48
49
  public function queryTemporary($query, Array $args, $tablename, $options
= array()) {
500
    $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' .
$tablename . ' Engine=HEAP SELECT', $this->prefixTables($query));
51
520
    return $this->query($query, $args, $options);
530
  }
54
55
  public function driver() {
562487
    return 'mysql';
570
  }
58
59
  public function databaseType() {
600
    return 'mysql';
610
  }
62
63
  public function supportsTransactions() {
640
    return $this->transactionSupport;
650
  }
66
67
  public function escapeTable($table) {
682370
    return preg_replace('/[^A-Za-z0-9_]+/', '', $table);
690
  }
70
71
  public function mapConditionOperator($operator) {
72
    // We don't want to override any of the defaults.
732370
    return NULL;
740
  }
75
76
  /**
77
   * @todo Remove this as soon as db_rewrite_sql() has been exterminated.
78
   */
79
  public function distinctField($table, $field, $query) {
800
    $field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
81
    // (?<!text) is a negative look-behind (no need to rewrite queries that
already use DISTINCT).
820
    return preg_replace('/(SELECT.*)(?:' . $table .
'\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM
)/AUsi', '\1 ' . $field_to_select . '\2', $query);
830
  }
84
}
85
86
87
/**
88
 * @} End of "ingroup database".
89
 */
902367