[limb-svn] r5854 - in 3.x/trunk/limb/dbal: src tests/cases/non-driver tests/cases/non-driver/.fixture
svn at limb-project.com
svn at limb-project.com
Thu May 10 14:25:36 MSD 2007
Author: pachanga
Date: 2007-05-10 14:25:36 +0400 (Thu, 10 May 2007)
New Revision: 5854
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5854
Modified:
3.x/trunk/limb/dbal/src/lmbTableGateway.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.mysql
3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.oci
3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.pgsql
3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php
Log:
-- lmbTableGateway :: update() now can accept row set as a raw sql expression as well as array
Modified: 3.x/trunk/limb/dbal/src/lmbTableGateway.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/lmbTableGateway.class.php 2007-05-10 09:39:15 UTC (rev 5853)
+++ 3.x/trunk/limb/dbal/src/lmbTableGateway.class.php 2007-05-10 10:25:36 UTC (rev 5854)
@@ -149,22 +149,31 @@
return (int)$this->_stmt->insertId($this->_primary_key_name);
}
- function update($row, $criteria = null)
+ function update($set, $criteria = null)
{
- $row = $this->_filterRow($row);
+ if(is_array($set))
+ $set = $this->_filterRow($set);
+
$query = new lmbUpdateQuery($this->_db_table_name, $this->_conn);
if($criteria)
$query->addCriteria($criteria);
- foreach(array_keys($row) as $key)
- $query->addField($key);
+ if(is_array($set))
+ {
+ foreach(array_keys($set) as $key)
+ $query->addField($key);
- $this->_stmt = $query->getStatement();
-
- $this->_bindValuesToStatement($this->_stmt, $row);
-
- return $this->_stmt->execute();
+ $this->_stmt = $query->getStatement();
+ $this->_bindValuesToStatement($this->_stmt, $set);
+ return $this->_stmt->execute();
+ }
+ else
+ {
+ $query->addRawField($set);
+ $this->_stmt = $query->getStatement();
+ return $this->_stmt->execute();
+ }
}
protected function _bindValuesToStatement($stmt, $values)
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.mysql
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.mysql 2007-05-10 09:39:15 UTC (rev 5853)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.mysql 2007-05-10 10:25:36 UTC (rev 5854)
@@ -12,6 +12,7 @@
`id` int(11) unsigned NOT NULL auto_increment,
`description` text,
`title` varchar(255) NOT NULL default '',
+ `ordr` int(11) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.oci
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.oci 2007-05-10 09:39:15 UTC (rev 5853)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.oci 2007-05-10 10:25:36 UTC (rev 5854)
@@ -26,6 +26,7 @@
id number NOT NULL,
description VARCHAR2(255),
title VARCHAR2(255),
+ ordr number default NULL,
PRIMARY KEY (id)
);
/
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.pgsql
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.pgsql 2007-05-10 09:39:15 UTC (rev 5853)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.pgsql 2007-05-10 10:25:36 UTC (rev 5854)
@@ -13,6 +13,7 @@
"id" SERIAL,
"description" text,
"title" varchar(255) NOT NULL default '',
+ "ordr" int8 NULL,
PRIMARY KEY (id)
) ;
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php 2007-05-10 09:39:15 UTC (rev 5853)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php 2007-05-10 10:25:36 UTC (rev 5854)
@@ -1,13 +1,13 @@
<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright Copyright © 2004-2007 BIT
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- * @version $Id$
- * @package dbal
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright Copyright © 2004-2007 BIT
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version $Id$
+ * @package dbal
*/
require_once('limb/dbal/src/drivers/lmbDbTypeInfo.class.php');
lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php');
@@ -84,7 +84,7 @@
function testUpdateAll()
{
- $this->db_table_test->insert(array('title' => 'wow', 'description' => 'description' ));
+ $this->db_table_test->insert(array('title' => 'wow', 'description' => 'description'));
$this->db_table_test->insert(array('title' => 'wow', 'description' => 'description2'));
$this->db_table_test->update(array('description' => 'new_description',
@@ -104,6 +104,27 @@
$this->assertEqual($record->get('description'), 'new_description');
}
+ function testUpdateAllWithRawSet()
+ {
+ $this->db_table_test->insert(array('ordr' => '1'));
+ $this->db_table_test->insert(array('ordr' => '10'));
+
+ $this->db_table_test->update('ordr=ordr+1');
+
+ $this->assertEqual($this->db_table_test->getAffectedRowCount(), 2);
+
+ $stmt = $this->conn->newStatement("SELECT * FROM test_db_table");
+ $records = $stmt->getRecordSet();
+
+ $records->rewind();
+ $record = $records->current();
+ $this->assertEqual($record->get('ordr'), '2');
+
+ $records->next();
+ $record = $records->current();
+ $this->assertEqual($record->get('ordr'), '11');
+ }
+
function testUpdateByCriteria()
{
$this->db_table_test->insert(array('title' => 'wow', 'description' => 'description'));//should be changed
@@ -306,7 +327,8 @@
{
$this->assertEqual($this->db_table_test->getColumnsForSelect(), array('test_db_table.id' => 'id',
'test_db_table.description' => 'description',
- 'test_db_table.title' => 'title'));
+ 'test_db_table.title' => 'title',
+ 'test_db_table.ordr' => 'ordr'));
}
function testGetColumnsForSelectSpecificNameAndPrefix()
@@ -314,13 +336,14 @@
$this->assertEqual($this->db_table_test->getColumnsForSelect('tn', array(), '_'),
array('tn.id' => '_id',
'tn.description' => '_description',
- 'tn.title' => '_title'));
+ 'tn.title' => '_title',
+ 'tn.ordr' => '_ordr'));
}
function testGetColumnsForSelectSpecificNameWithExcludes()
{
$this->assertEqual($this->db_table_test->getColumnsForSelect('tn', array('id', 'description')),
- array('tn.title' => 'title'));
+ array('tn.title' => 'title', 'tn.ordr' => 'ordr'));
}
}
More information about the limb-svn
mailing list