mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-28 14:52:24 +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
|
|
@ -1,52 +1,62 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
class Argument {
|
||||
var $value;
|
||||
var $name;
|
||||
var $type;
|
||||
|
||||
|
||||
var $isValid;
|
||||
var $errorMessage;
|
||||
|
||||
|
||||
var $column_operation;
|
||||
|
||||
function Argument($name, $value){
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->name = $name;
|
||||
$this->isValid = true;
|
||||
}
|
||||
|
||||
|
||||
function getType(){
|
||||
if(isset($this->type)) return $this->type;
|
||||
if(is_string($this->value)) return 'column_name';
|
||||
return 'number';
|
||||
}
|
||||
|
||||
|
||||
function setColumnType($value){
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
|
||||
function setColumnOperation($operation){
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
function getValue(){
|
||||
$value = $this->escapeValue($this->value);
|
||||
return $this->toString($value);
|
||||
}
|
||||
|
||||
function getColumnOperation(){
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getUnescapedValue(){
|
||||
return $this->toString($this->value);
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
function toString($value){
|
||||
if(is_array($value)) return '('.implode(',', $value).')';
|
||||
return $value;
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
function escapeValue($value){
|
||||
if($this->getType() == 'column_name'){
|
||||
$dbParser = XmlQueryParser::getDBParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if(!isset($value)) return null;
|
||||
if(in_array($this->type, array('date', 'varchar', 'char','text', 'bigtext'))){
|
||||
if(!is_array($value))
|
||||
|
|
@ -57,32 +67,32 @@
|
|||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||
//$value[$i] = '\''.$value[$i].'\'';
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function _escapeStringValue($value){
|
||||
$db = &DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
$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 == '')
|
||||
if(!isset($this->value) || $this->value == '')
|
||||
$this->value = $default_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function checkFilter($filter_type){
|
||||
if(isset($this->value) && $this->value != ''){
|
||||
$val = $this->value;
|
||||
|
|
@ -90,7 +100,7 @@
|
|||
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)) {
|
||||
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));
|
||||
}
|
||||
|
|
@ -111,7 +121,7 @@
|
|||
case 'number' :
|
||||
case 'numbers' :
|
||||
if(is_array($val)) $val = join(',', $val);
|
||||
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $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));
|
||||
}
|
||||
|
|
@ -128,10 +138,10 @@
|
|||
$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)){
|
||||
$this->isValid = false;
|
||||
|
|
@ -139,15 +149,15 @@
|
|||
$this->errorMessage = new Object(-1, $lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function checkMinLength($length){
|
||||
if($this->value && (strlen($this->value) > $length)){
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, $lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function checkNotNull(){
|
||||
if(!isset($this->value)){
|
||||
$this->isValid = false;
|
||||
|
|
|
|||
|
|
@ -1,35 +1,46 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
class DefaultValue {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
function isString(){
|
||||
$str_pos = strpos($this->value, '(');
|
||||
if($str_pos===false) return true;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function isSequence(){
|
||||
return $this->is_sequence;
|
||||
}
|
||||
|
||||
|
||||
function isOperation(){
|
||||
return $this->is_operation;
|
||||
}
|
||||
|
||||
function getOperation(){
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
function _setValue(){
|
||||
if(!isset($this->value)) return;
|
||||
|
||||
|
||||
// If value contains comma separated values and does not contain paranthesis
|
||||
// -> default value is an array
|
||||
if(strpos($this->value, ',') !== false && strpos($this->value, '(') === false) {
|
||||
return sprintf('array(%s)', $this->value);
|
||||
}
|
||||
|
||||
|
||||
$str_pos = strpos($this->value, '(');
|
||||
// // TODO Replace this with parseExpression
|
||||
if($str_pos===false) return '\''.$this->value.'\'';
|
||||
|
|
@ -37,7 +48,7 @@
|
|||
|
||||
$func_name = substr($this->value, 0, $str_pos);
|
||||
$args = substr($this->value, $str_pos+1, strlen($value)-1);
|
||||
|
||||
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '$_SERVER[\'REMOTE_ADDR\']';
|
||||
|
|
@ -54,25 +65,30 @@
|
|||
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 . '\'';
|
||||
//$val = $this->value;
|
||||
}
|
||||
|
||||
return $val;
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
function toString(){
|
||||
return $this->value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
|
||||
class QueryArgumentValidator {
|
||||
|
|
@ -10,54 +10,59 @@
|
|||
var $max_length;
|
||||
|
||||
var $validator_string;
|
||||
|
||||
|
||||
var $argument;
|
||||
|
||||
|
||||
function QueryArgumentValidator($tag, $argument){
|
||||
$this->argument = $argument;
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
|
||||
|
||||
$this->default_value = $tag->attrs->default;
|
||||
$this->notnull = $tag->attrs->notnull;
|
||||
$this->filter = $tag->attrs->filter;
|
||||
$this->min_length = $tag->attrs->min_length;
|
||||
$this->max_length = $tag->attrs->max_length;
|
||||
$this->max_length = $tag->attrs->max_length;
|
||||
}
|
||||
|
||||
|
||||
function toString(){
|
||||
$validator = '';
|
||||
if(isset($this->default_value)){
|
||||
$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()
|
||||
);
|
||||
}
|
||||
}
|
||||
if($this->notnull){
|
||||
$validator .= sprintf("$%s_argument->checkNotNull();\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
);
|
||||
}
|
||||
if($this->filter){
|
||||
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
);
|
||||
}
|
||||
if($this->min_length){
|
||||
$validator .= sprintf("$%s_argument->checkMinLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
);
|
||||
}
|
||||
if($this->max_length){
|
||||
$validator .= sprintf("$%s_argument->checkMaxLength(%s);\n"
|
||||
, $this->argument_name
|
||||
, $this->max_length
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue