Changeset 5031
- Timestamp:
- 10/02/08 04:59:32 (9 months ago)
- Location:
- branches/1.1
- Files:
-
- 3 modified
-
lib/Doctrine/Query/Abstract.php (modified) (1 diff)
-
tests/Query/SelectTestCase.php (modified) (1 diff)
-
UPGRADE_TO_1_1 (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1/lib/Doctrine/Query/Abstract.php
r5024 r5031 1559 1559 * @return Doctrine_Query 1560 1560 */ 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 } 1564 1569 } 1565 1570 -
branches/1.1/tests/Query/SelectTestCase.php
r5014 r5031 109 109 } 110 110 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 = ?'); 122 125 } 123 126 -
branches/1.1/UPGRADE_TO_1_1
r5030 r5031 71 71 72 72 $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 74 Doctrine Query 75 -------------- 76 77 A 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();