summaryrefslogtreecommitdiff
path: root/includes/database
diff options
context:
space:
mode:
Diffstat (limited to 'includes/database')
-rw-r--r--includes/database/mysql/query.inc24
-rw-r--r--includes/database/mysql/schema.inc66
-rw-r--r--includes/database/pgsql/database.inc6
-rw-r--r--includes/database/pgsql/query.inc26
-rw-r--r--includes/database/pgsql/schema.inc2
5 files changed, 62 insertions, 62 deletions
diff --git a/includes/database/mysql/query.inc b/includes/database/mysql/query.inc
index 60eb73c42..ed32411a4 100644
--- a/includes/database/mysql/query.inc
+++ b/includes/database/mysql/query.inc
@@ -9,13 +9,13 @@
class InsertQuery_mysql extends InsertQuery {
public function execute() {
-
+
// Confirm that the user did not try to specify an identical
// field and default field.
if (array_intersect($this->insertFields, $this->defaultFields)) {
throw new PDOException('You may not specify the same field to have a value and a schema-default value.');
}
-
+
$last_insert_id = 0;
$max_placeholder = 0;
@@ -37,10 +37,10 @@ class InsertQuery_mysql extends InsertQuery {
public function __toString() {
$delay = $this->queryOptions['delay'] ? 'DELAYED' : '';
-
+
// Default fields are always placed first for consistency.
$insert_fields = array_merge($this->defaultFields, $this->insertFields);
-
+
$query = "INSERT $delay INTO {" . $this->table . '} (' . implode(', ', $insert_fields) . ') VALUES ';
$max_placeholder = 0;
@@ -48,11 +48,11 @@ class InsertQuery_mysql extends InsertQuery {
if (count($this->insertValues)) {
foreach ($this->insertValues as $insert_values) {
$placeholders = array();
-
+
// Default fields aren't really placeholders, but this is the most convenient
// way to handle them.
$placeholders = array_pad($placeholders, count($this->defaultFields), 'default');
-
+
$new_placeholder = $max_placeholder + count($insert_values);
for ($i = $max_placeholder; $i < $new_placeholder; ++$i) {
$placeholders[] = ':db_insert_placeholder_'. $i;
@@ -87,7 +87,7 @@ class MergeQuery_mysql extends MergeQuery {
unset($update_fields[$exclude_field]);
}
}
-
+
$insert_fields = $this->insertFields + $this->keyFields;
$max_placeholder = 0;
@@ -106,7 +106,7 @@ class MergeQuery_mysql extends MergeQuery {
}
unset($update_fields[$field]);
}
-
+
// Because we filter $fields the same way here and in __toString(), the
// placeholders will all match up properly.
$max_placeholder = 0;
@@ -119,7 +119,7 @@ class MergeQuery_mysql extends MergeQuery {
return $last_insert_id;
}
-
+
public function __toString() {
// Set defaults.
@@ -134,7 +134,7 @@ class MergeQuery_mysql extends MergeQuery {
unset($update_fields[$exclude_field]);
}
}
-
+
$insert_fields = $this->insertFields + $this->keyFields;
$query = "INSERT INTO {" . $this->table . '} (' . implode(', ', array_keys($insert_fields)) . ') VALUES ';
@@ -147,7 +147,7 @@ class MergeQuery_mysql extends MergeQuery {
}
$query .= '(' . implode(', ', $values) . ') ON DUPLICATE KEY UPDATE ';
-
+
// Expressions take priority over literal fields, so we process those first
// and remove any literal fields that conflict.
$max_placeholder = 0;
@@ -160,7 +160,7 @@ class MergeQuery_mysql extends MergeQuery {
foreach ($update_fields as $field => $value) {
$update[] = ($field . '=:db_update_placeholder_' . $max_placeholder++);
}
-
+
$query .= implode(', ', $update);
return $query;
diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc
index 969912cdf..afea775df 100644
--- a/includes/database/mysql/schema.inc
+++ b/includes/database/mysql/schema.inc
@@ -17,7 +17,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
public function tableExists($table) {
return (bool) $this->connection->query("SHOW TABLES LIKE '{" . $table . "}'", array(), array())->fetchField();
}
-
+
public function columnExists($table, $column) {
return (bool) $this->connection->query("SHOW COLUMNS FROM {" . $this->escapeTable($table) . "} LIKE '" . $this->escapeTable($column) . "'", array(), array())->fetchField();
}
@@ -37,25 +37,25 @@ class DatabaseSchema_mysql extends DatabaseSchema {
if (empty($table['mysql_suffix'])) {
$table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */";
}
-
+
$sql = "CREATE TABLE {" . $name . "} (\n";
-
+
// Add the SQL statement for each field.
foreach ($table['fields'] as $field_name => $field) {
$sql .= $this->createFieldSql($field_name, $this->processField($field)) . ", \n";
}
-
+
// Process keys & indexes.
$keys = $this->createKeysSql($table);
if (count($keys)) {
$sql .= implode(", \n", $keys) . ", \n";
}
-
+
// Remove the last comma and space.
$sql = substr($sql, 0, -3) . "\n) ";
-
+
$sql .= $table['mysql_suffix'];
-
+
return array($sql);
}
@@ -72,40 +72,40 @@ class DatabaseSchema_mysql extends DatabaseSchema {
*/
protected function createFieldSql($name, $spec) {
$sql = "`" . $name . "` " . $spec['mysql_type'];
-
+
if (isset($spec['length'])) {
$sql .= '(' . $spec['length'] . ')';
}
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
}
-
+
if (!empty($spec['unsigned'])) {
$sql .= ' unsigned';
}
-
+
if (!empty($spec['not null'])) {
$sql .= ' NOT NULL';
}
-
+
if (!empty($spec['auto_increment'])) {
$sql .= ' auto_increment';
}
-
+
if (isset($spec['default'])) {
if (is_string($spec['default'])) {
$spec['default'] = "'" . $spec['default'] . "'";
}
$sql .= ' DEFAULT ' . $spec['default'];
}
-
+
if (empty($spec['not null']) && !isset($spec['default'])) {
$sql .= ' DEFAULT NULL';
}
-
+
return $sql;
}
-
+
/**
* Set database-engine specific properties for a field.
*
@@ -113,21 +113,21 @@ class DatabaseSchema_mysql extends DatabaseSchema {
* A field description array, as specified in the schema documentation.
*/
protected function processField($field) {
-
+
if (!isset($field['size'])) {
$field['size'] = 'normal';
}
-
+
// Set the correct database-engine specific datatype.
if (!isset($field['mysql_type'])) {
$map = db_type_map();
$field['mysql_type'] = $map[$field['type'] . ':' . $field['size']];
}
-
+
if ($field['type'] == 'serial') {
$field['auto_increment'] = TRUE;
}
-
+
return $field;
}
@@ -138,41 +138,41 @@ class DatabaseSchema_mysql extends DatabaseSchema {
static $map = array(
'varchar:normal' => 'VARCHAR',
'char:normal' => 'CHAR',
-
+
'text:tiny' => 'TINYTEXT',
'text:small' => 'TINYTEXT',
'text:medium' => 'MEDIUMTEXT',
'text:big' => 'LONGTEXT',
'text:normal' => 'TEXT',
-
+
'serial:tiny' => 'TINYINT',
'serial:small' => 'SMALLINT',
'serial:medium' => 'MEDIUMINT',
'serial:big' => 'BIGINT',
'serial:normal' => 'INT',
-
+
'int:tiny' => 'TINYINT',
'int:small' => 'SMALLINT',
'int:medium' => 'MEDIUMINT',
'int:big' => 'BIGINT',
'int:normal' => 'INT',
-
+
'float:tiny' => 'FLOAT',
'float:small' => 'FLOAT',
'float:medium' => 'FLOAT',
'float:big' => 'DOUBLE',
'float:normal' => 'FLOAT',
-
+
'numeric:normal' => 'DECIMAL',
-
+
'blob:big' => 'LONGBLOB',
'blob:normal' => 'BLOB',
-
+
'datetime:normal' => 'DATETIME',
);
return $map;
}
-
+
@@ -195,7 +195,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
return $keys;
}
-
+
protected function createKeySql($fields) {
$ret = array();
foreach ($fields as $field) {
@@ -225,7 +225,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
public function renameTable(&$ret, $table, $new_name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
}
-
+
public function dropTable(&$ret, $table) {
$ret[] = update_sql('DROP TABLE {' . $table . '}');
}
@@ -265,7 +265,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
else {
$default = is_string($default) ? "'$default'" : $default;
}
-
+
$ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN ' . $field . ' SET DEFAULT ' . $default);
}
@@ -276,7 +276,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
public function addPrimaryKey(&$ret, $table, $fields) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
}
-
+
public function dropPrimaryKey(&$ret, $table) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
}
@@ -288,7 +288,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
public function dropUniqueKey(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP KEY ' . $name);
}
-
+
public function addIndex(&$ret, $table, $name, $fields) {
$query = 'ALTER TABLE {' . $table . '} ADD INDEX ' . $name . ' (' . $this->createKeySql($fields) . ')';
$ret[] = update_sql($query);
@@ -297,7 +297,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
public function dropIndex(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP INDEX ' . $name);
}
-
+
public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
$sql = 'ALTER TABLE {' . $table . '} CHANGE ' . $field . ' ' . $this->createFieldSql($field_new, $this->processField($spec));
if (count($keys_new)) {
diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc
index 85a8e8315..166811235 100644
--- a/includes/database/pgsql/database.inc
+++ b/includes/database/pgsql/database.inc
@@ -33,7 +33,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
public function query($query, Array $args = array(), $options = array()) {
$options += $this->defaultOptions();
-
+
try {
if ($query instanceof DatabaseStatement) {
$stmt = $query;
@@ -43,7 +43,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
$stmt = $this->prepareQuery($query);
$stmt->execute($args, $options);
}
-
+
switch ($options['return']) {
case Database::RETURN_STATEMENT:
return $stmt;
@@ -74,7 +74,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
return NULL;
}
}
-
+
public function queryRange($query, Array $args, $from, $count, Array $options) {
// Backward compatibility hack, temporary.
$query = str_replace(array('%d' , '%f' , '%b' , "'%s'"), '?', $query);
diff --git a/includes/database/pgsql/query.inc b/includes/database/pgsql/query.inc
index 4f3a08da6..dc9054a99 100644
--- a/includes/database/pgsql/query.inc
+++ b/includes/database/pgsql/query.inc
@@ -13,9 +13,9 @@ class InsertQuery_pgsql extends InsertQuery {
parent::__construct($connection, $table, $options);
$this->queryOptions['return'] = Database::RETURN_NULL;
}
-
+
public function execute() {
-
+
// Confirm that the user did not try to specify an identical
// field and default field.
if (array_intersect($this->insertFields, $this->defaultFields)) {
@@ -53,13 +53,13 @@ class InsertQuery_pgsql extends InsertQuery {
// when requesting the last insert ID, so we pass that in via
// the options array.
$options = $this->queryOptions;
-
+
if ($schema['fields'][$schema['primary key'][0]]['type'] == 'serial') {
$options['sequence_name'] = $this->connection->makeSequenceName($this->table, $schema['primary key'][0]);
$options['return'] = Database::RETURN_INSERT_ID;
}
$last_insert_id = $this->connection->query($stmt, array(), $options);
-
+
// Re-initialize the values array so that we can re-use this query.
$this->insertValues = array();
@@ -67,7 +67,7 @@ class InsertQuery_pgsql extends InsertQuery {
}
public function __toString() {
-
+
// Default fields are always placed first for consistency.
$insert_fields = array_merge($this->defaultFields, $this->insertFields);
@@ -78,11 +78,11 @@ class InsertQuery_pgsql extends InsertQuery {
if (count($this->insertValues)) {
foreach ($this->insertValues as $insert_values) {
$placeholders = array();
-
+
// Default fields aren't really placeholders, but this is the most convenient
// way to handle them.
$placeholders = array_pad($placeholders, count($this->defaultFields), 'default');
-
+
$new_placeholder = $max_placeholder + count($insert_values);
for ($i = $max_placeholder; $i < $new_placeholder; ++$i) {
$placeholders[] = ':db_insert_placeholder_' . $i;
@@ -103,18 +103,18 @@ class InsertQuery_pgsql extends InsertQuery {
}
}
-class UpdateQuery_pgsql extends UpdateQuery {
+class UpdateQuery_pgsql extends UpdateQuery {
public function execute() {
$max_placeholder = 0;
$blobs = array();
$blob_count = 0;
-
+
$schema = drupal_get_schema($this->table);
-
+
// Because we filter $fields the same way here and in __toString(), the
// placeholders will all match up properly.
$stmt = $this->connection->prepareQuery((string)$this);
-
+
// Expressions take priority over literal fields, so we process those first
// and remove any literal fields that conflict.
$fields = $this->fields;
@@ -130,7 +130,7 @@ class UpdateQuery_pgsql extends UpdateQuery {
}
unset($fields[$field]);
}
-
+
foreach ($fields as $field => &$value) {
$placeholder = ':db_update_placeholder_' . ($max_placeholder++);
@@ -160,7 +160,7 @@ class UpdateQuery_pgsql extends UpdateQuery {
$options = $this->queryOptions;
$options['already_prepared'] = TRUE;
$this->connection->query($stmt, $options);
-
+
//$stmt->execute(NULL, $this->queryOptions);
return $stmt->rowCount();
}
diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc
index fa817c4d1..c98818a26 100644
--- a/includes/database/pgsql/schema.inc
+++ b/includes/database/pgsql/schema.inc
@@ -16,7 +16,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
public function tableExists($table) {
return (bool) db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '{" . db_escape_table($table) . "}'"));
}
-
+
public function columnExists($table, $column) {
return (bool) db_result(db_query("SELECT COUNT(pg_attribute.attname) FROM pg_class, pg_attribute WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relname = '{" . db_escape_table($table) . "}' AND attname = '" . db_escape_table($column) . "'"));
}