mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-16 09:49:54 +09:00
merge from branch luminous (version 1.5.4.2, ~r12561)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@12611 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
2263200ce4
commit
cc47d2b247
196 changed files with 3655 additions and 2033 deletions
|
|
@ -1,193 +1,272 @@
|
|||
<?php
|
||||
/**
|
||||
* File containing the DBParser class
|
||||
*/
|
||||
/**
|
||||
* Escapes query statements: <br />
|
||||
* - column names: member.member_srl => "member"."member_srl" <br />
|
||||
* - expressions: SUM(member.member_srl) => SUM("member"."member_srl") <br />
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class DBParser
|
||||
{
|
||||
/**
|
||||
* DBParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
* Character for escape target value on the left
|
||||
*
|
||||
* For example, in CUBRID left and right escape
|
||||
* chars are the same, the double quote - " <br />
|
||||
* But for SQL Server, the escape is made with
|
||||
* [double brackets], so the left and right char differ
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
class DBParser {
|
||||
/**
|
||||
* Character for escape target value on the left
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_left;
|
||||
/**
|
||||
* Character for escape target value on the right
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_right;
|
||||
/**
|
||||
* Table prefix string
|
||||
* @var string
|
||||
*/
|
||||
var $table_prefix;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $escape_char_left
|
||||
* @param string $escape_char_right
|
||||
* @param string $table_prefix
|
||||
* @return void
|
||||
*/
|
||||
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_"){
|
||||
$this->escape_char_left = $escape_char_left;
|
||||
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
|
||||
else $this->escape_char_right = $escape_char_left;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get escape character
|
||||
* @param string $leftOrRight left or right
|
||||
* @return string
|
||||
*/
|
||||
function getEscapeChar($leftOrRight){
|
||||
if ($leftOrRight === 'left')return $this->escape_char_left;
|
||||
else return $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the value
|
||||
* @param mixed $name
|
||||
* @return string
|
||||
*/
|
||||
function escape($name){
|
||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function escapeString($name){
|
||||
return "'".$this->escapeStringValue($name)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function escapeStringValue($value){
|
||||
if($value == "*") return $value;
|
||||
if (is_string($value)) return $value = str_replace("'","''",$value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table full name
|
||||
* @param string $name table name without table prefix
|
||||
* @return string table full name with table prefix
|
||||
*/
|
||||
function parseTableName($name){
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return colmun name after escape
|
||||
* @param string $name column name before escape
|
||||
* @return string column name after escape
|
||||
*/
|
||||
function parseColumnName($name){
|
||||
return $this->escapeColumn($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape column
|
||||
* @param string $column_name
|
||||
* @return string column name with db name
|
||||
*/
|
||||
function escapeColumn($column_name){
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
return $this->escape($column_name);
|
||||
if($this->isQualifiedColumnName($column_name)){
|
||||
list($table, $column) = explode('.', $column_name);
|
||||
// $table can also be an alias, so the prefix should not be added
|
||||
return $this->escape($table).'.'.$this->escape($column);
|
||||
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
|
||||
}
|
||||
}
|
||||
var $escape_char_left;
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isUnqualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isQualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Character for escape target value on the right
|
||||
*
|
||||
* For example, in CUBRID left and right escape
|
||||
* chars are the same, the double quote - " <br />
|
||||
* But for SQL Server, the escape is made with
|
||||
* [double brackets], so the left and right char differ
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_right;
|
||||
|
||||
function parseExpression($column_name){
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v){
|
||||
$function = &$functions[$k];
|
||||
if(strlen($function)==1) continue; // skip delimiters
|
||||
$pos = strrpos("(", $function);
|
||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
$total_brackets = substr_count($function, "(");
|
||||
$brackets = 0;
|
||||
foreach($matches as $i => $j){
|
||||
$match = &$matches[$i];
|
||||
if($match == '(') {$brackets++; continue;}
|
||||
if(strpos($match,')') !== false) continue;
|
||||
if(in_array($match, array(',', '.'))) continue;
|
||||
if($brackets == $total_brackets){
|
||||
if(!is_numeric($match)) {
|
||||
$match = $this->escapeColumnExpression($match);
|
||||
}
|
||||
/**
|
||||
* Table prefix string
|
||||
*
|
||||
* Default is "xe_"
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $table_prefix;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $escape_char_left
|
||||
* @param string $escape_char_right
|
||||
* @param string $table_prefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_")
|
||||
{
|
||||
$this->escape_char_left = $escape_char_left;
|
||||
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
|
||||
else $this->escape_char_right = $escape_char_left;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get escape character
|
||||
*
|
||||
* @param string $leftOrRight left or right
|
||||
* @return string
|
||||
*/
|
||||
function getEscapeChar($leftOrRight)
|
||||
{
|
||||
if ($leftOrRight === 'left')return $this->escape_char_left;
|
||||
else return $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the value
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return string
|
||||
*/
|
||||
function escape($name)
|
||||
{
|
||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the string value
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function escapeString($name)
|
||||
{
|
||||
return "'".$this->escapeStringValue($name)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the string value
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function escapeStringValue($value)
|
||||
{
|
||||
if($value == "*") return $value;
|
||||
if (is_string($value)) return $value = str_replace("'","''",$value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table full name
|
||||
*
|
||||
* @param string $name table name without table prefix
|
||||
*
|
||||
* @return string table full name with table prefix
|
||||
*/
|
||||
function parseTableName($name)
|
||||
{
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column name after escape
|
||||
*
|
||||
* @param string $name column name before escape
|
||||
*
|
||||
* @return string column name after escape
|
||||
*/
|
||||
function parseColumnName($name)
|
||||
{
|
||||
return $this->escapeColumn($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape column name
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return string column name with db name
|
||||
*/
|
||||
function escapeColumn($column_name)
|
||||
{
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
return $this->escape($column_name);
|
||||
if($this->isQualifiedColumnName($column_name)){
|
||||
list($table, $column) = explode('.', $column_name);
|
||||
// $table can also be an alias, so the prefix should not be added
|
||||
return $this->escape($table).'.'.$this->escape($column);
|
||||
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a given column name is unqualified
|
||||
*
|
||||
* Ex: "member_srl" -> unqualified <br />
|
||||
* "member"."member_srl" -> qualified
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isUnqualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name,'.')===FALSE && strpos($column_name,'(')===FALSE) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a given column name is qualified
|
||||
*
|
||||
* Ex: "member_srl" -> unqualified <br />
|
||||
* "member"."member_srl" -> qualified
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isQualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name,'.')!==FALSE && strpos($column_name,'(')===FALSE) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a query expression
|
||||
*
|
||||
* An expression can be: <br />
|
||||
* <ul>
|
||||
* <li> a column name: "member_srl" or "xe_member"."member_srl"
|
||||
* <li> an expression:
|
||||
* <ul>
|
||||
* <li> LEFT(UPPER("content")) <br />
|
||||
* <li> readed_count + voted_count <br />
|
||||
* <li> CAST(regdate as DATE) </li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param $column_name
|
||||
* @return string
|
||||
*/
|
||||
function parseExpression($column_name)
|
||||
{
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v){
|
||||
$function = &$functions[$k];
|
||||
if(strlen($function)==1) continue; // skip delimiters
|
||||
$pos = strrpos("(", $function);
|
||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
$total_brackets = substr_count($function, "(");
|
||||
$brackets = 0;
|
||||
foreach($matches as $i => $j){
|
||||
$match = &$matches[$i];
|
||||
if($match == '(') {$brackets++; continue;}
|
||||
if(strpos($match,')') !== FALSE) continue;
|
||||
if(in_array($match, array(',', '.'))) continue;
|
||||
if($brackets == $total_brackets){
|
||||
if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS'))) {
|
||||
$match = $this->escapeColumnExpression($match);
|
||||
}
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks argument is asterisk
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStar($column_name){
|
||||
if(substr($column_name,-1) == '*') return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks to see if expression is an aggregate star function
|
||||
* like count(*)
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStarFunction($column_name){
|
||||
if(strpos($column_name, "(*)")!==false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return column name after escape
|
||||
* @param string $column_name
|
||||
* @return string
|
||||
*/
|
||||
function escapeColumnExpression($column_name){
|
||||
if($this->isStar($column_name)) return $column_name;
|
||||
if($this->isStarFunction($column_name)){
|
||||
return $column_name;
|
||||
}
|
||||
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a given argument is an asterisk
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStar($column_name)
|
||||
{
|
||||
if(substr($column_name,-1) == '*') return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if expression is an aggregate star function
|
||||
* like count(*)
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStarFunction($column_name)
|
||||
{
|
||||
if(strpos($column_name, "(*)")!==FALSE) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column name after escape
|
||||
* @param string $column_name
|
||||
* @return string
|
||||
*/
|
||||
function escapeColumnExpression($column_name)
|
||||
{
|
||||
if($this->isStar($column_name)) return $column_name;
|
||||
if($this->isStarFunction($column_name))
|
||||
{
|
||||
return $column_name;
|
||||
}
|
||||
if(strpos(strtolower($column_name), 'distinct') !== FALSE) return $column_name;
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,92 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* File containing the QueryParser class
|
||||
*/
|
||||
/**
|
||||
* Parses an XML Object and returns a string used for generating the PHP cache file <br />
|
||||
* The XML Object structure must be the one defined in the XmlParser class
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryParser {
|
||||
|
||||
/**
|
||||
* QueryParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
* Property containing the associated QueryTag object
|
||||
*
|
||||
* @var QueryTag object
|
||||
*/
|
||||
class QueryParser {
|
||||
/**
|
||||
* QueryTag object
|
||||
* @var QueryTag object
|
||||
*/
|
||||
var $queryTag;
|
||||
var $queryTag;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $query
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function QueryParser($query = NULL, $isSubQuery = false) {
|
||||
if ($query)
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $query XML object obtained after reading the XML Query file
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function QueryParser($query = NULL, $isSubQuery = FALSE)
|
||||
{
|
||||
if ($query)
|
||||
{
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table information
|
||||
* @param object $query_id
|
||||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name) {
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
if (count($id_args) == 2) {
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
} elseif (count($id_args) == 3) {
|
||||
$target = $id_args[0];
|
||||
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
|
||||
if (!isset($targetList[$target]))
|
||||
return;
|
||||
$module = $id_args[1];
|
||||
$id = $id_args[2];
|
||||
}
|
||||
/**
|
||||
* Returns table information
|
||||
*
|
||||
* Used for finding column type info (string/numeric) <br />
|
||||
* Obtains the table info from XE's XML schema files
|
||||
*
|
||||
* @param object $query_id
|
||||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name) {
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
// get column properties from the table
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||
if (!file_exists($table_file)) {
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for ($i = 0; $i < $searched_count; $i++) {
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if (file_exists($table_file))
|
||||
break;
|
||||
}
|
||||
}
|
||||
$id_args = explode('.', $query_id);
|
||||
if (count($id_args) == 2) {
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
} elseif (count($id_args) == 3) {
|
||||
$target = $id_args[0];
|
||||
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
|
||||
if (!isset($targetList[$target]))
|
||||
return;
|
||||
$module = $id_args[1];
|
||||
$id = $id_args[2];
|
||||
}
|
||||
|
||||
if (file_exists($table_file)) {
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if ($table_obj->table) {
|
||||
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
// get column properties from the table
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||
if (!file_exists($table_file)) {
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for ($i = 0; $i < $searched_count; $i++) {
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if (file_exists($table_file))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($table_obj->table->column as $k => $v) {
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file_exists($table_file)) {
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if ($table_obj->table) {
|
||||
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
|
||||
return $column_type;
|
||||
}
|
||||
foreach ($table_obj->table->column as $k => $v) {
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change code string from queryTag object
|
||||
* @return string
|
||||
*/
|
||||
function toString() {
|
||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
return $column_type;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Returns the contents for the query cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString() {
|
||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ class Argument {
|
|||
}
|
||||
|
||||
function getUnescapedValue() {
|
||||
if($this->value === 'null') return null;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
|
@ -163,19 +164,47 @@ class Argument {
|
|||
* @return string
|
||||
*/
|
||||
function _escapeStringValue($value) {
|
||||
// Remove non-utf8 chars.
|
||||
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
||||
|
||||
$value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value);
|
||||
$db = &DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
return '\'' . $value . '\'';
|
||||
}
|
||||
|
||||
function utf8Replacer($captures) {
|
||||
if (!empty($captures[1]))
|
||||
{
|
||||
// Valid byte sequence. Return unmodified.
|
||||
return $captures[1];
|
||||
}
|
||||
elseif(!empty($captures[2]))
|
||||
{
|
||||
// Remove user defined area
|
||||
if("\xF3\xB0\x80\x80" <= $captures[2])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return $captures[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function isValid() {
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function isColumnName(){
|
||||
$type = $this->getType();
|
||||
$value = $this->getUnescapedValue();
|
||||
if($type == 'column_name') return true;
|
||||
if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true;
|
||||
if($type == 'number' && is_null($value)) return false;
|
||||
if($type == 'number' && !is_numeric($value) && $this->uses_default_value) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file <br />
|
||||
* Since the <column> tag supports different attributes depending on
|
||||
* the type of query (select, update, insert, delete) this is only
|
||||
* the base class for the classes that will model each type <column> tag.
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class ColumnTag
|
||||
{
|
||||
/**
|
||||
* ColumnTag class
|
||||
* Models the <column> tag inside an XML Query file
|
||||
* Since the <column> tag supports different attributes depending on
|
||||
* the type of query (select, update, insert, delete) this is only
|
||||
* the base class for the classes that will model each type <column> tag.
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
class ColumnTag {
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
function ColumnTag($name){
|
||||
$this->name = $name;
|
||||
}
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
function ColumnTag($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnTag extends ColumnTag
|
||||
{
|
||||
/**
|
||||
* InsertColumnTag
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert'
|
||||
* Argument
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
class InsertColumnTag extends ColumnTag {
|
||||
/**
|
||||
* argument
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function InsertColumnTag($column) {
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
$this->argument = new QueryArgument($column);
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
||||
function getArgument(){
|
||||
return $this->argument;
|
||||
}
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function InsertColumnTag($column)
|
||||
{
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
$this->argument = new QueryArgument($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
* used for instantiating an InsertExpression when a
|
||||
* query is executed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the QueryArgument object associated with this INSERT statement
|
||||
*
|
||||
* @return QueryArgument
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,31 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert-select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnTagWithoutArgument extends ColumnTag
|
||||
{
|
||||
/**
|
||||
* InsertColumnTagWithoutArgument
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert-select'
|
||||
* Constructor
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
class InsertColumnTagWithoutArgument extends ColumnTag {
|
||||
/**
|
||||
* constructor
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function InsertColumnTagWithoutArgument($column) {
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
return sprintf('new Expression(\'%s\')', $this->name);
|
||||
}
|
||||
|
||||
function getArgument(){
|
||||
return null;
|
||||
}
|
||||
|
||||
function InsertColumnTagWithoutArgument($column)
|
||||
{
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
return sprintf('new Expression(\'%s\')', $this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the QueryArgument object associated with this INSERT statement
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,65 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'insert'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnsTag
|
||||
{
|
||||
/**
|
||||
* InsertColumnsTag class
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert'
|
||||
* Column list
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var array value is InsertColumnTag object
|
||||
*/
|
||||
class InsertColumnsTag{
|
||||
/**
|
||||
* Column list
|
||||
* @var array value is InsertColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array|string $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function InsertColumnsTag($xml_columns) {
|
||||
$this->columns = array();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|string $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function InsertColumnsTag($xml_columns)
|
||||
{
|
||||
$this->columns = array();
|
||||
|
||||
if(!$xml_columns)
|
||||
return;
|
||||
if(!$xml_columns)
|
||||
return;
|
||||
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
|
||||
foreach($xml_columns as $column){
|
||||
if($column->name === 'query') $this->columns[] = new QueryTag($column, true);
|
||||
else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column);
|
||||
else $this->columns[] = new InsertColumnTag($column);
|
||||
}
|
||||
foreach($xml_columns as $column){
|
||||
if($column->name === 'query') $this->columns[] = new QueryTag($column, true);
|
||||
else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column);
|
||||
else $this->columns[] = new InsertColumnTag($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* InsertColumnTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString(){
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
* @return array
|
||||
*/
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* InsertColumnTag object to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,53 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class SelectColumnTag extends ColumnTag
|
||||
{
|
||||
/**
|
||||
* SelectColumnTag
|
||||
* Models the <column> tag inside an XML Query file whose action is 'select'
|
||||
* Column alias
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var string
|
||||
*/
|
||||
class SelectColumnTag extends ColumnTag{
|
||||
/**
|
||||
* alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
/**
|
||||
* click count status
|
||||
* @var bool
|
||||
*/
|
||||
var $click_count;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string|object $column
|
||||
* @return void
|
||||
*/
|
||||
function SelectColumnTag($column){
|
||||
if ($column == "*" || $column->attrs->name == '*')
|
||||
{
|
||||
parent::ColumnTag(NULL);
|
||||
$this->name = "*";
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = new DB(); $dbParser = &$dbParser->getParser();
|
||||
$this->name = $dbParser->parseExpression($this->name);
|
||||
|
||||
$this->alias = $column->attrs->alias;
|
||||
$this->click_count = $column->attrs->click_count;
|
||||
}
|
||||
var $alias;
|
||||
|
||||
/**
|
||||
* Click count status
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $click_count;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string|object $column
|
||||
* @return void
|
||||
*/
|
||||
function SelectColumnTag($column)
|
||||
{
|
||||
if ($column == "*" || $column->attrs->name == '*')
|
||||
{
|
||||
parent::ColumnTag(NULL);
|
||||
$this->name = "*";
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
if($this->name == '*') return "new StarExpression()";
|
||||
if($this->click_count)
|
||||
return sprintf('new ClickCountExpression(%s, %s, $args->%s)', $this->name, $this->alias,$this->click_count);
|
||||
if(strpos($this->name, '$') === 0)
|
||||
return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
|
||||
$dbParser = DB::getParser();
|
||||
return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \''.$dbParser->escape($this->alias) .'\'': '');
|
||||
else
|
||||
{
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = new DB(); $dbParser = &$dbParser->getParser();
|
||||
$this->name = $dbParser->parseExpression($this->name);
|
||||
|
||||
$this->alias = $column->attrs->alias;
|
||||
$this->click_count = $column->attrs->click_count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* A select column tag in an XML query can be used for:
|
||||
* <ul>
|
||||
* <li> a star expression: SELECT *
|
||||
* <li> a click count expression: SELECT + UPDATE
|
||||
* <li> any other select expression (column name, function call etc). </li>
|
||||
* </ul>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
if($this->name == '*') return "new StarExpression()";
|
||||
if($this->click_count)
|
||||
return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''",$this->click_count);
|
||||
if(strpos($this->name, '$') === 0)
|
||||
return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
|
||||
$dbParser = DB::getParser();
|
||||
return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \''.$dbParser->escape($this->alias) .'\'': '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,83 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class SelectColumnsTag
|
||||
{
|
||||
/**
|
||||
* SelectColumnTag class
|
||||
* Column list
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var array value is SelectColumnTag object
|
||||
*/
|
||||
class SelectColumnsTag {
|
||||
/**
|
||||
* Column list
|
||||
* @var array value is SelectColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param Xml_Node_ $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function SelectColumnsTag($xml_columns_tag){
|
||||
if (!$xml_columns_tag)
|
||||
$xml_columns_tag = new Xml_Node_();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $xml_columns_tag
|
||||
* @internal param \Xml_Node_ $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function SelectColumnsTag($xml_columns_tag)
|
||||
{
|
||||
if (!$xml_columns_tag)
|
||||
$xml_columns_tag = new Xml_Node_();
|
||||
|
||||
$xml_columns = $xml_columns_tag->column;
|
||||
$xml_queries = $xml_columns_tag->query;
|
||||
$xml_columns = $xml_columns_tag->column;
|
||||
$xml_queries = $xml_columns_tag->query;
|
||||
|
||||
$this->columns = array();
|
||||
$this->columns = array();
|
||||
|
||||
if(!$xml_columns) {
|
||||
$this->columns[] = new SelectColumnTag("*");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
|
||||
foreach($xml_columns as $column){
|
||||
$this->columns[] = new SelectColumnTag($column);
|
||||
}
|
||||
|
||||
|
||||
if(!$xml_queries) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_queries)) $xml_queries = array($xml_queries);
|
||||
|
||||
foreach($xml_queries as $column){
|
||||
$this->columns[] = new QueryTag($column, true);
|
||||
}
|
||||
if(!$xml_columns) {
|
||||
$this->columns[] = new SelectColumnTag("*");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* SelectColumnTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString(){
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
if(is_a($column, 'QueryTag'))
|
||||
$output_columns .= $column->toString() . PHP_EOL . ',';
|
||||
else
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
|
||||
foreach($xml_columns as $column){
|
||||
$this->columns[] = new SelectColumnTag($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
* @return array
|
||||
*/
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
if(is_a($column, 'QueryTag'))
|
||||
$arguments = array_merge($arguments, $column->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
|
||||
if(!$xml_queries) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_queries)) $xml_queries = array($xml_queries);
|
||||
|
||||
foreach($xml_queries as $column){
|
||||
$this->columns[] = new QueryTag($column, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
if(is_a($column, 'QueryTag'))
|
||||
$output_columns .= $column->toString() . PHP_EOL . ',';
|
||||
else
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
if(is_a($column, 'QueryTag'))
|
||||
$arguments = array_merge($arguments, $column->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,73 +1,103 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class UpdateColumnTag extends ColumnTag
|
||||
{
|
||||
/**
|
||||
* UpdateColumnTag
|
||||
* Models the <column> tag inside an XML Query file whose action is 'update'
|
||||
* Argument
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
class UpdateColumnTag extends ColumnTag {
|
||||
/**
|
||||
* argument
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
/**
|
||||
* default value
|
||||
* @var string
|
||||
*/
|
||||
var $default_value;
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function UpdateColumnTag($column) {
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
if($column->attrs->var)
|
||||
$this->argument = new QueryArgument($column);
|
||||
else {
|
||||
if(strpos($column->attrs->default, '.') !== false)
|
||||
$this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'";
|
||||
else {
|
||||
$default_value = new DefaultValue($this->name, $column->attrs->default);
|
||||
if($default_value->isOperation())
|
||||
$this->argument = new QueryArgument($column, true);
|
||||
//else $this->default_value = $dbParser->parseColumnName($column->attrs->default);
|
||||
else {
|
||||
$this->default_value = $default_value->toString();
|
||||
if($default_value->isStringFromFunction()){
|
||||
$this->default_value = '"\'".' . $this->default_value . '."\'"';
|
||||
}
|
||||
if($default_value->isString()){
|
||||
$this->default_value = '"' . $this->default_value . '"';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Default value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $default_value;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function UpdateColumnTag($column)
|
||||
{
|
||||
parent::ColumnTag($column->attrs->name);
|
||||
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
|
||||
if($column->attrs->var)
|
||||
$this->argument = new QueryArgument($column);
|
||||
else {
|
||||
if(strpos($column->attrs->default, '.') !== FALSE)
|
||||
{
|
||||
$this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value = new DefaultValue($this->name, $column->attrs->default);
|
||||
if($default_value->isOperation())
|
||||
{
|
||||
$this->argument = new QueryArgument($column, TRUE);
|
||||
}
|
||||
//else $this->default_value = $dbParser->parseColumnName($column->attrs->default);
|
||||
else
|
||||
{
|
||||
$this->default_value = $default_value->toString();
|
||||
if($default_value->isStringFromFunction())
|
||||
{
|
||||
$this->default_value = '"\'".' . $this->default_value . '."\'"';
|
||||
}
|
||||
if($default_value->isString())
|
||||
{
|
||||
$this->default_value = '"' . $this->default_value . '"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getExpressionString(){
|
||||
if($this->argument)
|
||||
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
else {
|
||||
return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)'
|
||||
, $this->name
|
||||
, $this->default_value);
|
||||
}
|
||||
}
|
||||
|
||||
function getArgument(){
|
||||
return $this->argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
if($this->argument)
|
||||
{
|
||||
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)'
|
||||
, $this->name
|
||||
, $this->default_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Argument associated with this update statement
|
||||
*
|
||||
* @return QueryArgument
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,61 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class UpdateColumnsTag
|
||||
{
|
||||
/**
|
||||
* UpdateColumnsTag
|
||||
* Models the <column> tag inside an XML Query file whose action is 'update'
|
||||
* Column list
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/column
|
||||
* @version 0.1
|
||||
* @var array value is UpdateColumnTag object
|
||||
*/
|
||||
class UpdateColumnsTag{
|
||||
/**
|
||||
* Column list
|
||||
* @var array value is UpdateColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array|string $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function UpdateColumnsTag($xml_columns) {
|
||||
$this->columns = array();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|object $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function UpdateColumnsTag($xml_columns)
|
||||
{
|
||||
$this->columns = array();
|
||||
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
|
||||
foreach($xml_columns as $column){
|
||||
if($column->name === 'query') $this->columns[] = new QueryTag($column, true);
|
||||
else $this->columns[] = new UpdateColumnTag($column);
|
||||
}
|
||||
foreach($xml_columns as $column){
|
||||
if($column->name === 'query') $this->columns[] = new QueryTag($column, true);
|
||||
else $this->columns[] = new UpdateColumnTag($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateColumnTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString(){
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
* @return array
|
||||
*/
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue