mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Update new xml query classes with xe 1.5
with improved query argument support and update and delete queries git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8378 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
5f9a5249ac
commit
7dbe0626b6
39 changed files with 1619 additions and 540 deletions
98
classes/xml/xmlquery/DBParser.class.php
Normal file
98
classes/xml/xmlquery/DBParser.class.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
class DBParser {
|
||||
var $escape_char;
|
||||
var $table_prefix;
|
||||
|
||||
function DBParser($escape_char, $table_prefix = "xe_"){
|
||||
$this->escape_char = $escape_char;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
function getEscapeChar(){
|
||||
return $this->escape_char;
|
||||
}
|
||||
|
||||
function escape($name){
|
||||
return $this->escape_char . $name . $this->escape_char;
|
||||
}
|
||||
|
||||
function escapeString($name){
|
||||
return "'".$name."'";
|
||||
}
|
||||
|
||||
function parseTableName($name){
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
function parseColumnName($name){
|
||||
return $this->escapeColumn($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);
|
||||
}
|
||||
}
|
||||
|
||||
function isUnqualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isQualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseExpression($column_name){
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as &$function){
|
||||
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 &$match){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
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(*)
|
||||
*/
|
||||
function isStarFunction($column_name){
|
||||
if(strpos($column_name, "(*)")!==false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function escapeColumnExpression($column_name){
|
||||
if($this->isStar($column_name)) return $column_name;
|
||||
if($this->isStarFunction($column_name)){
|
||||
return $column_name;
|
||||
}
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue