mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-27 23:29:57 +09:00
Updated Condition query part class to make code more readable and reduce calls to ->hasArgument().
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9035 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
833dcfae37
commit
3f8d72b537
7 changed files with 92 additions and 38 deletions
|
|
@ -31,6 +31,9 @@
|
||||||
require(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
|
||||||
require(_XE_PATH_.'classes/db/queryparts/condition/ConditionGroup.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/condition/ConditionGroup.class.php');
|
||||||
require(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
||||||
|
require(_XE_PATH_.'classes/db/queryparts/condition/ConditionWithArgument.class.php');
|
||||||
|
require(_XE_PATH_.'classes/db/queryparts/condition/ConditionWithoutArgument.class.php');
|
||||||
|
require(_XE_PATH_.'classes/db/queryparts/condition/ConditionSubquery.class.php');
|
||||||
require(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.class.php');
|
||||||
require(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||||
require(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
require(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||||
|
|
|
||||||
|
|
@ -8,29 +8,14 @@
|
||||||
|
|
||||||
var $_value;
|
var $_value;
|
||||||
|
|
||||||
function Condition($column_name, $argument, $operation, $pipe = ""){
|
function Condition($column_name, $argument, $operation, $pipe){
|
||||||
$this->column_name = $column_name;
|
$this->column_name = $column_name;
|
||||||
$this->argument = $argument;
|
$this->argument = $argument;
|
||||||
$this->operation = $operation;
|
$this->operation = $operation;
|
||||||
$this->pipe = $pipe;
|
$this->pipe = $pipe;
|
||||||
if($this->hasArgument())
|
|
||||||
$this->_value = $argument->getValue();
|
|
||||||
else if(is_a($this->argument, 'Subquery'))
|
|
||||||
$this->_value = $argument->toString();
|
|
||||||
else {
|
|
||||||
if(in_array($operation, array('in', 'not in')))
|
|
||||||
$this->_value = '('. $argument .')';
|
|
||||||
else
|
|
||||||
$this->_value = $argument;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasArgument(){
|
|
||||||
return is_a($this->argument, 'Argument');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArgument(){
|
function getArgument(){
|
||||||
if($this->hasArgument()) return $this->argument;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,19 +27,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function toStringWithoutValue(){
|
function toStringWithoutValue(){
|
||||||
if($this->hasArgument()){
|
return $this->argument;
|
||||||
$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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toStringWithValue(){
|
function toStringWithValue(){
|
||||||
|
|
@ -66,8 +39,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(){
|
function show(){
|
||||||
if($this->hasArgument() && !$this->argument->isValid()) return false;
|
|
||||||
if($this->hasArgument() && ($this->_value === '\'\'')) return false;
|
|
||||||
if(is_array($this->_value) && count($this->_value) === 1 && $this->_value[0] === '') return false;
|
if(is_array($this->_value) && count($this->_value) === 1 && $this->_value[0] === '') return false;
|
||||||
switch($this->operation) {
|
switch($this->operation) {
|
||||||
case 'equal' :
|
case 'equal' :
|
||||||
|
|
@ -91,7 +62,7 @@
|
||||||
if(count($this->_value)!=2) return false;
|
if(count($this->_value)!=2) return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConditionPart($value) {
|
function getConditionPart($value) {
|
||||||
|
|
|
||||||
11
classes/db/queryparts/condition/ConditionSubquery.class.php
Normal file
11
classes/db/queryparts/condition/ConditionSubquery.class.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ConditionSubquery extends Condition {
|
||||||
|
|
||||||
|
function ConditionSubquery($column_name, $argument, $operation, $pipe = ""){
|
||||||
|
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||||
|
$this->_value = $this->argument->toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ConditionWithArgument extends Condition {
|
||||||
|
|
||||||
|
function ConditionWithArgument($column_name, $argument, $operation, $pipe = ""){
|
||||||
|
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||||
|
$this->_value = $argument->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArgument(){
|
||||||
|
return $this->argument;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toStringWithoutValue(){
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(){
|
||||||
|
if(!$this->argument->isValid()) return false;
|
||||||
|
if($this->_value === '\'\'') return false;
|
||||||
|
return parent::show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ConditionWithoutArgument extends Condition {
|
||||||
|
function ConditionWithoutArgument($column_name, $argument, $operation, $pipe = ""){
|
||||||
|
parent::Condition($column_name, $argument, $operation, $pipe);
|
||||||
|
if(in_array($operation, array('in', 'not in')))
|
||||||
|
$this->_value = '('. $argument .')';
|
||||||
|
else
|
||||||
|
$this->_value = $argument;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -56,12 +56,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConditionString(){
|
function getConditionString(){
|
||||||
return sprintf("new Condition('%s',%s,%s%s)"
|
if($this->query){
|
||||||
, $this->column_name
|
return sprintf("new ConditionSubquery('%s',%s,%s%s)"
|
||||||
, $this->default_column ? $this->default_column: '$' . $this->argument_name . '_argument'
|
, $this->column_name
|
||||||
, '"'.$this->operation.'"'
|
, $this->default_column
|
||||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
, '"'.$this->operation.'"'
|
||||||
);
|
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if($this->default_column){
|
||||||
|
return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)"
|
||||||
|
, $this->column_name
|
||||||
|
, $this->default_column
|
||||||
|
, '"'.$this->operation.'"'
|
||||||
|
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
|
||||||
|
, $this->column_name
|
||||||
|
, '$' . $this->argument_name . '_argument'
|
||||||
|
, '"'.$this->operation.'"'
|
||||||
|
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -40,6 +40,9 @@
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/table/JoinTable.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/ConditionGroup.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
||||||
|
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionWithArgument.class.php');
|
||||||
|
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionWithoutArgument.class.php');
|
||||||
|
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionSubquery.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.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/order/OrderByColumn.class.php');
|
||||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue