mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
add phpDoc style comment
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10774 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
744cc459ac
commit
3f0dd9cb06
11 changed files with 534 additions and 229 deletions
|
|
@ -1,9 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* DBParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
**/
|
||||
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;
|
||||
|
|
@ -11,33 +36,68 @@
|
|||
$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);
|
||||
|
|
@ -49,11 +109,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
|
@ -92,12 +162,19 @@
|
|||
/*
|
||||
* 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)){
|
||||
|
|
@ -108,4 +185,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue