Simpletest Coverage - includes/database/mysql/database.inc

1 <?php
2 // $Id: database.inc,v 1.17 2009/03/25 18:43:01 webchick Exp $
3
4 /**
5 * @file
6 * Database interface code for MySQL database servers.
7 */
8
9 /**
10 * @ingroup database
11 * @{
12 */
13
14 class DatabaseConnection_mysql extends DatabaseConnection {
15
16 public function __construct(array $connection_options = array()) {
17 // This driver defaults to non transaction support.
18 $this->transactionSupport = !empty($connection_options['transactions']);
19
20 // MySQL never supports transactional DDL.
21 $this->transactionalDDLSupport = FALSE;
22
23 // Default to TCP connection on port 3306.
24 if (empty($connection_options['port'])) {
25 $connection_options['port'] = 3306;
26 }
27
28 $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . $connection_options['port'] . ';dbname=' . $connection_options['database'];
29 parent::__construct($dsn, $connection_options['username'], $connection_options['password'], array(
30 // So we don't have to mess around with cursors and unbuffered queries by default.
31 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
32 // Because MySQL's prepared statements skip the query cache, because it's dumb.
33 PDO::ATTR_EMULATE_PREPARES => TRUE,
34 // Force column names to lower case.
35 PDO::ATTR_CASE => PDO::CASE_LOWER,
36 ));
37
38 // Force MySQL to use the UTF-8 character set by default.
39 $this->exec('SET NAMES "utf8"');
40
41 // Force MySQL's behavior to conform more closely to SQL standards.
42 // This allows Drupal to run almost seamlessly on many different
43 // kinds of database systems. These settings force MySQL to behave
44 // the same as postgresql, or sqlite in regards to syntax interpretation
45 // and invalid data handling. See http://drupal.org/node/344575 for further disscussion.
46 $this->exec("SET sql_mode='ANSI,TRADITIONAL'");
47 }
48
49 public function queryRange($query, array $args, $from, $count, array $options = array()) {
50 return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
51 }
52
53 public function queryTemporary($query, array $args, array $options = array()) {
54 $tablename = $this->generateTemporaryTableName();
55 $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} Engine=MEMORY SELECT', $query), $args, $options);
56 return $tablename;
57 }
58
59 public function driver() {
60 return 'mysql';
61 }
62
63 public function databaseType() {
64 return 'mysql';
65 }
66
67 public function mapConditionOperator($operator) {
68 // We don't want to override any of the defaults.
69 return NULL;
70 }
71
72 /**
73 * @todo Remove this as soon as db_rewrite_sql() has been exterminated.
74 */
75 public function distinctField($table, $field, $query) {
76 $field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
77 // (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
78 return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
79 }
80 }
81
82
83 /**
84 * @} End of "ingroup database".
85 */
86

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.