diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-07-21 01:56:36 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-07-21 01:56:36 +0000 |
commit | d2c02ca453f938fb6f8f2c6853f36dfe426ced1f (patch) | |
tree | d447f5810b5f80a0ce1836fa5e1fe591591bbaa4 /includes/database/pgsql | |
parent | 7719a888950f61c68b6645b3e9adc53df46338d4 (diff) | |
download | brdo-d2c02ca453f938fb6f8f2c6853f36dfe426ced1f.tar.gz brdo-d2c02ca453f938fb6f8f2c6853f36dfe426ced1f.tar.bz2 |
#481288 by Berdir and Crell: Add support for INSERT INTO ... SELECT FROM ...
Diffstat (limited to 'includes/database/pgsql')
-rw-r--r-- | includes/database/pgsql/query.inc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/includes/database/pgsql/query.inc b/includes/database/pgsql/query.inc index 489d57e65..ab16a70ec 100644 --- a/includes/database/pgsql/query.inc +++ b/includes/database/pgsql/query.inc @@ -15,19 +15,7 @@ class InsertQuery_pgsql 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)) { - return NULL; - } - - // Don't execute query without values. - if (!isset($this->insertValues[0]) && count($this->insertFields) > 0 && empty($this->fromQuery)) { + if (!$this->preExecute()) { return NULL; } @@ -56,6 +44,11 @@ class InsertQuery_pgsql extends InsertQuery { } } } + if (!empty($this->fromQuery)) { + foreach ($this->fromQuery->getArguments() as $key => $value) { + $stmt->bindParam($key, $value); + } + } // PostgreSQL requires the table name to be specified explicitly // when requesting the last insert ID, so we pass that in via @@ -82,6 +75,8 @@ class InsertQuery_pgsql 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 INTO {" . $this->table . '} (' . implode(', ', $insert_fields) . ') ' . $this->fromQuery; } |