| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php'); 10 lmb_require('limb/dbal/src/lmbSimpleDb.class.php'); 11 lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php'); 12 13 class lmbUpdateQueryTest extends UnitTestCase 14 { 15 var $query; 16 var $db; 17 18 function setUp() 19 { 20 $toolkit = lmbToolkit :: save(); 21 $this->conn = $toolkit->getDefaultDbConnection(); 22 $this->db = new lmbSimpleDb($this->conn); 23 24 $this->_dbCleanUp(); 25 } 26 27 function tearDown() 28 { 29 $this->_dbCleanUp(); 30 } 31 32 function _dbCleanUp() 33 { 34 $this->db->delete('test_db_table'); 35 } 36 37 function testUpdate() 38 { 39 $this->db->insert('test_db_table', array('id' => 100)); 40 $this->db->insert('test_db_table', array('id' => 101)); 41 42 $query = new lmbUpdateQuery('test_db_table', $this->conn); 43 $query->addField('description', $description = 'Some description'); 44 $query->addField('title', $title = 'Some title'); 45 46 $stmt = $query->getStatement($this->conn); 47 $stmt->execute(); 48 49 $rs = $this->db->select('test_db_table'); 50 $rs->rewind(); 51 $record = $rs->current(); 52 $this->assertEqual($record->get('title'), $title); 53 $this->assertEqual($record->get('description'), $description); 54 55 $rs->next(); 56 $record = $rs->current(); 57 $this->assertEqual($record->get('title'), $title); 58 $this->assertEqual($record->get('description'), $description); 59 } 60 61 function testUpdateAddFieldWithoutValueOnlyReservesAPlaceholder() 62 { 63 $this->db->insert('test_db_table', array('id' => 101)); 64 65 $query = new lmbUpdateQuery('test_db_table', $this->conn); 66 $query->addField('description'); 67 $query->addField('title'); 68 69 $stmt = $query->getStatement($this->conn); 70 $stmt->set('description', $description = 'Some \'description\''); 71 $stmt->set('title', $title = 'Some title'); 72 $stmt->execute(); 73 74 $rs = $this->db->select('test_db_table'); 75 $rs->rewind(); 76 $record = $rs->current(); 77 $this->assertEqual($record->get('title'), $title); 78 $this->assertEqual($record->get('description'), $description); 79 } 80 81 function testUpdateSpecialCase() 82 { 83 $this->db->insert('test_db_table', array('id' => 100)); 84 85 $query = new lmbUpdateQuery('test_db_table', $this->conn); 86 $query->addRawField('id = id + 1'); 87 88 $stmt = $query->getStatement($this->conn); 89 $stmt->execute(); 90 91 $rs = $this->db->select('test_db_table'); 92 $rs->rewind(); 93 $record = $rs->current(); 94 $this->assertEqual($record->get('id'), 101); 95 } 96 97 function testUpdateWithCriteria() 98 { 99 $this->db->insert('test_db_table', array('id' => 100)); 100 $this->db->insert('test_db_table', array('id' => 101)); 101 102 $query = new lmbUpdateQuery('test_db_table', $this->conn); 103 $query->addField('description', $description = 'Some description'); 104 $query->addField('title', $title = 'Some title'); 105 $query->addCriteria(new lmbSQLFieldCriteria('id', 101)); 106 107 $stmt = $query->getStatement($this->conn); 108 $stmt->execute(); 109 110 $rs = $this->db->select('test_db_table'); 111 $rs->rewind(); 112 $record = $rs->current(); 113 $this->assertEqual($record->get('id'), 100); 114 $this->assertEqual($record->get('title'), ''); 115 $this->assertEqual($record->get('description'), ''); 116 117 $rs->next(); 118 $record = $rs->current(); 119 $this->assertEqual($record->get('id'), 101); 120 $this->assertEqual($record->get('title'), $title); 121 $this->assertEqual($record->get('description'), $description); 122 } 123 } 124 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |