mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-24 04:42:14 +09:00
Updated the query parts that work with arguments (conditions, update and insert expressions) to work with QueryArgument objects instead of string values.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8457 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
e41c45433e
commit
313bfca8e8
18 changed files with 120 additions and 169 deletions
|
|
@ -2,19 +2,39 @@
|
|||
|
||||
class Condition {
|
||||
var $column_name;
|
||||
var $value;
|
||||
var $argument;
|
||||
var $operation;
|
||||
var $pipe;
|
||||
|
||||
function Condition($column_name, $value, $operation, $pipe = ""){
|
||||
var $_value;
|
||||
|
||||
function Condition($column_name, $argument, $operation, $pipe = ""){
|
||||
$this->column_name = $column_name;
|
||||
$this->value = $value;
|
||||
$this->argument = $argument;
|
||||
$this->operation = $operation;
|
||||
$this->pipe = $pipe;
|
||||
if($this->hasArgument())
|
||||
$this->_value = $argument->getValue();
|
||||
else
|
||||
$this->_value = $argument;
|
||||
}
|
||||
|
||||
function hasArgument(){
|
||||
return is_a($this->argument, 'Argument');
|
||||
}
|
||||
|
||||
function toString(){
|
||||
return $this->pipe . ' ' . $this->getConditionPart();
|
||||
return $this->toStringWithValue();
|
||||
}
|
||||
|
||||
function toStringWithoutValue(){
|
||||
if($this->hasArgument())
|
||||
return $this->pipe . ' ' . $this->getConditionPart("?");
|
||||
else return $this->toString();
|
||||
}
|
||||
|
||||
function toStringWithValue(){
|
||||
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
|
||||
}
|
||||
|
||||
function setPipe($pipe){
|
||||
|
|
@ -35,22 +55,20 @@
|
|||
case 'notin' :
|
||||
case 'notequal' :
|
||||
// if variable is not set or is not string or number, return
|
||||
if(!isset($this->value)) return false;
|
||||
if($this->value === '') return false;
|
||||
if(!in_array(gettype($this->value), array('string', 'integer'))) return false;
|
||||
if(!isset($this->_value)) return false;
|
||||
if($this->_value === '') return false;
|
||||
if(!in_array(gettype($this->_value), array('string', 'integer'))) return false;
|
||||
break;
|
||||
case 'between' :
|
||||
if(!is_array($this->value)) return false;
|
||||
if(count($this->value)!=2) return false;
|
||||
if(!is_array($this->_value)) return false;
|
||||
if(count($this->_value)!=2) return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getConditionPart() {
|
||||
|
||||
|
||||
function getConditionPart($value) {
|
||||
$name = $this->column_name;
|
||||
$value = $this->value;
|
||||
$operation = $this->operation;
|
||||
|
||||
switch($operation) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// TODO Fix this class
|
||||
class DeleteExpression extends Expression {
|
||||
var $value;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,19 +8,20 @@
|
|||
*/
|
||||
|
||||
class InsertExpression extends Expression {
|
||||
var $value;
|
||||
var $argument;
|
||||
|
||||
function InsertExpression($column_name, $value){
|
||||
function InsertExpression($column_name, $argument){
|
||||
parent::Expression($column_name);
|
||||
$this->value = $value;
|
||||
$this->argument = $argument;
|
||||
}
|
||||
|
||||
function getValue(){
|
||||
return $this->value;
|
||||
return $this->argument->getValue();
|
||||
}
|
||||
|
||||
function show(){
|
||||
if(!isset($this->value)) return false;
|
||||
$value = $this->argument->getValue();
|
||||
if(!isset($value)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,25 +7,35 @@
|
|||
*/
|
||||
|
||||
class UpdateExpression extends Expression {
|
||||
var $value;
|
||||
var $argument;
|
||||
|
||||
function UpdateExpression($column_name, $value){
|
||||
function UpdateExpression($column_name, $argument){
|
||||
parent::Expression($column_name);
|
||||
$this->value = $value;
|
||||
$this->argument = $argument;
|
||||
}
|
||||
|
||||
function getExpression(){
|
||||
return "$this->column_name = $this->value";
|
||||
return $this->getExpressionWithValue();
|
||||
}
|
||||
|
||||
function getExpressionWithValue(){
|
||||
$value = $this->argument->getValue();
|
||||
return "$this->column_name = $value";
|
||||
}
|
||||
|
||||
function getExpressionWithoutValue(){
|
||||
return "$this->column_name = ?";
|
||||
}
|
||||
|
||||
function getValue(){
|
||||
// TODO Escape value according to column type instead of variable type
|
||||
if(!is_numeric($this->value)) return "'".$this->value."'";
|
||||
return $this->value;
|
||||
$value = $this->argument->getValue();
|
||||
if(!is_numeric($value)) return "'".$value."'";
|
||||
return $value;
|
||||
}
|
||||
|
||||
function show(){
|
||||
if(!$this->value) return false;
|
||||
if(!$this->argument->getValue()) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@
|
|||
}
|
||||
|
||||
function getLimit(){
|
||||
return $this->list_count;
|
||||
return $this->list_count->getValue();
|
||||
}
|
||||
|
||||
function toString(){
|
||||
if ($this->page) return $this->start . ' , ' . $this->list_count;
|
||||
else return $this->list_count;
|
||||
if ($this->page) return $this->start . ' , ' . $this->list_count->getValue();
|
||||
else return $this->list_count->getValue();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -9,7 +9,10 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
return $this->column_name . ' ' . $this->sort_order;
|
||||
$result = is_a($this->column_name, 'Argument') ? $this->column_name->getValue() : $this->column_name;
|
||||
$result .= ' ';
|
||||
$result .= is_a($this->sort_order, 'Argument') ? $this->sort_order->getValue() : $this->sort_order;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@
|
|||
if(__DEBUG__==3) $start = getMicroTime();
|
||||
|
||||
$this->lang = Context::getLangType();
|
||||
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
$this->input = str_replace(array('',''),array('',''),$this->input);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@
|
|||
/* function &getDBParser(){
|
||||
static $dbParser;
|
||||
if(!$dbParser){
|
||||
$oDB = &DB::getInstance();
|
||||
$dbParser = $oDB->getParser();
|
||||
//$oDB = &DB::getInstance();
|
||||
//$dbParser = $oDB->getParser();
|
||||
return new DBParser('"');
|
||||
}
|
||||
return $dbParser;
|
||||
}*/
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
|
||||
function getExpressionString(){
|
||||
return sprintf('new InsertExpression(\'%s\', $%s_argument->getValue())'
|
||||
return sprintf('new InsertExpression(\'%s\', $%s_argument)'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
}
|
||||
|
||||
function getExpressionString(){
|
||||
return sprintf('new UpdateExpression(\'%s\', $%s_argument->getValue())'
|
||||
return sprintf('new UpdateExpression(\'%s\', $%s_argument)'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
function getConditionString(){
|
||||
return sprintf("new Condition('%s',%s,%s%s)"
|
||||
, $this->column_name
|
||||
, $this->default_column ? "'" . $this->default_column . "'" : '$' . $this->argument_name . '_argument->getValue()'
|
||||
, $this->default_column ? "'" . $this->default_column . "'" : '$' . $this->argument_name . '_argument'
|
||||
, '"'.$this->operation.'"'
|
||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||
);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
return sprintf("new OrderByColumn(\$%s_argument->getValue(), %s)", $this->argument_name, $this->sort_order);
|
||||
return sprintf("new OrderByColumn(\$%s_argument, %s)", $this->argument_name, $this->sort_order);
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
if ($this->page)return sprintf("new Limit(\$%s_argument->getValue(), \$%s_argument->getValue(), \$%s_argument->getValue())",$this->list_count->var, $this->page->var, $this->page_count->var);
|
||||
else return sprintf("new Limit(\$%s_argument->getValue())", $this->list_count->var);
|
||||
if ($this->page)return sprintf("new Limit(\$%s_argument, \$%s_argument, \$%s_argument)",$this->list_count->var, $this->page->var, $this->page_count->var);
|
||||
else return sprintf("new Limit(\$%s_argument)", $this->list_count->var);
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
echo $outputString;
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
|
|
@ -35,4 +34,9 @@
|
|||
and "act" = \'tata\'';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
// $queryTester->test_admin_deleteActionForward();
|
||||
// $queryTester->test_module_insertModule();
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
echo $xml_file . $argsString;
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
//echo $outputString;
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
|
|
@ -62,79 +62,9 @@
|
|||
, \'n\')';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
// $queryTester->test_admin_deleteActionForward();
|
||||
// $queryTester->test_module_insertModule();
|
||||
|
||||
function test_module_insertSiteTodayStatus(){
|
||||
//\''.date("YmdHis").'\'
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/insertTodayStatus.xml";
|
||||
$argsString = ' $args->regdate = 0;
|
||||
$args->unique_visitor = 0;
|
||||
$args->pageview = 0;';
|
||||
$expected = 'insert into "xe_counter_status"
|
||||
("regdate"
|
||||
, "unique_visitor"
|
||||
, "pageview")
|
||||
values
|
||||
(0
|
||||
, 0
|
||||
, 0)';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertCounterLog(){
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/insertCounterLog.xml";
|
||||
$argsString = ' $args->site_srl = 0;
|
||||
$args->regdate = "20110607120619";
|
||||
$args->ipaddress = "127.0.0.1";
|
||||
$args->user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Safari/534.24";';
|
||||
$expected = 'insert into "xe_counter_log"
|
||||
("site_srl", "regdate", "ipaddress", "user_agent")
|
||||
VALUES (0, \'20110607120619\', \'127.0.0.1\', \'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Safari/534.24\')
|
||||
';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertMember(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/insertMember.xml";
|
||||
$argsString = ' $args->member_srl = 203;
|
||||
$args->user_id = "cacao";
|
||||
$args->email_address = "teta@ar.ro";
|
||||
$args->password = "23e5484cb88f3c07bcce2920a5e6a2a7";
|
||||
$args->email_id = "teta";
|
||||
$args->email_host = "ar.ro";
|
||||
$args->user_name = "trident";
|
||||
$args->nick_name = "aloha";
|
||||
$args->homepage = "http://jkgjfk./ww";
|
||||
$args->allow_mailing = "Y";
|
||||
$args->allow_message = "Y";
|
||||
$args->denied = "N";
|
||||
$args->limit_date = "";
|
||||
$args->regdate = "20110607121952";
|
||||
$args->change_password_date = "20110607121952";
|
||||
$args->last_login = "20110607121952";
|
||||
$args->is_admin = "N";
|
||||
$args->extra_vars = "O:8:\"stdClass\":2:{s:4:\"body\";s:0:\"\";s:7:\"_filter\";s:6:\"insert\";}";
|
||||
$args->list_order = -203;
|
||||
';
|
||||
$expected = 'INSERT INTO "xe_member"
|
||||
("member_srl", "user_id", "email_address", "password", "email_id", "email_host", "user_name", "nick_name",
|
||||
"homepage", "allow_mailing", "allow_message", "denied", "limit_date", "regdate", "change_password_date",
|
||||
"last_login", "is_admin", "extra_vars", "list_order")
|
||||
VALUES (203, \'cacao\', \'teta@ar.ro\', \'23e5484cb88f3c07bcce2920a5e6a2a7\', \'teta\', \'ar.ro\', \'trident\',
|
||||
\'aloha\', \'http://jkgjfk./ww\', \'Y\', \'Y\', \'N\', \'\', \'20110607121952\', \'20110607121952\',
|
||||
\'20110607121952\', \'N\', \'O:8:"stdClass":2:{s:4:"body";s:0:"";s:7:"_filter";s:6:"insert";}\', -203)';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertModuleExtraVars(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/insertModuleExtraVars.xml";
|
||||
$argsString = ' $args->module_srl = 202;
|
||||
$args->name = "_filter";
|
||||
$args->value = "insert_page";
|
||||
';
|
||||
$expected = 'INSERT INTO "xe_module_extra_vars"
|
||||
("module_srl", "name", "value")
|
||||
VALUES (202, \'_filter\', \'insert_page\')
|
||||
';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
|
|
@ -166,5 +167,14 @@
|
|||
or "group_srl" = -2)
|
||||
group by "module_srl"';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
// $queryTester->test_admin_deleteActionForward();
|
||||
// $queryTester->test_module_insertModule();
|
||||
// $queryTester->test_module_updateModule();
|
||||
|
||||
|
||||
// $queryTester->test_opage_getOpageList();
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -47,38 +47,9 @@
|
|||
AND "module_srl" = 47374';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
// $queryTester->test_admin_deleteActionForward();
|
||||
// $queryTester->test_module_insertModule();
|
||||
|
||||
function test_module_updateMember(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/updateLastLogin.xml";
|
||||
$argsString = ' $args->member_srl = 4;
|
||||
$args->last_login = "20110607120549";';
|
||||
$expected = 'UPDATE "xe_member" SET "member_srl" = 4, "last_login" = \'20110607120549\' WHERE "member_srl" = 4';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updatePoint(){
|
||||
$xml_file = _XE_PATH_ . "modules/point/queries/updatePoint.xml";
|
||||
$argsString = ' $args->member_srl = 4;
|
||||
$args->point = 105;';
|
||||
$expected = 'UPDATE "xe_point" SET "point" = 105 WHERE "member_srl" = 4';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updateCounterUnique(){
|
||||
$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 ';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updateMenu(){
|
||||
$xml_file = _XE_PATH_ . "modules/menu/queries/updateMenu.xml";
|
||||
$argsString = '$args->menu_srl = 204;
|
||||
$args->title = "test_menu";
|
||||
';
|
||||
$expected = 'UPDATE "xe_menu" SET "title" = \'test_menu\' WHERE "menu_srl" = 204';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +1,38 @@
|
|||
<?php
|
||||
// Report all errors except E_NOTICE
|
||||
// This is the default value set in php.ini
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
<?php
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
define('_XE_PATH_', str_replace('test-phpUnit/config.inc.php', '', str_replace('\\', '/', __FILE__)));
|
||||
|
||||
require_once('QueryTester.class.php');
|
||||
require_once('Helper.class.php');
|
||||
//define('_TEST_PATH_', substr(_XE_PATH_,0,strrpos(substr(_XE_PATH_,0.-1),'/')));
|
||||
|
||||
if(!defined('__DEBUG__')) define('__DEBUG__', 4);
|
||||
|
||||
require_once(_XE_PATH_.'test-phpUnit/Helper.class.php');
|
||||
|
||||
require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||
require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require_once(_XE_PATH_.'classes/context/Context.class.php');
|
||||
require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/DB.class.php');
|
||||
|
||||
require_once('QueryTester.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
|
||||
|
||||
|
||||
require_once(_XE_PATH_.'classes/db/DB.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/DBCubrid.class.php');
|
||||
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/Argument.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/Expression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/InsertExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/UpdateExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/Table.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/ConditionArgument.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionGroup.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/SelectExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/DBParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/Argument.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/ConditionArgument.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/Expression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/SelectExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/InsertExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/UpdateExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/Table.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionGroup.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue