[limb-svn] r5979 - in 3.x/trunk/limb/dbal: src/drivers/mysql src/drivers/pgsql src/drivers/sqlite tests/cases/non-driver tests/cases/non-driver/.fixture tests/cases/non-driver/filter
svn at limb-project.com
svn at limb-project.com
Sat Jun 9 16:33:19 MSD 2007
Author: pachanga
Date: 2007-06-09 16:33:19 +0400 (Sat, 09 Jun 2007)
New Revision: 5979
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5979
Added:
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDropStatement.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.sqlite
3.x/trunk/limb/dbal/tests/cases/non-driver/.ignore.php
Modified:
3.x/trunk/limb/dbal/src/drivers/mysql/lmbMysqlStatement.class.php
3.x/trunk/limb/dbal/src/drivers/pgsql/lmbPgsqlDropStatement.class.php
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecord.class.php
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php
3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/filter/lmbAutoDbTransactionFilterTest.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php
3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php
Log:
-- all dbal tests for sqlite driver now pass
-- .ignore.php for non-driver tests added
Modified: 3.x/trunk/limb/dbal/src/drivers/mysql/lmbMysqlStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/mysql/lmbMysqlStatement.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/mysql/lmbMysqlStatement.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,17 +2,17 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/dbal/src/drivers/lmbDbStatement.interface.php');
-/**
- * class lmbMysqlStatement.
- *
- * @package dbal
- * @version $Id$
+/**
+ * class lmbMysqlStatement.
+ *
+ * @package dbal
+ * @version $Id$
*/
class lmbMysqlStatement implements lmbDbStatement
{
@@ -187,7 +187,7 @@
function execute()
{
- return (Boolean) $this->connection->execute($this->getSQL());
+ return (bool) $this->connection->execute($this->getSQL());
}
}
Modified: 3.x/trunk/limb/dbal/src/drivers/pgsql/lmbPgsqlDropStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/pgsql/lmbPgsqlDropStatement.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/pgsql/lmbPgsqlDropStatement.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,18 +2,18 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require(dirname(__FILE__) . '/lmbPgsqlStatement.class.php');
-/**
- * class lmbPgsqlDropStatement.
- *
- * @package dbal
- * @version $Id$
+/**
+ * class lmbPgsqlDropStatement.
+ *
+ * @package dbal
+ * @version $Id$
*/
class lmbPgsqlDropStatement extends lmbPgsqlStatement
{
@@ -22,7 +22,7 @@
try
{
$this->queryId = @$this->connection->execute($this->getSQL());
- return (Boolean) $this->queryId;
+ return (bool) $this->queryId;
}
catch(lmbException $e)
{
Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteConnection.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,15 +2,16 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/dbal/src/drivers/lmbDbConnection.interface.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteDbInfo.class.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteQueryStatement.class.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteInsertStatement.class.php');
+lmb_require(dirname(__FILE__) . '/lmbSqliteDropStatement.class.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteManipulationStatement.class.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteStatement.class.php');
lmb_require(dirname(__FILE__) . '/lmbSqliteTypeInfo.class.php');
@@ -26,6 +27,7 @@
{
protected $connectionId;
protected $config;
+ protected $in_transaction = false;
function __construct($config)
{
@@ -41,7 +43,7 @@
{
if(!is_resource($this->connectionId))
$this->connect();
-
+
return $this->connectionId;
}
@@ -66,7 +68,7 @@
function disconnect()
{
if(is_resource($this->connectionId))
- {
+ {
sqlite_close($this->connectionId);
$this->connectionId = null;
}
@@ -78,13 +80,13 @@
throw new lmbDbException('Could not connect to database "' . $this->config['database'] . '"');
$errno = sqlite_last_error($this->getConnectionId());
-
+
$info = array('driver' => 'sqlite');
- $info['errorno'] = $errno;
-
+ $info['errorno'] = $errno;
+
if(!is_null($sql))
- $info['sql'] = $sql;
-
+ $info['sql'] = $sql;
+
throw new lmbDbException(sqlite_error_string($errno) . ' SQL: '. $sql, $info);
}
@@ -93,23 +95,32 @@
$result = sqlite_query($this->getConnectionId(), $sql);
if($result === false)
$this->_raiseError($sql);
-
+
return $result;
}
function beginTransaction()
{
$this->execute('BEGIN');
+ $this->in_transaction = true;
}
function commitTransaction()
{
- $this->execute('COMMIT');
+ if($this->in_transaction)
+ {
+ $this->execute('COMMIT');
+ $this->in_transaction = false;
+ }
}
function rollbackTransaction()
{
- $this->execute('ROLLBACK');
+ if($this->in_transaction)
+ {
+ $this->execute('ROLLBACK');
+ $this->in_transaction = false;
+ }
}
function newStatement($sql)
@@ -118,7 +129,7 @@
$statement = $match[1];
else
$statement = $sql;
-
+
switch(strtoupper($statement))
{
case 'SELECT':
@@ -128,6 +139,8 @@
return new lmbSqliteQueryStatement($this, $sql);
case 'INSERT':
return new lmbSqliteInsertStatement($this, $sql);
+ case 'DROP':
+ return new lmbSqliteDropStatement($this, $sql);
case 'UPDATE':
case 'DELETE':
return new lmbSqliteManipulationStatement($this, $sql);
Added: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDropStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDropStatement.class.php (rev 0)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteDropStatement.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -0,0 +1,31 @@
+<?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(dirname(__FILE__) . '/lmbSqliteStatement.class.php');
+
+/**
+ * class lmbSqliteDropStatement.
+ *
+ * @package dbal
+ * @version $Id$
+ */
+class lmbSqliteDropStatement extends lmbSqliteStatement
+{
+ function execute()
+ {
+ try
+ {
+ $this->queryId = @$this->connection->execute($this->getSQL());
+ return (bool) $this->queryId;
+ }
+ catch(lmbException $e){}
+ }
+}
+
+?>
Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteManipulationStatement.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -1,27 +1,40 @@
<?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
+/*
+ * 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/drivers/lmbDbManipulationStatement.interface.php');
-lmb_require(dirname(__FILE__) . '/lmbSqliteStatement.class.php');
-
+lmb_require(dirname(__FILE__) . '/lmbSqliteStatement.class.php');
+
/**
* class lmbSqliteManipulationStatement.
*
* @package dbal
* @version $Id$
- */
+ */
class lmbSqliteManipulationStatement extends lmbSqliteStatement implements lmbDbManipulationStatement
{
function getAffectedRowCount()
{
return sqlite_changes($this->connection->getConnectionId());
}
+
+ function execute()
+ {
+ $sql = ltrim($this->getSQL());
+
+ //this is a dirty hack for sqlite_changes which
+ //doesn't return proper value if there was not
+ if((stripos($sql, 'delete ') === 0 || stripos($sql, 'update '))
+ && stripos($sql, ' where ') === false)
+ $sql .= " WHERE 1=1";
+
+ return (bool)$this->connection->execute($sql);
+ }
}
?>
\ No newline at end of file
Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecord.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecord.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecord.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,17 +2,17 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/dbal/src/drivers/lmbDbBaseRecord.class.php');
-/**
- * class lmbSqliteRecord.
- *
- * @package dbal
- * @version $Id$
+/**
+ * class lmbSqliteRecord.
+ *
+ * @package dbal
+ * @version $Id$
*/
class lmbSqliteRecord extends lmbDbBaseRecord
{
@@ -44,6 +44,14 @@
$this->properties = $values;
}
+ function importRaw($values)
+ {
+ $this->properties = array();
+ //dirty hack for stripping escaping " symbols
+ foreach($values as $key => $value)
+ $this->properties[trim($key, '"')] = $value;
+ }
+
function remove($name)
{
if(isset($this->properties[$name]))
Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteRecordSet.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/dbal/src/drivers/lmbDbBaseRecordSet.class.php');
lmb_require('limb/dbal/src/drivers/sqlite/lmbSqliteRecord.class.php');
@@ -65,8 +65,8 @@
if($this->limit)
{
$query .= ' LIMIT ' .
- $this->limit . ' OFFSET ' .
- $this->offset;
+ $this->limit . ' OFFSET ' .
+ $this->offset;
}
$this->queryId = $this->connection->execute($query);
@@ -79,8 +79,8 @@
{
$this->current = new lmbSqliteRecord();
$values = sqlite_fetch_array($this->queryId, SQLITE_ASSOC);
- $this->current->import($values);
- $this->valid = is_array($values);
+ if($this->valid = is_array($values))
+ $this->current->importRaw($values);
$this->key++;
}
@@ -113,11 +113,11 @@
$queryId = $this->connection->execute($query . " LIMIT 1 OFFSET $pos");
- $res = sqlite_fetch_array($queryId, SQLITE_ASSOC);
- if($res)
+ $res = sqlite_fetch_array($queryId, SQLITE_ASSOC);
+ if(is_array($res))
{
$record = new lmbSqliteRecord();
- $record->import($res);
+ $record->importRaw($res);
return $record;
}
}
Modified: 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php
===================================================================
--- 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/src/drivers/sqlite/lmbSqliteStatement.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -2,17 +2,17 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/dbal/src/drivers/lmbDbStatement.interface.php');
-/**
- * class lmbSqliteStatement.
- *
- * @package dbal
- * @version $Id$
+/**
+ * class lmbSqliteStatement.
+ *
+ * @package dbal
+ * @version $Id$
*/
class lmbSqliteStatement implements lmbDbStatement
{
@@ -187,7 +187,7 @@
function execute()
{
- return (Boolean) $this->connection->execute($this->getSQL());
+ return (bool)$this->connection->execute($this->getSQL());
}
}
Added: 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.sqlite
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.sqlite (rev 0)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/.fixture/init_tests.sqlite 2007-06-09 12:33:19 UTC (rev 5979)
@@ -0,0 +1,32 @@
+DROP TABLE "test_one_table_object";
+CREATE TABLE "test_one_table_object" (
+ "id" INTEGER PRIMARY KEY,
+ "annotation" text,
+ "content" text,
+ "news_date" date default NULL
+);
+
+DROP TABLE "test_db_table";
+CREATE TABLE "test_db_table" (
+ "id" INTEGER PRIMARY KEY,
+ "description" text,
+ "title" varchar(255) NOT NULL default '',
+ "ordr" int(11) NULL
+);
+
+DROP TABLE "all_types_test";
+CREATE TABLE "all_types_test" (
+ "field_int" int(11) default NULL,
+ "field_varchar" varchar(255) default NULL,
+ "field_char" varchar(11) default NULL,
+ "field_date" date default NULL,
+ "field_datetime" datetime default NULL,
+ "field_time" time default NULL,
+ "field_text" text,
+ "field_smallint" smallint(6) default NULL,
+ "field_bigint" bigint(20) default NULL,
+ "field_blob" blob,
+ "field_float" float default NULL,
+ "field_decimal" decimal(10,0) default NULL,
+ "field_tinyint" tinyint(4) default NULL
+);
Added: 3.x/trunk/limb/dbal/tests/cases/non-driver/.ignore.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/.ignore.php (rev 0)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/.ignore.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -0,0 +1,12 @@
+<?php
+require_once('limb/dbal/common.inc.php');
+
+$type = lmbToolkit :: instance()->getDefaultDbConnection()->getType();
+$ignore = !file_exists(dirname(__FILE__) . '/.fixture/init_tests.' . $type);
+$test_dir = basename(dirname(__FILE__));
+
+if($ignore)
+ echo "\nDBAL package '$test_dir' tests are skipped!(no compatible database fixture found for '$type' connection)\n\n";
+
+return $ignore;
+?>
Modified: 3.x/trunk/limb/dbal/tests/cases/non-driver/filter/lmbAutoDbTransactionFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/dbal/tests/cases/non-driver/filter/lmbAutoDbTransactionFilterTest.class.php 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/filter/lmbAutoDbTransactionFilterTest.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -1,10 +1,10 @@
<?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
+/*
+ * 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/filter/lmbAutoDbTransactionFilter.class.php');
lmb_require('limb/filter_chain/src/lmbFilterChain.class.php');
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 2007-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbSimpleDbTest.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -1,10 +1,10 @@
<?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
+/*
+ * 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/criteria/lmbSQLFieldCriteria.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
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-06-09 11:32:47 UTC (rev 5978)
+++ 3.x/trunk/limb/dbal/tests/cases/non-driver/lmbTableGatewayTest.class.php 2007-06-09 12:33:19 UTC (rev 5979)
@@ -1,10 +1,10 @@
<?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
+/*
+ * 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
*/
require_once('limb/dbal/src/drivers/lmbDbTypeInfo.class.php');
lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php');
More information about the limb-svn
mailing list