[DDC-2313] Deep clone for DBAL QueryBuilder Created: 21/Feb/13  Updated: 21/Feb/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.2
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Tim Mundt Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This is basically a duplicate of another issue I stumbled across lately but cannot find here again. It added a __clone() function to the ORM QueryBuilder to allow this use case:
Create a base query and derive two different queries from it.

I adopted the code for the DBAL QueryBuilder which is suffering the same issue (e.g. expressions were not cloned but shared between instances). The code is tested at least for my limited use case.

/**

  • Deep clone of all expression objects in the SQL parts.
    *
  • @return void
    */
    public function __clone()
    {
    foreach ($this->sqlParts as $part => $elements) {
    if (is_array($this->sqlParts[$part])) {
    foreach ($this->sqlParts[$part] as $idx => $element)
    Unknown macro: { if (is_object($element)) { $this->sqlParts[$part][$idx] = clone $element; } }

    } else if (is_object($elements))

    { $this->sqlParts[$part] = clone $elements; }

    }

$params = array();

foreach ($this->params as $param)

{ $params[] = clone $param; }

$this->params = $params;
}


Generated at Mon May 20 07:46:30 UTC 2013 using JIRA 5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5.