[limb-svn] r5855 - in 3.x/trunk/limb/active_record: src tests/cases tests/cases/.fixture

svn at limb-project.com svn at limb-project.com
Thu May 10 14:30:44 MSD 2007


Author: pachanga
Date: 2007-05-10 14:30:43 +0400 (Thu, 10 May 2007)
New Revision: 5855
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5855

Modified:
   3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
   3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql
   3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci
   3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
Log:
-- initial version of lmbActiveRecord :: update($class_name, $set, $criteria = null) added, it simply updates records in DB without loading objects into memory

Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php	2007-05-10 10:25:36 UTC (rev 5854)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php	2007-05-10 10:30:43 UTC (rev 5855)
@@ -1362,6 +1362,13 @@
       $object->destroy();
   }
 
+  static function update($class_name, $set, $criteria = null)
+  {
+    $object = new $class_name();
+    $db_table = $object->getDbTable();
+    $db_table->update($set, $criteria);
+  }
+
   protected function _getColumnsForSelect()
   {
     return $this->_db_table->getColumnsForSelect('', $this->_lazy_attributes);

Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql	2007-05-10 10:25:36 UTC (rev 5854)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql	2007-05-10 10:30:43 UTC (rev 5855)
@@ -5,6 +5,7 @@
   `annotation` text,
   `content` text,
   `news_date` date default NULL,
+  `ordr` int(11) NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 

Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci	2007-05-10 10:25:36 UTC (rev 5854)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci	2007-05-10 10:30:43 UTC (rev 5855)
@@ -9,6 +9,7 @@
   annotation clob,
   content clob,
   news_date varchar(255) default NULL,
+  ordr number default NULL,
   PRIMARY KEY  (id)
 );
 /

Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql	2007-05-10 10:25:36 UTC (rev 5854)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql	2007-05-10 10:30:43 UTC (rev 5855)
@@ -5,6 +5,7 @@
   "annotation" text,
   "content" text,
   "news_date" date default NULL,
+  "ordr" int8 NULL,
   PRIMARY KEY  (id)
 )  ;
 

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php	2007-05-10 10:25:36 UTC (rev 5854)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php	2007-05-10 10:30:43 UTC (rev 5855)
@@ -178,7 +178,7 @@
     $this->assertEqual($this->db->count('test_one_table_object'), 2);
   }
 
-  function testUpdate()
+  function testSaveUpdate()
   {
     $object = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
 
@@ -588,6 +588,54 @@
     $this->assertEqual($object3->getContent(), $object1->getContent());
   }
 
+  function testUpdateAllWithArraySet()
+  {
+    $object1 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+    $object2 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+
+    lmbActiveRecord :: update($this->class_name, array('content' => 'blah'));
+
+    $rs = lmbActiveRecord :: find($this->class_name);
+    $rs->rewind();
+    $this->assertEqual($rs->current()->getContent(), 'blah');
+    $rs->next();
+    $this->assertEqual($rs->current()->getContent(), 'blah');
+    $rs->next();
+    $this->assertFalse($rs->valid());
+  }
+
+  function testUpdateAllWithRawValues()
+  {
+    $object1 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+    $object2 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+
+    lmbActiveRecord :: update($this->class_name, 'ordr=1');
+
+    $rs = lmbActiveRecord :: find($this->class_name);
+    $rs->rewind();
+    $this->assertEqual($rs->current()->getOrdr(), 1);
+    $rs->next();
+    $this->assertEqual($rs->current()->getOrdr(), 1);
+    $rs->next();
+    $this->assertFalse($rs->valid());
+  }
+
+  function testUpdateWithCriteria()
+  {
+    $object1 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+    $object2 = $this->_initActiveRecordWithDataAndSave(new TestOneTableObject());
+
+    lmbActiveRecord :: update($this->class_name, array('content' => 'blah'), 'id=' . $object2->getId());
+
+    $rs = lmbActiveRecord :: find($this->class_name);
+    $rs->rewind();
+    $this->assertEqual($rs->current()->getContent(), $object1->getContent());
+    $rs->next();
+    $this->assertEqual($rs->current()->getContent(), 'blah');
+    $rs->next();
+    $this->assertFalse($rs->valid());
+  }
+
   function testGetTableName()
   {
     $object = new TestOneTableObject();
@@ -599,6 +647,7 @@
     $object->set('annotation', 'Annotation ' . time());
     $object->set('content', 'Content ' . time());
     $object->set('news_date', date("Y-m-d", time()));
+    $object->set('ordr', mt_rand());
     return $object;
   }
 



More information about the limb-svn mailing list