mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
Added Query object to hold together query parts. Updated structure of query cache file to return Query object. Added support for array query arguments - used in the IN clause. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8438 201d5d3c-b55e-5fd7-737f-ddc643e51545
70 lines
No EOL
1.8 KiB
PHP
70 lines
No EOL
1.8 KiB
PHP
<?php
|
|
|
|
class DefaultValue {
|
|
var $column_name;
|
|
var $value;
|
|
|
|
function DefaultValue($column_name, $value){
|
|
$this->column_name = $column_name;
|
|
$this->value = $value;
|
|
}
|
|
|
|
function isString(){
|
|
$str_pos = strpos($this->value, '(');
|
|
if($str_pos===false) return true;
|
|
return false;
|
|
}
|
|
|
|
function toString(){
|
|
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.'\'';
|
|
//if($str_pos===false) return $this->value;
|
|
|
|
$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\']';
|
|
break;
|
|
case 'unixtime' :
|
|
$val = 'time()';
|
|
break;
|
|
case 'curdate' :
|
|
$val = 'date("YmdHis")';
|
|
break;
|
|
case 'sequence' :
|
|
$val = '$this->getNextSequence()';
|
|
break;
|
|
case 'plus' :
|
|
$args = abs($args);
|
|
// TODO Make sure column name is escaped
|
|
$val = sprintf('"%s+%d"', $this->column_name, $args);
|
|
break;
|
|
case 'minus' :
|
|
$args = abs($args);
|
|
$val = sprintf('"%s-%d"', $this->column_name, $args);
|
|
break;
|
|
case 'multiply' :
|
|
$args = intval($args);
|
|
$val = sprintf('"%s*%d"', $this->column_name, $args);
|
|
break;
|
|
default :
|
|
$val = '\'' . $this->value . '\'';
|
|
//$val = $this->value;
|
|
}
|
|
|
|
return $val;
|
|
}
|
|
}
|
|
|
|
?>
|