mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 04:24:14 +09:00
Fixed a few MSSQL bugs - related to array query arguments and increment columns.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8632 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
6edd5f03a7
commit
b3c75ac4db
15 changed files with 411 additions and 276 deletions
|
|
@ -502,7 +502,7 @@
|
|||
}
|
||||
|
||||
function getUpdateSql($query, $with_values = true){
|
||||
$columnsList = $query->getSelectString();
|
||||
$columnsList = $query->getSelectString($with_values);
|
||||
if($columnsList == '') return new Object(-1, "Invalid query");
|
||||
|
||||
$tableName = $query->getFirstTableName();
|
||||
|
|
|
|||
|
|
@ -159,6 +159,15 @@
|
|||
* object if a row returned \n
|
||||
* return\n
|
||||
**/
|
||||
|
||||
// TODO Support array arguments in sql server
|
||||
/*
|
||||
* $query_emp="select name from employee where id in (?,?,?)";
|
||||
$params_emp= Array(1,2,3);
|
||||
$res_emp = sqlsrv_query($conn, $query_emp, $params_emp);
|
||||
*
|
||||
*/
|
||||
|
||||
function _query($query) {
|
||||
if($this->is_connected == false || !$query) return;
|
||||
|
||||
|
|
@ -167,8 +176,11 @@
|
|||
if(count($this->param)){
|
||||
foreach($this->param as $k => $o){
|
||||
if($o->getType() == 'number'){
|
||||
$_param[] = $o->getUnescapedValue();
|
||||
$value = $o->getUnescapedValue();
|
||||
if(is_array($value)) $_param = array_merge($_param, $value);
|
||||
else $_param[] = $o->getUnescapedValue();
|
||||
}else{
|
||||
// TODO treat arrays here too
|
||||
$value = $o->getUnescapedValue();
|
||||
$_param[] = array($value, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'));
|
||||
}
|
||||
|
|
@ -419,7 +431,7 @@
|
|||
**/
|
||||
// TODO Lookup _filterNumber against sql injection - see if it is still needed and how to integrate
|
||||
function _executeInsertAct($queryObject) {
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
$query = $this->getInsertSql($queryObject, false);
|
||||
$this->param = $queryObject->getArguments();
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -428,7 +440,7 @@
|
|||
* @brief Handle updateAct
|
||||
**/
|
||||
function _executeUpdateAct($queryObject) {
|
||||
$query = $this->getUpdateSql($queryObject);
|
||||
$query = $this->getUpdateSql($queryObject, false);
|
||||
$this->param = $queryObject->getArguments();
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -437,7 +449,7 @@
|
|||
* @brief Handle deleteAct
|
||||
**/
|
||||
function _executeDeleteAct($queryObject) {
|
||||
$query = $this->getDeleteSql($queryObject);
|
||||
$query = $this->getDeleteSql($queryObject, false);
|
||||
$this->param = $queryObject->getArguments();
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -490,11 +502,11 @@
|
|||
// TODO Decide if we continue to pass parameters like this
|
||||
$this->param = $queryObject->getArguments();
|
||||
|
||||
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
|
||||
$result = $this->_query($query);
|
||||
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
|
||||
$result = $this->_query($query);
|
||||
|
||||
if ($this->isError ()) return $this->queryError($queryObject);
|
||||
else return $this->queryPageLimit($queryObject, $result);
|
||||
if ($this->isError ()) return $this->queryError($queryObject);
|
||||
else return $this->queryPageLimit($queryObject, $result);
|
||||
}
|
||||
|
||||
function getParser(){
|
||||
|
|
|
|||
|
|
@ -38,8 +38,18 @@
|
|||
}
|
||||
|
||||
function toStringWithoutValue(){
|
||||
if($this->hasArgument())
|
||||
return $this->pipe . ' ' . $this->getConditionPart("?");
|
||||
if($this->hasArgument()){
|
||||
$value = $this->argument->getUnescapedValue();
|
||||
|
||||
if(is_array($value)){
|
||||
$q = '';
|
||||
foreach ($value as $v) $q .= '?,';
|
||||
if($q !== '') $q = substr($q, 0, -1);
|
||||
$q = '(' . $q . ')';
|
||||
}
|
||||
else $q = '?';
|
||||
return $this->pipe . ' ' . $this->getConditionPart($q);
|
||||
}
|
||||
else return $this->toString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,16 @@
|
|||
|
||||
function getExpressionWithValue(){
|
||||
$value = $this->argument->getValue();
|
||||
$operation = $this->argument->getColumnOperation();
|
||||
if(isset($operation))
|
||||
return "$this->column_name = $this->column_name $operation $value";
|
||||
return "$this->column_name = $value";
|
||||
}
|
||||
|
||||
function getExpressionWithoutValue(){
|
||||
$operation = $this->argument->getColumnOperation();
|
||||
if(isset($operation))
|
||||
return "$this->column_name = $this->column_name $operation ?";
|
||||
return "$this->column_name = ?";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
var $isValid;
|
||||
var $errorMessage;
|
||||
|
||||
var $column_operation;
|
||||
|
||||
function Argument($name, $value){
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
|
|
@ -24,6 +26,10 @@
|
|||
$this->type = $value;
|
||||
}
|
||||
|
||||
function setColumnOperation($operation){
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
|
@ -33,8 +39,12 @@
|
|||
return $this->toString($value);
|
||||
}
|
||||
|
||||
function getColumnOperation(){
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getUnescapedValue(){
|
||||
return $this->toString($this->value);
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function toString($value){
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@
|
|||
var $column_name;
|
||||
var $value;
|
||||
var $is_sequence = false;
|
||||
var $is_operation = false;
|
||||
var $operation = '';
|
||||
|
||||
function DefaultValue($column_name, $value){
|
||||
$this->column_name = $column_name;
|
||||
$dbParser = &XmlQueryParser::getDBParser();
|
||||
$this->column_name = $dbParser->parseColumnName($column_name);
|
||||
$this->value = $value;
|
||||
$this->value = $this->_setValue();
|
||||
}
|
||||
|
|
@ -21,6 +24,14 @@
|
|||
return $this->is_sequence;
|
||||
}
|
||||
|
||||
function isOperation(){
|
||||
return $this->is_operation;
|
||||
}
|
||||
|
||||
function getOperation(){
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
function _setValue(){
|
||||
if(!isset($this->value)) return;
|
||||
|
||||
|
|
@ -54,16 +65,21 @@
|
|||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
// TODO Make sure column name is escaped
|
||||
$val = sprintf('"%s+%d"', $this->column_name, $args);
|
||||
$this->is_operation = true;
|
||||
$this->operation = '+';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('"%s-%d"', $this->column_name, $args);
|
||||
break;
|
||||
$this->is_operation = true;
|
||||
$this->operation = '-';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'multiply' :
|
||||
$args = intval($args);
|
||||
$val = sprintf('"%s*%d"', $this->column_name, $args);
|
||||
$this->is_operation = true;
|
||||
$this->operation = '*';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
default :
|
||||
$val = '\'' . $this->value . '\'';
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@
|
|||
$this->default_value = new DefaultValue($this->argument_name, $this->default_value);
|
||||
if($this->default_value->isSequence())
|
||||
$validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); ';
|
||||
if($this->default_value->isOperation())
|
||||
$validator .= sprintf("$%s_argument->setColumnOperation('%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->getOperation()
|
||||
);
|
||||
$validator .= sprintf("$%s_argument->ensureDefaultValue(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->toString()
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
require_once(_XE_PATH_.'test-phpUnit/db/DBTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/CubridTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/CubridOnlineTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/MssqlTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/MssqlOnlineTest.php');
|
||||
|
||||
require_once(_XE_PATH_.'config/config.inc.php');
|
||||
// require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
$oContext->setDbInfo($db_info);
|
||||
|
||||
// remove cache dir
|
||||
$tmp_cache_list = FileHandler::readDir('./files','/(^cache_[0-9]+)/');
|
||||
if($tmp_cache_list){
|
||||
foreach($tmp_cache_list as $tmp_dir){
|
||||
if($tmp_dir) FileHandler::removeDir('./files/'.$tmp_dir);
|
||||
}
|
||||
}
|
||||
FileHandler::removeDir( _XE_PATH_ . 'files/cache');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
$db = &DB::getInstance();
|
||||
$querySql = $db->{$methodName}($output);
|
||||
$querySql = $db->{$methodName}($output, false);
|
||||
$queryArguments = $output->getArguments();
|
||||
|
||||
// Remove whitespaces, tabs and all
|
||||
|
|
|
|||
41
test-phpUnit/db/MssqlOnlineTest.php
Normal file
41
test-phpUnit/db/MssqlOnlineTest.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base class for tests for MSSQL SQL syntax
|
||||
*/
|
||||
|
||||
class MssqlOnlineTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backupGlobals = FALSE;
|
||||
protected $backupStaticAttributes = FALSE;
|
||||
protected $preserveGlobalState = FALSE;
|
||||
|
||||
/**
|
||||
* Prepare runtime context - tell DB class that current DB is CUBRID
|
||||
*/
|
||||
protected function setUp() {
|
||||
$oContext = &Context::getInstance();
|
||||
|
||||
$db_info->db_type = 'mssql';
|
||||
$db_info->db_port = '3306';
|
||||
$db_info->db_hostname = 'PHENOMII\SQL2008EXPRESS';
|
||||
$db_info->db_userid = 'dba';
|
||||
$db_info->db_password = 'arniarules';
|
||||
$db_info->db_database = 'xe-15-db';
|
||||
$db_info->db_table_prefix = 'xe';
|
||||
|
||||
$oContext->setDbInfo($db_info);
|
||||
|
||||
// remove cache dir
|
||||
FileHandler::removeDir( _XE_PATH_ . 'files/cache');
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources - reset static DB and QueryParser
|
||||
*/
|
||||
protected function tearDown() {
|
||||
unset($GLOBALS['__DB__']);
|
||||
XmlQueryParser::setDBParser(null);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
AND "module_srl" = 47374';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
function test_module_updateMember(){
|
||||
function test_member_updateLastLogin(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/updateLastLogin.xml";
|
||||
$argsString = ' $args->member_srl = 4;
|
||||
$args->last_login = "20110607120549";';
|
||||
|
|
@ -52,8 +52,8 @@
|
|||
$xml_file = _XE_PATH_ . "modules/counter/queries/updateCounterUnique.xml";
|
||||
$argsString = '$args->regdate = 20110607;
|
||||
';
|
||||
$expected = 'UPDATE "xe_counter_status" SET "unique_visitor" = unique_visitor+1,
|
||||
"pageview" = pageview+1 WHERE "regdate" = 20110607 ';
|
||||
$expected = 'UPDATE "xe_counter_status" SET "unique_visitor" = "unique_visitor" + 1,
|
||||
"pageview" = "pageview" + 1 WHERE "regdate" = 20110607 ';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,15 @@
|
|||
$this->_test($xml_file, $argsString, $expected, array("'opage'", "'%yuhuu%'"));
|
||||
}
|
||||
|
||||
function test_module_getExtraVars(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleExtraVars.xml";
|
||||
$argsString = '$args->module_srl = 25;';
|
||||
$expected = 'SELECT * FROM [xe_module_extra_vars] as [module_extra_vars] WHERE [module_srl] in (?)';
|
||||
$this->_test($xml_file, $argsString, $expected, array("25"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO Something fishy about this query - to be investigated
|
||||
/*
|
||||
function test_syndication_getGrantedModules(){
|
||||
|
|
|
|||
12
test-phpUnit/db/xml_query/mssql/MssqlUpdateOnlineTest.php
Normal file
12
test-phpUnit/db/xml_query/mssql/MssqlUpdateOnlineTest.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
class MssqlUpdateOnlineTest extends MssqlOnlineTest {
|
||||
|
||||
function test_counter_updateCounterUnique(){
|
||||
$args->regdate = 20110211;
|
||||
|
||||
$output = executeQuery("counter.updateCounterUnique", $args);
|
||||
$this->assertEquals(0, $output->error, $output->error + ' ' + $output->message);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
17
test-phpUnit/db/xml_query/mssql/MssqlUpdateTest.php
Normal file
17
test-phpUnit/db/xml_query/mssql/MssqlUpdateTest.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||
|
||||
class MssqlUpdateTest extends MssqlTest {
|
||||
|
||||
function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){
|
||||
$this->_testPreparedQuery($xml_file, $argsString, $expected, 'getUpdateSql', $expectedArgs = NULL);
|
||||
}
|
||||
|
||||
function test_counter_updateCounterUnique(){
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/updateCounterUnique.xml";
|
||||
$argsString = '$args->regdate = 25;';
|
||||
$expected = 'UPDATE [xe_counter_status] SET [unique_visitor] = [unique_visitor] + ?, [pageview] = [pageview] + ? WHERE [regdate] = ?';
|
||||
$this->_test($xml_file, $argsString, $expected, array("25", 1, 1));
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue