summaryrefslogtreecommitdiff
path: root/includes/database/mysql
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-07-21 01:56:36 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-07-21 01:56:36 +0000
commitd2c02ca453f938fb6f8f2c6853f36dfe426ced1f (patch)
treed447f5810b5f80a0ce1836fa5e1fe591591bbaa4 /includes/database/mysql
parent7719a888950f61c68b6645b3e9adc53df46338d4 (diff)
downloadbrdo-d2c02ca453f938fb6f8f2c6853f36dfe426ced1f.tar.gz
brdo-d2c02ca453f938fb6f8f2c6853f36dfe426ced1f.tar.bz2
#481288 by Berdir and Crell: Add support for INSERT INTO ... SELECT FROM ...
Diffstat (limited to 'includes/database/mysql')
-rw-r--r--includes/database/mysql/query.inc35
1 files changed, 15 insertions, 20 deletions
diff --git a/includes/database/mysql/query.inc b/includes/database/mysql/query.inc
index 84caf0386..09878f96d 100644
--- a/includes/database/mysql/query.inc
+++ b/includes/database/mysql/query.inc
@@ -15,31 +15,24 @@
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.');
- }
-
- if (count($this->insertFields) + count($this->defaultFields) == 0 && empty($this->fromQuery)) {
+ if (!$this->preExecute()) {
return NULL;
}
- // Don't execute query without values.
- if (!isset($this->insertValues[0]) && count($this->insertFields) > 0 && empty($this->fromQuery)) {
- return NULL;
- }
-
- $last_insert_id = 0;
-
- $max_placeholder = 0;
- $values = array();
- foreach ($this->insertValues as $insert_values) {
- foreach ($insert_values as $value) {
- $values[':db_insert_placeholder_' . $max_placeholder++] = $value;
+ // If we're selecting from a SelectQuery, finish building the query and
+ // pass it back, as any remaining options are irrelevant.
+ if (empty($this->fromQuery)) {
+ $max_placeholder = 0;
+ $values = array();
+ foreach ($this->insertValues as $insert_values) {
+ foreach ($insert_values as $value) {
+ $values[':db_insert_placeholder_' . $max_placeholder++] = $value;
+ }
}
}
+ else {
+ $values = $this->fromQuery->getArguments();
+ }
$last_insert_id = $this->connection->query((string)$this, $values, $this->queryOptions);
@@ -56,6 +49,8 @@ class InsertQuery_mysql extends InsertQuery {
// Default fields are always placed first for consistency.
$insert_fields = array_merge($this->defaultFields, $this->insertFields);
+ // If we're selecting from a SelectQuery, finish building the query and
+ // pass it back, as any remaining options are irrelevant.
if (!empty($this->fromQuery)) {
return "INSERT $delay INTO {" . $this->table . '} (' . implode(', ', $insert_fields) . ') ' . $this->fromQuery;
}