### Eclipse Workspace Patch 1.0 #P cowimas_php Index: lib/Doctrine/DBAL/Query/QueryBuilder.php =================================================================== --- lib/Doctrine/DBAL/Query/QueryBuilder.php (revision 1732) +++ lib/Doctrine/DBAL/Query/QueryBuilder.php (working copy) @@ -44,6 +44,7 @@ const SELECT = 0; const DELETE = 1; const UPDATE = 2; + const INSERT = 3; /** The builder states. */ const STATE_DIRTY = 0; @@ -209,10 +210,14 @@ $sql = ''; switch ($this->type) { + case self::INSERT: + $sql = $this->getSQLForInsert(); + break; + case self::DELETE: $sql = $this->getSQLForDelete(); break; - + case self::UPDATE: $sql = $this->getSQLForUpdate(); break; @@ -508,6 +513,34 @@ } /** + * Turns the query being built into a bulk insert query that inserts into + * a certain table + * + * + * $qb = $conn->createQueryBuilder() + * ->isnert('users', 'u') + * ->set('u.password', md5('password')); + * + * + * @param string $insert The table into which the rows should be inserted. + * @param string $alias The table alias used in the constructed query. + * @return QueryBuilder This QueryBuilder instance. + */ + public function insert($insert = null, $alias = null) + { + $this->type = self::INSERT; + + if ( ! $insert) { + return $this; + } + + return $this->add('from', array( + 'table' => $insert, + 'alias' => $alias + )); + } + + /** * Create and add a query root corresponding to the table identified by the * given alias, forming a cartesian product with any existing query roots. * @@ -996,6 +1029,20 @@ } /** + * Converts this instance into an INSERT string in SQL. + * + * @return string + */ + private function getSQLForInsert() + { + $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); + $query = 'INSERT INTO ' . $table + . ' SET ' . implode(", ", $this->sqlParts['set']); + + return $query; + } + + /** * Converts this instance into a DELETE string in SQL. * * @return string