[limb-svn] r6930 - in 3.x/trunk/limb/dbal: src src/criteria tests/cases/non-driver
svn at limb-project.com
svn at limb-project.com
Mon Apr 14 15:22:49 MSD 2008
Author: pachanga
Date: 2008-04-14 15:22:49 +0400 (Mon, 14 Apr 2008)
New Revision: 6930
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6930
Modified:
3.x/trunk/limb/dbal/src/criteria/lmbSQLCriteria.class.php
3.x/trunk/limb/dbal/src/lmbDBAL.class.php
3.x/trunk/limb/dbal/src/lmbSimpleDb.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php
Log:
-- lmbSQLCriteria throws exception if criteria is not supported
-- lmbSimpleDb :: execute($sql) added
-- lmbDBAL includes dbal/common.inc.php
Modified: 3.x/trunk/limb/dbal/src/criteria/lmbSQLCriteria.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/criteria/lmbSQLCriteria.class.php 2008-04-14 11:02:24 UTC (rev 6929)
+++ 3.x/trunk/limb/dbal/src/criteria/lmbSQLCriteria.class.php 2008-04-14 11:22:49 UTC (rev 6930)
@@ -94,15 +94,19 @@
//array('id=1')
if(!isset($args[1]) && isset($args[0]))
return new lmbSQLCriteria($args[0]);
+
//array('id=?', array(1))
- elseif(isset($args[0]) && is_array($args[1]))
+ if(isset($args[0]) && is_array($args[1]))
return new lmbSQLCriteria($args[0], $args[1]);
+
//array('id=?', 1)
- elseif(isset($args[0]))
+ if(isset($args[0]))
{
$sql = array_shift($args);
return new lmbSQLCriteria($sql, $args);
}
+
+ throw new lmbDbException("Unsupported criteria format passed as array", array('criteria' => $args));
}
//id=1
elseif(is_string($args))
Modified: 3.x/trunk/limb/dbal/src/lmbDBAL.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2008-04-14 11:02:24 UTC (rev 6929)
+++ 3.x/trunk/limb/dbal/src/lmbDBAL.class.php 2008-04-14 11:22:49 UTC (rev 6930)
@@ -6,7 +6,7 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/dbal/toolkit.inc.php');
+require_once('limb/dbal/common.inc.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php');
Modified: 3.x/trunk/limb/dbal/src/lmbSimpleDb.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/lmbSimpleDb.class.php 2008-04-14 11:02:24 UTC (rev 6929)
+++ 3.x/trunk/limb/dbal/src/lmbSimpleDb.class.php 2008-04-14 11:22:49 UTC (rev 6930)
@@ -1,174 +1,179 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/dbal/src/query/lmbInsertQuery.class.php');
-lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
-lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php');
-lmb_require('limb/dbal/src/query/lmbDeleteQuery.class.php');
-lmb_require('limb/dbal/src/criteria/lmbSQLCriteria.class.php');
-
-/**
- * class lmbSimpleDb.
- *
- * @package dbal
- * @version $Id$
- */
-class lmbSimpleDb
-{
- protected $conn;
- protected $stmt;
-
- function __construct($conn)
- {
- $this->conn = $conn;
- }
-
- function getConnection()
- {
- return $this->conn;
- }
-
- function getType()
- {
- return $this->conn->getType();
- }
-
- function select($table, $criteria = null, $order = array())
- {
- $query = new lmbSelectQuery($table, $this->conn);
-
- if($criteria)
- $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
-
- $rs = $query->getRecordSet();
-
- if(is_array($order) && sizeof($order))
- $rs->sort($order);
-
- return $rs;
- }
-
- function selectRecord($table, $criteria = null, $order = array())
- {
- $rs = $this->select($table, $criteria, $order)->paginate(0, 1);
- $rs->rewind();
- if($rs->valid())
- return $rs->current();
- }
-
- /**
- * @deprecated
- */
- function getFirstRecordFrom($table_name, $criteria = null, $order = array())
- {
- return $this->selectRecord($table_name, $criteria, $order);
- }
-
- function count($table_name, $criteria = null)
- {
- $rs = $this->select($table_name, $criteria);
- return $rs->count();
- }
-
- function countAffected()
- {
- if($this->stmt)
- return $this->stmt->getAffectedRowCount();
- else
- return 0;
- }
-
- function insert($table, $values, $primary_key = 'id')
- {
- $query = new lmbInsertQuery($table, $this->conn);
-
- foreach($values as $key => $value)
- $query->addField($key , $value);
-
- $stmt = $query->getStatement($this->conn);
-
- if($primary_key)
- {
- if(isset($values[$primary_key]))
- {
- $stmt->execute();
- return $values[$primary_key];
- }
- else
- return $stmt->insertId($primary_key);
- }
- else
- $stmt->execute();
- }
-
- function update($table, $values, $criteria = null)
- {
- $query = new lmbUpdateQuery($table, $this->conn);
-
- if($criteria)
- $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
-
- foreach($values as $key => $value)
- $query->addField($key, $value);
-
- $this->stmt = $query->getStatement($this->conn);
- $this->stmt->execute();
- return $this;
- }
-
- function delete($table, $criteria = null)
- {
- $query = new lmbDeleteQuery($table, $this->conn);
-
- if($criteria)
- $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
-
- $this->stmt = $query->getStatement($this->conn);
- $this->stmt->execute();
- return $this;
- }
-
- function truncateDb()
- {
- $info = $this->conn->getDatabaseInfo();
- foreach($info->getTableList() as $table)
- $this->conn->newStatement("DELETE FROM $table")->execute();
- return $this;
- }
-
- function disconnect()
- {
- $this->conn->disconnect();
- return $this;
- }
-
- function begin()
- {
- $this->conn->beginTransaction();
- return $this;
- }
-
- function commit()
- {
- $this->conn->commitTransaction();
- return $this;
- }
-
- function rollback()
- {
- $this->conn->rollbackTransaction();
- return $this;
- }
-
- function quote($id)
- {
- return $this->conn->quoteIdentifier($id);
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/dbal/src/query/lmbInsertQuery.class.php');
+lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
+lmb_require('limb/dbal/src/query/lmbUpdateQuery.class.php');
+lmb_require('limb/dbal/src/query/lmbDeleteQuery.class.php');
+lmb_require('limb/dbal/src/criteria/lmbSQLCriteria.class.php');
+
+/**
+ * class lmbSimpleDb.
+ *
+ * @package dbal
+ * @version $Id$
+ */
+class lmbSimpleDb
+{
+ protected $conn;
+ protected $stmt;
+
+ function __construct($conn)
+ {
+ $this->conn = $conn;
+ }
+
+ function getConnection()
+ {
+ return $this->conn;
+ }
+
+ function getType()
+ {
+ return $this->conn->getType();
+ }
+
+ function execute($sql)
+ {
+ $this->conn->execute($sql);
+ }
+
+ function select($table, $criteria = null, $order = array())
+ {
+ $query = new lmbSelectQuery($table, $this->conn);
+
+ if($criteria)
+ $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
+
+ $rs = $query->getRecordSet();
+
+ if(is_array($order) && sizeof($order))
+ $rs->sort($order);
+
+ return $rs;
+ }
+
+ function selectRecord($table, $criteria = null, $order = array())
+ {
+ $rs = $this->select($table, $criteria, $order)->paginate(0, 1);
+ $rs->rewind();
+ if($rs->valid())
+ return $rs->current();
+ }
+
+ /**
+ * @deprecated
+ */
+ function getFirstRecordFrom($table_name, $criteria = null, $order = array())
+ {
+ return $this->selectRecord($table_name, $criteria, $order);
+ }
+
+ function count($table_name, $criteria = null)
+ {
+ $rs = $this->select($table_name, $criteria);
+ return $rs->count();
+ }
+
+ function countAffected()
+ {
+ if($this->stmt)
+ return $this->stmt->getAffectedRowCount();
+ else
+ return 0;
+ }
+
+ function insert($table, $values, $primary_key = 'id')
+ {
+ $query = new lmbInsertQuery($table, $this->conn);
+
+ foreach($values as $key => $value)
+ $query->addField($key , $value);
+
+ $stmt = $query->getStatement($this->conn);
+
+ if($primary_key)
+ {
+ if(isset($values[$primary_key]))
+ {
+ $stmt->execute();
+ return $values[$primary_key];
+ }
+ else
+ return $stmt->insertId($primary_key);
+ }
+ else
+ $stmt->execute();
+ }
+
+ function update($table, $values, $criteria = null)
+ {
+ $query = new lmbUpdateQuery($table, $this->conn);
+
+ if($criteria)
+ $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
+
+ foreach($values as $key => $value)
+ $query->addField($key, $value);
+
+ $this->stmt = $query->getStatement($this->conn);
+ $this->stmt->execute();
+ return $this;
+ }
+
+ function delete($table, $criteria = null)
+ {
+ $query = new lmbDeleteQuery($table, $this->conn);
+
+ if($criteria)
+ $query->addCriteria(lmbSQLCriteria :: objectify($criteria));
+
+ $this->stmt = $query->getStatement($this->conn);
+ $this->stmt->execute();
+ return $this;
+ }
+
+ function truncateDb()
+ {
+ $info = $this->conn->getDatabaseInfo();
+ foreach($info->getTableList() as $table)
+ $this->conn->newStatement("DELETE FROM $table")->execute();
+ return $this;
+ }
+
+ function disconnect()
+ {
+ $this->conn->disconnect();
+ return $this;
+ }
+
+ function begin()
+ {
+ $this->conn->beginTransaction();
+ return $this;
+ }
+
+ function commit()
+ {
+ $this->conn->commitTransaction();
+ return $this;
+ }
+
+ function rollback()
+ {
+ $this->conn->rollbackTransaction();
+ return $this;
+ }
+
+ function quote($id)
+ {
+ return $this->conn->quoteIdentifier($id);
+ }
+}
+
+
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php 2008-04-14 11:02:24 UTC (rev 6929)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php 2008-04-14 11:22:49 UTC (rev 6930)
@@ -178,6 +178,5 @@
{
$this->assertEqual($this->db->quote('foo'), $this->conn->quoteIdentifier('foo'));
}
-
}
More information about the limb-svn
mailing list