From d2c02ca453f938fb6f8f2c6853f36dfe426ced1f Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Tue, 21 Jul 2009 01:56:36 +0000 Subject: #481288 by Berdir and Crell: Add support for INSERT INTO ... SELECT FROM ... --- includes/database/pgsql/query.inc | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'includes/database/pgsql') 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; } -- cgit v1.2.3