Fix for Sqlite - "Transaction already started" PDOException. Added unit tests for delete and update Sqlite syntax.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9651 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-10-14 16:05:47 +00:00
parent ce6496e247
commit 2160ca2833
8 changed files with 108 additions and 3 deletions

View file

@ -74,7 +74,7 @@
$db_info = Context::getDBInfo(); $db_info = Context::getDBInfo();
$this->database = $db_info->master_db["db_database"]; $this->database = $db_info->master_db["db_database"];
$this->prefix = $db_info->master_db["db_table_prefix"]; $this->prefix = $db_info->master_db["db_table_prefix"];
if(!substr($this->prefix,-1)!='_') $this->prefix .= '_'; //if(!substr($this->prefix,-1)!='_') $this->prefix .= '_';
} }
/** /**
@ -130,7 +130,13 @@
**/ **/
function commit($force = false) { function commit($force = false) {
if(!$force && (!$this->is_connected || !$this->transaction_started)) return; if(!$force && (!$this->is_connected || !$this->transaction_started)) return;
$this->handler->commit(); try {
$this->handler->commit();
}
catch(PDOException $e){
// There was no transaction started, so just continue.
error_log($e->getMessage());
}
$this->transaction_started = false; $this->transaction_started = false;
} }
@ -403,6 +409,10 @@
} }
} }
function _getConnection($type = null){
return null;
}
/** /**
* @brief insertAct * @brief insertAct
* */ * */
@ -457,6 +467,7 @@
$this->_prepare($query); $this->_prepare($query);
$data = $this->_execute(); $data = $this->_execute();
// TODO isError is called twice
if ($this->isError()) if ($this->isError())
return; return;

View file

@ -15,6 +15,7 @@
require_once(_XE_PATH_.'test-phpUnit/db/MssqlTest.php'); require_once(_XE_PATH_.'test-phpUnit/db/MssqlTest.php');
require_once(_XE_PATH_.'test-phpUnit/db/MssqlOnlineTest.php'); require_once(_XE_PATH_.'test-phpUnit/db/MssqlOnlineTest.php');
require_once(_XE_PATH_.'test-phpUnit/db/MysqlTest.php'); require_once(_XE_PATH_.'test-phpUnit/db/MysqlTest.php');
require_once(_XE_PATH_.'test-phpUnit/db/SqliteTest.php');
require_once(_XE_PATH_.'config/config.inc.php'); require_once(_XE_PATH_.'config/config.inc.php');
// require_once(_XE_PATH_.'classes/object/Object.class.php'); // require_once(_XE_PATH_.'classes/object/Object.class.php');

View file

@ -29,7 +29,7 @@
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL; echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
echo $xml_file; echo $xml_file;
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL; echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
$tester = new QueryTester(); $tester = new QueryTester();
$outputString = $tester->getNewParserOutputString($xml_file, $argsString); $outputString = $tester->getNewParserOutputString($xml_file, $argsString);
echo $outputString; echo $outputString;

View file

@ -0,0 +1,32 @@
<?php
/**
* Base class for tests for Sqlite SQL syntax
*
* See syntax reference:
* http://www.sqlite.org/lang.html
*/
class SqliteTest extends DBTest {
/**
* Prepare runtime context - tell DB class that current DB is CUBRID
*/
protected function setUp() {
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'sqlite3_pdo','db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'sqlite3_pdo','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
DB::getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,18 @@
<?php
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
class SqliteDeleteTest extends SqliteTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getDeleteSql', $columnList);
}
function testDeleteIsGeneratedWithoutAlias(){
$xml_file = _TEST_PATH_ . "db/xml_query/sqlite/data/module.deleteModuleConfig.xml";
$argsString = '$args->module = "comment"; $args->site_srl = 0; ';
$expected = 'delete from "xe_module_config"
where "module" = \'comment\' and "site_srl" = 0';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,22 @@
<?php
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
class SqliteDeleteTest extends SqliteTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getUpdateSql', $columnList);
}
function testUpdateIsGeneratedWithoutAlias(){
$xml_file = _TEST_PATH_ . "db/xml_query/sqlite/data/member.updateLastLogin.xml";
$argsString = '$args->member_srl = 4;
$args->last_login = \'20111014184010\';
';
$expected = 'UPDATE "xe_member"
SET "member_srl" = 4
, "last_login" = \'20111014184010\'
WHERE "member_srl" = 4';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,12 @@
<query id="updateLastLogin" action="update">
<tables>
<table name="member" />
</tables>
<columns>
<column name="member_srl" var="member_srl" filter="number" notnull="notnull" />
<column name="last_login" var="last_login" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull" filter="number" />
</conditions>
</query>

View file

@ -0,0 +1,9 @@
<query id="deleteModuleConfig" action="delete">
<tables>
<table name="module_config" />
</tables>
<conditions>
<condition operation="equal" column="module" var="module" notnull="notnull" />
<condition operation="equal" column="site_srl" var="site_srl" notnull="notnull" pipe="and" />
</conditions>
</query>