mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-13 16:34:52 +09:00
merge from 1.5.2
git-svn-id: http://xe-core.googlecode.com/svn/trunk@10446 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
6c23751ef8
commit
c727926d9e
382 changed files with 6855 additions and 3603 deletions
|
|
@ -103,6 +103,7 @@
|
|||
if($this->isStarFunction($column_name)){
|
||||
return $column_name;
|
||||
}
|
||||
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,209 +1,209 @@
|
|||
<?php
|
||||
|
||||
class Argument {
|
||||
var $value;
|
||||
var $name;
|
||||
var $type;
|
||||
class Argument {
|
||||
|
||||
var $isValid;
|
||||
var $errorMessage;
|
||||
var $value;
|
||||
var $name;
|
||||
var $type;
|
||||
var $isValid;
|
||||
var $errorMessage;
|
||||
var $column_operation;
|
||||
|
||||
var $uses_default_value; // Check if arg value is user submnitted or default
|
||||
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
|
||||
|
||||
var $column_operation;
|
||||
function Argument($name, $value) {
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->isValid = true;
|
||||
}
|
||||
|
||||
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
|
||||
function getType() {
|
||||
if (isset($this->type))
|
||||
return $this->type;
|
||||
if (is_string($this->value))
|
||||
return 'column_name';
|
||||
return 'number';
|
||||
}
|
||||
|
||||
function Argument($name, $value){
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->isValid = true;
|
||||
}
|
||||
function setColumnType($value) {
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
function getType(){
|
||||
if(isset($this->type)) return $this->type;
|
||||
if(is_string($this->value)) return 'column_name';
|
||||
return 'number';
|
||||
}
|
||||
function setColumnOperation($operation) {
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function setColumnType($value){
|
||||
$this->type = $value;
|
||||
}
|
||||
function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function setColumnOperation($operation){
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function getValue(){
|
||||
if(!isset($this->_value)){
|
||||
function getValue() {
|
||||
if (!isset($this->_value)) {
|
||||
$value = $this->getEscapedValue();
|
||||
$this->_value = $this->toString($value);
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
function getColumnOperation(){
|
||||
return $this->column_operation;
|
||||
}
|
||||
function getColumnOperation() {
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getEscapedValue(){
|
||||
return $this->escapeValue($this->value);
|
||||
}
|
||||
function getEscapedValue() {
|
||||
return $this->escapeValue($this->value);
|
||||
}
|
||||
|
||||
function getUnescapedValue(){
|
||||
return $this->value;
|
||||
function getUnescapedValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function toString($value) {
|
||||
if (is_array($value)) {
|
||||
if (count($value) === 0)
|
||||
return '';
|
||||
if (count($value) === 1 && $value[0] === '')
|
||||
return '';
|
||||
return '(' . implode(',', $value) . ')';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function toString($value){
|
||||
if(is_array($value)){
|
||||
if(count($value) === 0) return '';
|
||||
if(count($value) === 1 && $value[0] === '') return '';
|
||||
return '('.implode(',', $value).')';
|
||||
}
|
||||
return $value;
|
||||
function escapeValue($value) {
|
||||
$column_type = $this->getType();
|
||||
if ($column_type == 'column_name') {
|
||||
$dbParser = DB::getParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if (!isset($value))
|
||||
return null;
|
||||
|
||||
function escapeValue($value){
|
||||
$column_type = $this->getType();
|
||||
if($column_type == 'column_name'){
|
||||
$dbParser = DB::getParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) {
|
||||
if (!is_array($value))
|
||||
$value = $this->_escapeStringValue($value);
|
||||
else {
|
||||
$total = count($value);
|
||||
for ($i = 0; $i < $total; $i++)
|
||||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||
//$value[$i] = '\''.$value[$i].'\'';
|
||||
}
|
||||
if(!isset($value)) return null;
|
||||
|
||||
if(in_array($column_type, array('date', 'varchar', 'char','text', 'bigtext'))){
|
||||
if(!is_array($value))
|
||||
$value = $this->_escapeStringValue ($value);
|
||||
else {
|
||||
$total = count($value);
|
||||
for($i = 0; $i < $total; $i++)
|
||||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||
//$value[$i] = '\''.$value[$i].'\'';
|
||||
}
|
||||
}
|
||||
if($column_type == 'number')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
foreach($value AS $key=>$val)
|
||||
{
|
||||
if(isset($val))
|
||||
{
|
||||
$value[$key] = (int)$val;
|
||||
}
|
||||
}
|
||||
if($this->uses_default_value) return $value;
|
||||
if ($column_type == 'number') {
|
||||
if (is_array($value)) {
|
||||
foreach ($value AS $key => $val) {
|
||||
if (isset($val)) {
|
||||
$value[$key] = (int) $val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($val))
|
||||
{
|
||||
$value = (int)$value;
|
||||
} else {
|
||||
$value = (int) $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function _escapeStringValue($value) {
|
||||
$db = &DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
return '\'' . $value . '\'';
|
||||
}
|
||||
|
||||
function isValid() {
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function getErrorMessage() {
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
function ensureDefaultValue($default_value) {
|
||||
if (!isset($this->value) || $this->value == '')
|
||||
{
|
||||
$this->value = $default_value;
|
||||
$this->uses_default_value = true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkFilter($filter_type) {
|
||||
if (isset($this->value) && $this->value != '') {
|
||||
global $lang;
|
||||
$val = $this->value;
|
||||
$key = $this->name;
|
||||
switch ($filter_type) {
|
||||
case 'email' :
|
||||
case 'email_address' :
|
||||
if (!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function _escapeStringValue($value){
|
||||
$db = &DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
return '\''.$value.'\'';
|
||||
|
||||
}
|
||||
|
||||
function isValid(){
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function getErrorMessage(){
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
function ensureDefaultValue($default_value){
|
||||
if(!isset($this->value) || $this->value == '')
|
||||
$this->value = $default_value;
|
||||
}
|
||||
|
||||
function checkFilter($filter_type){
|
||||
if(isset($this->value) && $this->value != ''){
|
||||
global $lang;
|
||||
$val = $this->value;
|
||||
$key = $this->name;
|
||||
switch($filter_type) {
|
||||
case 'email' :
|
||||
case 'email_address' :
|
||||
if(!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'homepage' :
|
||||
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'userid' :
|
||||
case 'user_id' :
|
||||
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'number' :
|
||||
case 'numbers' :
|
||||
if(is_array($val)) $val = join(',', $val);
|
||||
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)){
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha' :
|
||||
if(!preg_match('/^[a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha_number' :
|
||||
if(!preg_match('/^[0-9a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkMaxLength($length){
|
||||
if($this->value && (strlen($this->value) > $length)){
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkMinLength($length){
|
||||
if($this->value && (strlen($this->value) < $length)){
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkNotNull(){
|
||||
if(!isset($this->value)){
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
||||
break;
|
||||
case 'homepage' :
|
||||
if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'userid' :
|
||||
case 'user_id' :
|
||||
if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'number' :
|
||||
case 'numbers' :
|
||||
if (is_array($val))
|
||||
$val = join(',', $val);
|
||||
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha' :
|
||||
if (!preg_match('/^[a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha_number' :
|
||||
if (!preg_match('/^[0-9a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkMaxLength($length) {
|
||||
if ($this->value && (strlen($this->value) > $length)) {
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkMinLength($length) {
|
||||
if ($this->value && (strlen($this->value) < $length)) {
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkNotNull() {
|
||||
if (!isset($this->value)) {
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,104 +1,115 @@
|
|||
<?php
|
||||
|
||||
class QueryArgument {
|
||||
var $argument_name;
|
||||
var $variable_name;
|
||||
var $argument_validator;
|
||||
var $column_name;
|
||||
var $operation;
|
||||
class QueryArgument {
|
||||
|
||||
var $ignore_value;
|
||||
var $argument_name;
|
||||
var $variable_name;
|
||||
var $argument_validator;
|
||||
var $column_name;
|
||||
var $table_name;
|
||||
var $operation;
|
||||
var $ignore_value;
|
||||
|
||||
function QueryArgument($tag, $ignore_value = false){
|
||||
static $number_of_arguments = 0;
|
||||
function QueryArgument($tag, $ignore_value = false) {
|
||||
static $number_of_arguments = 0;
|
||||
|
||||
$this->argument_name = $tag->attrs->var;
|
||||
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->name);
|
||||
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->column);
|
||||
$this->argument_name = $tag->attrs->var;
|
||||
if (!$this->argument_name)
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->name);
|
||||
if (!$this->argument_name)
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->column);
|
||||
|
||||
$this->variable_name = $this->argument_name;
|
||||
$this->variable_name = $this->argument_name;
|
||||
|
||||
$number_of_arguments++;
|
||||
$this->argument_name .= $number_of_arguments;
|
||||
$number_of_arguments++;
|
||||
$this->argument_name .= $number_of_arguments;
|
||||
|
||||
$name = $tag->attrs->name;
|
||||
if(!$name) $name = $tag->attrs->column;
|
||||
if(strpos($name, '.') === false) $this->column_name = $name;
|
||||
else {
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
}
|
||||
|
||||
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
$name = $tag->attrs->name;
|
||||
if (!$name)
|
||||
$name = $tag->attrs->column;
|
||||
if (strpos($name, '.') === false)
|
||||
$this->column_name = $name;
|
||||
else {
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
$this->table_name = $prefix;
|
||||
}
|
||||
|
||||
function getArgumentName(){
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName(){
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getValidatorString(){
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument(){
|
||||
if($this->operation) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
if($this->isConditionArgument()){
|
||||
// Instantiation
|
||||
$arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, '$args->'.$this->variable_name
|
||||
, $this->operation
|
||||
);
|
||||
// Call methods to validate argument and ensure default value
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
// Prepare condition string
|
||||
$arg .= sprintf("$%s_argument->createConditionValue();\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
|
||||
// Check that argument passed validation, else return
|
||||
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
else {
|
||||
$arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, $this->ignore_value ? 'null' : '$args->'.$this->variable_name);
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if($this->argument_validator->isIgnorable()){
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->'.$this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else \n$%s_argument = null;", $this->argument_name);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
if ($tag->attrs->operation)
|
||||
$this->operation = $tag->attrs->operation;
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
}
|
||||
|
||||
?>
|
||||
function getArgumentName() {
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName() {
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getTableName(){
|
||||
return $this->table_name;
|
||||
}
|
||||
|
||||
function getValidatorString() {
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument() {
|
||||
if ($this->operation)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function toString() {
|
||||
if ($this->isConditionArgument()) {
|
||||
// Instantiation
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, '$args->' . $this->variable_name
|
||||
, $this->operation
|
||||
);
|
||||
// Call methods to validate argument and ensure default value
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
// Prepare condition string
|
||||
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
|
||||
// Check that argument passed validation, else return
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
} else {
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, $this->ignore_value ? 'null' : '$args->' . $this->variable_name);
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if ($this->argument_validator->isIgnorable()) {
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class SortQueryArgument extends QueryArgument{
|
||||
function toString(){
|
||||
$arg = sprintf("\n$%s_argument = new SortArgument('%s', %s);\n"
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
, '$args->'.$this->variable_name);
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
|
|
|
|||
|
|
@ -30,19 +30,19 @@
|
|||
function toString(){
|
||||
$validator = '';
|
||||
if($this->filter){
|
||||
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length){
|
||||
$validator .= sprintf("$%s_argument->checkMinLength(%s);\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($this->max_length){
|
||||
$validator .= sprintf("$%s_argument->checkMaxLength(%s);\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);'. "\n"
|
||||
, $this->argument_name
|
||||
, $this->max_length
|
||||
);
|
||||
|
|
@ -52,17 +52,17 @@
|
|||
if($this->default_value->isSequence())
|
||||
$validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); ';
|
||||
if($this->default_value->isOperation())
|
||||
$validator .= sprintf("$%s_argument->setColumnOperation('%s');\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->getOperation()
|
||||
);
|
||||
$validator .= sprintf("$%s_argument->ensureDefaultValue(%s);\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->toString()
|
||||
);
|
||||
}
|
||||
if($this->notnull){
|
||||
$validator .= sprintf("$%s_argument->checkNotNull();\n"
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
|
@ -70,4 +70,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
}
|
||||
|
||||
function getExpressionString(){
|
||||
return sprintf('new InsertExpression(\'%s\', $%s_argument)'
|
||||
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
|
@ -28,4 +28,4 @@
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
function getExpressionString(){
|
||||
if($this->argument)
|
||||
return sprintf('new UpdateExpression(\'%s\', $%s_argument)'
|
||||
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
else {
|
||||
|
|
@ -59,4 +59,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
return sprintf("new OrderByColumn(\$%s_argument, %s)", $this->argument->getArgumentName(), $this->sort_order);
|
||||
return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order);
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
|
|
@ -40,4 +40,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
if ($this->page)return sprintf("new Limit(\$%s_argument, \$%s_argument, \$%s_argument)", $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
|
||||
else return sprintf("new Limit(\$%s_argument)", $this->list_count->getArgumentName());
|
||||
if ($this->page)return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
|
||||
else return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName());
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class QueryTag {
|
||||
|
||||
var $action;
|
||||
var $query_id;
|
||||
var $priority;
|
||||
var $column_type;
|
||||
var $query;
|
||||
|
||||
//xml tags
|
||||
var $columns;
|
||||
var $tables;
|
||||
|
|
@ -17,22 +17,22 @@ class QueryTag {
|
|||
var $preBuff;
|
||||
var $buff;
|
||||
var $isSubQuery;
|
||||
|
||||
var $join_type;
|
||||
var $join_type;
|
||||
var $alias;
|
||||
|
||||
function QueryTag($query, $isSubQuery = false){
|
||||
function QueryTag($query, $isSubQuery = false) {
|
||||
$this->action = $query->attrs->action;
|
||||
$this->query_id = $query->attrs->id;
|
||||
$this->priority = $query->attrs->priority;
|
||||
$this->query = $query;
|
||||
$this->isSubQuery = $isSubQuery;
|
||||
if($this->isSubQuery) $this->action = 'select';
|
||||
if($query->attrs->alias){
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
$this->join_type = $query->attrs->join_type;
|
||||
if ($this->isSubQuery)
|
||||
$this->action = 'select';
|
||||
if ($query->attrs->alias) {
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
$this->join_type = $query->attrs->join_type;
|
||||
|
||||
$this->getColumns();
|
||||
$tables = $this->getTables();
|
||||
|
|
@ -44,155 +44,175 @@ class QueryTag {
|
|||
$this->getBuff();
|
||||
}
|
||||
|
||||
function show(){
|
||||
function show() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getQueryId(){
|
||||
function getQueryId() {
|
||||
return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id;
|
||||
}
|
||||
|
||||
function getPriority(){
|
||||
function getPriority() {
|
||||
return $this->query->attrs->priority;
|
||||
}
|
||||
|
||||
function getAction(){
|
||||
function getAction() {
|
||||
return $this->query->attrs->action;
|
||||
}
|
||||
|
||||
function setTableColumnTypes($tables){
|
||||
function setTableColumnTypes($tables) {
|
||||
$query_id = $this->getQueryId();
|
||||
if(!isset($this->column_type[$query_id])){
|
||||
if (!isset($this->column_type[$query_id])) {
|
||||
$table_tags = $tables->getTables();
|
||||
$column_type = array();
|
||||
foreach($table_tags as $table_tag){
|
||||
if(is_a($table_tag, 'TableTag')){
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_tag->getTableName());
|
||||
$column_type = array_merge($column_type, $tag_column_type);
|
||||
}
|
||||
foreach ($table_tags as $table_tag) {
|
||||
if (is_a($table_tag, 'TableTag')) {
|
||||
$table_name = $table_tag->getTableName();
|
||||
$table_alias = $table_tag->getTableAlias();
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
|
||||
$column_type[$table_alias] = $tag_column_type;
|
||||
}
|
||||
}
|
||||
$this->column_type[$query_id] = $column_type;
|
||||
}
|
||||
}
|
||||
|
||||
function getColumns(){
|
||||
if($this->action == 'select'){
|
||||
return $this->columns = new SelectColumnsTag($this->query->columns);
|
||||
}else if($this->action == 'insert'){
|
||||
return $this->columns = new InsertColumnsTag($this->query->columns->column);
|
||||
}else if($this->action == 'update') {
|
||||
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
|
||||
}else if($this->action == 'delete') {
|
||||
return $this->columns = null;
|
||||
function getColumns() {
|
||||
if ($this->action == 'select') {
|
||||
return $this->columns = new SelectColumnsTag($this->query->columns);
|
||||
} else if ($this->action == 'insert') {
|
||||
return $this->columns = new InsertColumnsTag($this->query->columns->column);
|
||||
} else if ($this->action == 'update') {
|
||||
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
|
||||
} else if ($this->action == 'delete') {
|
||||
return $this->columns = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getPrebuff(){
|
||||
function getPrebuff() {
|
||||
// TODO Check if this work with arguments in join clause
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$prebuff = '';
|
||||
foreach($arguments as $argument){
|
||||
if(isset($argument)){
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if($arg_name){
|
||||
$prebuff .= $argument->toString();
|
||||
$column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()];
|
||||
if(isset($column_type))
|
||||
$prebuff .= sprintf("if($%s_argument !== null) $%s_argument->setColumnType('%s');\n"
|
||||
, $arg_name
|
||||
, $arg_name
|
||||
, $column_type );
|
||||
}
|
||||
}
|
||||
foreach ($arguments as $argument) {
|
||||
if (isset($argument)) {
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if ($arg_name) {
|
||||
unset($column_type);
|
||||
$prebuff .= $argument->toString();
|
||||
|
||||
$table_alias = $argument->getTableName();
|
||||
if(isset($table_alias))
|
||||
{
|
||||
$column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_tables = $this->column_type[$this->getQueryId()];
|
||||
$column_name = $argument->getColumnName();
|
||||
foreach($current_tables as $current_table)
|
||||
{
|
||||
if($current_table[$column_name])
|
||||
$column_type = $current_table[$column_name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($column_type))
|
||||
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
|
||||
, $arg_name
|
||||
, $arg_name
|
||||
, $column_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
$prebuff .= "\n";
|
||||
|
||||
return $this->preBuff = $prebuff;
|
||||
}
|
||||
|
||||
function getBuff(){
|
||||
function getBuff() {
|
||||
$buff = '';
|
||||
if($this->isSubQuery){
|
||||
if ($this->isSubQuery) {
|
||||
$buff = 'new Subquery(';
|
||||
$buff .= "'" . $this->alias . '\', ';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ). ', '.PHP_EOL;
|
||||
$buff .= $this->tables->toString() .','.PHP_EOL;
|
||||
$buff .= $this->conditions->toString() .',' .PHP_EOL;
|
||||
$buff .= $this->groups->toString() . ',' .PHP_EOL;
|
||||
$buff .= $this->navigation->getOrderByString() .','.PHP_EOL;
|
||||
$limit = $this->navigation->getLimitString() ;
|
||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL;
|
||||
$buff .= $this->tables->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->conditions->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->groups->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->navigation->getOrderByString() . ',' . PHP_EOL;
|
||||
$limit = $this->navigation->getLimitString();
|
||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||
$buff .= ')';
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
$buff .= '$query = new Query();'.PHP_EOL;
|
||||
$buff .= '$query = new Query();' . PHP_EOL;
|
||||
$buff .= sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n");
|
||||
$buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n");
|
||||
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
|
||||
$buff .= $this->preBuff;
|
||||
if($this->columns)
|
||||
$buff .= '$query->setColumns(' . $this->columns->toString() . ');'.PHP_EOL;
|
||||
if ($this->columns)
|
||||
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
|
||||
|
||||
$buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL;
|
||||
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() .');'.PHP_EOL;
|
||||
$buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL;
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
if($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
|
||||
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
|
||||
else
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
function getTables() {
|
||||
if ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
|
||||
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
|
||||
else
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
}
|
||||
|
||||
function getConditions(){
|
||||
function getConditions() {
|
||||
return $this->conditions = new ConditionsTag($this->query->conditions);
|
||||
}
|
||||
|
||||
function getGroups(){
|
||||
function getGroups() {
|
||||
return $this->groups = new GroupsTag($this->query->groups->group);
|
||||
}
|
||||
|
||||
function getNavigation(){
|
||||
function getNavigation() {
|
||||
return $this->navigation = new NavigationTag($this->query->navigation);
|
||||
}
|
||||
|
||||
function toString(){
|
||||
function toString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTableString(){
|
||||
function getTableString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getConditionString(){
|
||||
function getConditionString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
function getExpressionString() {
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
|
||||
function getArguments(){
|
||||
function getArguments() {
|
||||
$arguments = array();
|
||||
if($this->columns)
|
||||
if ($this->columns)
|
||||
$arguments = array_merge($arguments, $this->columns->getArguments());
|
||||
$arguments = array_merge($arguments, $this->tables->getArguments());
|
||||
$arguments = array_merge($arguments, $this->tables->getArguments());
|
||||
$arguments = array_merge($arguments, $this->conditions->getArguments());
|
||||
$arguments = array_merge($arguments, $this->navigation->getArguments());
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue