mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-28 23:03:25 +09:00
Prepared statements - if argument is not given as array (eg. for IN clauses) even though it should be, convert it to an array.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8633 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
b3c75ac4db
commit
39c2c004c2
6 changed files with 118 additions and 185 deletions
|
|
@ -97,48 +97,48 @@
|
|||
if(isset($this->value) && $this->value != ''){
|
||||
$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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,28 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
class ConditionArgument extends Argument {
|
||||
var $operation;
|
||||
|
||||
|
||||
|
||||
|
||||
function ConditionArgument($name, $value, $operation){
|
||||
if(isset($value) && in_array($operation, array('in', 'not in', 'between')) && !is_array($value)){
|
||||
$value = explode(',', $value);
|
||||
}
|
||||
parent::Argument($name, $value);
|
||||
$this->operation = $operation;
|
||||
|
||||
$this->operation = $operation;
|
||||
|
||||
if($this->type !== 'date'){
|
||||
$dbParser = XmlQueryParser::getDBParser();
|
||||
$this->value = $dbParser->escapeStringValue($this->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createConditionValue(){
|
||||
if(!isset($this->value)) return;
|
||||
|
||||
|
||||
$name = $this->column_name;
|
||||
$operation = $this->operation;
|
||||
$value = $this->value;
|
||||
$value = $this->value;
|
||||
|
||||
switch($operation) {
|
||||
case 'like_prefix' :
|
||||
|
|
@ -27,7 +30,7 @@
|
|||
break;
|
||||
case 'like_tail' :
|
||||
$this->value = '%'.$value;
|
||||
break;
|
||||
break;
|
||||
case 'like' :
|
||||
$this->value = '%'.$value.'%';
|
||||
break;
|
||||
|
|
@ -35,103 +38,24 @@
|
|||
if(!is_array($value)) $this->value = array($value);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
//if(!in_array($operation,array('in','notin','between')) && is_array($value)){
|
||||
// $value = join(',', $value);
|
||||
//}
|
||||
// Daca operatia nu este in, notin, between si coloana e de tip numeric
|
||||
// daca valoarea e array -> concatenare
|
||||
// daca valoarea nu e array si nici nu contine paranteze (nu e functie) -> return (int)
|
||||
// altfel return valoare
|
||||
|
||||
// if(!in_array($operation,array('in','notin','between')) && $type == 'number') {
|
||||
// if(is_array($value)){
|
||||
// $value = join(',',$value);
|
||||
// }
|
||||
// if(strpos($value, ',') === false && strpos($value, '(') === false) return (int)$value;
|
||||
// return $value;
|
||||
// }
|
||||
//
|
||||
// if(!is_array($value) && strpos($name, '.') !== false && strpos($value, '.') !== false) {
|
||||
// list($table_name, $column_name) = explode('.', $value);
|
||||
// if($column_type[$column_name]) return $value;
|
||||
// }
|
||||
|
||||
switch($operation) {
|
||||
case 'like_prefix' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = $value.'%';
|
||||
break;
|
||||
case 'like_tail' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = '%'.$value;
|
||||
break;
|
||||
case 'like' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = '%'.$value.'%';
|
||||
break;
|
||||
// case 'notin' :
|
||||
// if(is_array($value))
|
||||
// {
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type=='number') return join(',',$value);
|
||||
// else return "'". join("','",$value)."'";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return $value;
|
||||
// }
|
||||
// break;
|
||||
// case 'in' :
|
||||
// if(is_array($value))
|
||||
// {
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type=='number') return join(',',$value);
|
||||
// else return "'". join("','",$value)."'";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return $value;
|
||||
// }
|
||||
// break;
|
||||
// case 'between' :
|
||||
// if(!is_array($value)) $value = array($value);
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type!='number')
|
||||
// {
|
||||
// foreach($value as $k=>$v)
|
||||
// {
|
||||
// $value[$k] = "'".$v."'";
|
||||
// }
|
||||
// }
|
||||
|
||||
//return $value;
|
||||
break;
|
||||
default:
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
}
|
||||
$this->value = $value;
|
||||
//return "'".$this->addQuotes($value)."'";
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getType(){
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
||||
function setColumnType($column_type){
|
||||
if(!isset($this->value)) return;
|
||||
if($column_type === '') return;
|
||||
|
||||
|
||||
$this->type = $column_type;
|
||||
|
||||
|
||||
//if($column_type === '') $column_type = 'varchar';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue