Changeset 5031

Show
Ignore:
Timestamp:
10/02/08 04:59:32 (9 months ago)
Author:
jwage
Message:

[1.1] fixes #1460 Allowing a update() or delete() query to be turned in to a select()

Location:
branches/1.1
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine/Query/Abstract.php

    r5024 r5031  
    15591559     * @return Doctrine_Query 
    15601560     */ 
    1561     public function select($select) 
    1562     { 
    1563         return $this->_addDqlQueryPart('select', $select); 
     1561    public function select($select = null) 
     1562    { 
     1563        $this->_type = self::SELECT; 
     1564        if ($select) { 
     1565            return $this->_addDqlQueryPart('select', $select); 
     1566        } else { 
     1567            return $this; 
     1568        } 
    15641569    } 
    15651570 
  • branches/1.1/tests/Query/SelectTestCase.php

    r5014 r5031  
    109109    } 
    110110 
    111     public function testEmptySelectPart() 
    112     { 
    113         $q = new Doctrine_Query(); 
    114  
    115         try { 
    116             $q->select(null); 
    117  
    118             $this->fail(); 
    119         } catch(Doctrine_Query_Exception $e) { 
    120             $this->pass(); 
    121         } 
     111    public function testChangeUpdateToSelect() 
     112    { 
     113        $q = Doctrine_Query::create() 
     114            ->update('User u') 
     115            ->set('u.password', '?', 'newpassword') 
     116            ->where('u.username = ?', 'jwage'); 
     117 
     118        $this->assertEqual($q->getType(), Doctrine_Query_Abstract::UPDATE); 
     119        $this->assertEqual($q->getDql(), 'UPDATE User u SET u.password = ? WHERE u.username = ?'); 
     120 
     121        $q->select(); 
     122 
     123        $this->assertEqual($q->getType(), Doctrine_Query_Abstract::SELECT); 
     124        $this->assertEqual($q->getDql(), ' FROM User u WHERE u.username = ?'); 
    122125    } 
    123126 
  • branches/1.1/UPGRADE_TO_1_1

    r5030 r5031  
    7171 
    7272    $manager->setAttribute(Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS, array('name' => '%s_id', 'type' => 'string', 'length' => 16)); // %s in the name is replaced with the table name. 
     73 
     74Doctrine Query 
     75-------------- 
     76 
     77A query can now be transformed from an update() or delete() to a select() or any combination. Run a query once to update a field then turn it to a select and execute it. 
     78 
     79    $q = Doctrine_Query::create() 
     80        ->update('User u') 
     81        ->set('u.password', '?', 'newpassword') 
     82        ->where('u.username = ?', 'jwage'); 
     83    $q->execute(); 
     84 
     85    // Change it to a select query 
     86    $q->select(); 
     87    $user = $q->fetchOne();