Project

General

Profile

Bug #21368 » 12351_v2.diff

Administrator Admin, 2009-10-27 10:56

View differences:

t3lib/class.t3lib_sqlparser.php (working copy)
* @return array Result array with all the parts in - or error message string
* @see compileSQL(), debug_testSQL()
*/
function parseSQL($parseString) {
public function parseSQL($parseString) {
// Prepare variables:
$parseString = $this->trimSQL($parseString);
$this->parse_error = '';
......
* @return mixed Returns array with components of SELECT query on success, otherwise an error message string.
* @see compileSELECT()
*/
function parseSELECT($parseString) {
protected function parseSELECT($parseString) {
// Removing SELECT:
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of UPDATE query on success, otherwise an error message string.
* @see compileUPDATE()
*/
function parseUPDATE($parseString) {
protected function parseUPDATE($parseString) {
// Removing UPDATE
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of INSERT query on success, otherwise an error message string.
* @see compileINSERT()
*/
function parseINSERT($parseString) {
protected function parseINSERT($parseString) {
// Removing INSERT
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of DELETE query on success, otherwise an error message string.
* @see compileDELETE()
*/
function parseDELETE($parseString) {
protected function parseDELETE($parseString) {
// Removing DELETE
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of EXPLAIN query on success, otherwise an error message string.
* @see parseSELECT()
*/
function parseEXPLAIN($parseString) {
protected function parseEXPLAIN($parseString) {
// Removing EXPLAIN
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of CREATE TABLE query on success, otherwise an error message string.
* @see compileCREATETABLE()
*/
function parseCREATETABLE($parseString) {
protected function parseCREATETABLE($parseString) {
// Removing CREATE TABLE
$parseString = $this->trimSQL($parseString);
......
* @return mixed Returns array with components of ALTER TABLE query on success, otherwise an error message string.
* @see compileALTERTABLE()
*/
function parseALTERTABLE($parseString) {
protected function parseALTERTABLE($parseString) {
// Removing ALTER TABLE
$parseString = $this->trimSQL($parseString);
......
* @param string SQL string starting with DROP TABLE
* @return mixed Returns array with components of DROP TABLE query on success, otherwise an error message string.
*/
function parseDROPTABLE($parseString) {
protected function parseDROPTABLE($parseString) {
// Removing DROP TABLE
$parseString = $this->trimSQL($parseString);
......
* @param string SQL string starting with CREATE DATABASE
* @return mixed Returns array with components of CREATE DATABASE query on success, otherwise an error message string.
*/
function parseCREATEDATABASE($parseString) {
protected function parseCREATEDATABASE($parseString) {
// Removing CREATE DATABASE
$parseString = $this->trimSQL($parseString);
......
* @return array If successful parsing, returns an array, otherwise an error string.
* @see compileFieldList()
*/
function parseFieldList(&$parseString, $stopRegex='') {
public function parseFieldList(&$parseString, $stopRegex = '') {
$stack = array(); // Contains the parsed content
......
* @return array If successful parsing, returns an array, otherwise an error string.
* @see compileFromTables()
*/
function parseFromTables(&$parseString, $stopRegex='') {
public function parseFromTables(&$parseString, $stopRegex = '') {
// Prepare variables:
$parseString = $this->trimSQL($parseString);
......
* @param string Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
* @return mixed If successful parsing, returns an array, otherwise an error string.
*/
function parseWhereClause(&$parseString, $stopRegex='') {
public function parseWhereClause(&$parseString, $stopRegex = '') {
// Prepare variables:
$parseString = $this->trimSQL($parseString);
......
* @param string Regular expressing to STOP parsing, eg. '^(GROUP BY|ORDER BY|LIMIT)([[:space:]]*)'
* @return mixed If successful parsing, returns an array, otherwise an error string.
*/
function parseFieldDef(&$parseString, $stopRegex='') {
public function parseFieldDef(&$parseString, $stopRegex = '') {
// Prepare variables:
$parseString = $this->trimSQL($parseString);
$this->lastStopKeyWord = '';
......
* @param boolean If set the full match of the regex is stripped of the beginning of the string!
* @return string The value of the first parenthesis level of the REGEX.
*/
function nextPart(&$parseString,$regex,$trimAll=FALSE) {
protected function nextPart(&$parseString, $regex, $trimAll = FALSE) {
$reg = array();
if (preg_match('/'.$regex.'/i',$parseString.' ', $reg)) { // Adding space char because [[:space:]]+ is often a requirement in regex's
$parseString = ltrim(substr($parseString,strlen($reg[$trimAll?0:1])));
......
* @param string The comparator used before. If "NOT IN" or "IN" then the value is expected to be a list of values. Otherwise just an integer (un-quoted) or string (quoted)
* @return mixed The value (string/integer). Otherwise an array with error message in first key (0)
*/
function getValue(&$parseString,$comparator='') {
protected function getValue(&$parseString, $comparator = '') {
$value = '';
if (t3lib_div::inList('NOTIN,IN,_LIST',strtoupper(str_replace(array(' ',"\n","\r","\t"),'',$comparator)))) { // List of values:
......
* @param string The quote used; input either " or '
* @return string The value, passed through stripslashes() !
*/
function getValueInQuotes(&$parseString,$quote) {
protected function getValueInQuotes(&$parseString, $quote) {
$parts = explode($quote,substr($parseString,1));
$buffer = '';
......
* @param string Input string
* @return string Output string
*/
function parseStripslashes($str) {
protected function parseStripslashes($str) {
$search = array('\\\\', '\\\'', '\\"', '\0', '\n', '\r', '\Z');
$replace = array('\\', '\'', '"', "\x00", "\x0a", "\x0d", "\x1a");
......
* @param string Input string
* @return string Output string
*/
function compileAddslashes($str) {
protected function compileAddslashes($str) {
return $str;
$search = array('\\', '\'', '"', "\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\\\\', '\\\'', '\\"', '\0', '\n', '\r', '\Z');
......
* @param string Remaining query to parse.
* @return string Error message.
*/
function parseError($msg,$restQuery) {
protected function parseError($msg, $restQuery) {
$this->parse_error = 'SQL engine parse ERROR: '.$msg.': near "'.substr($restQuery,0,50).'"';
return $this->parse_error;
}
......
* @param string Input string
* @return string Output string
*/
function trimSQL($str) {
protected function trimSQL($str) {
return trim(rtrim($str, "; \r\n\t")).' ';
}
......
* @return string SQL query
* @see parseSQL()
*/
function compileSQL($components) {
public function compileSQL($components) {
switch($components['type']) {
case 'SELECT':
$query = $this->compileSELECT($components);
......
* @return string SQL SELECT query
* @see parseSELECT()
*/
function compileSELECT($components) {
protected function compileSELECT($components) {
// Initialize:
$where = $this->compileWhereClause($components['WHERE']);
......
* @return string SQL UPDATE query
* @see parseUPDATE()
*/
function compileUPDATE($components) {
protected function compileUPDATE($components) {
// Where clause:
$where = $this->compileWhereClause($components['WHERE']);
......
* @return string SQL INSERT query
* @see parseINSERT()
*/
function compileINSERT($components) {
protected function compileINSERT($components) {
if ($components['VALUES_ONLY']) {
// Initialize:
......
* @return string SQL DELETE query
* @see parseDELETE()
*/
function compileDELETE($components) {
protected function compileDELETE($components) {
// Where clause:
$where = $this->compileWhereClause($components['WHERE']);
......
* @return string SQL CREATE TABLE query
* @see parseCREATETABLE()
*/
function compileCREATETABLE($components) {
protected function compileCREATETABLE($components) {
// Create fields and keys:
$fieldsKeys = array();
......
* @return string SQL ALTER TABLE query
* @see parseALTERTABLE()
*/
function compileALTERTABLE($components) {
protected function compileALTERTABLE($components) {
// Make query:
$query = 'ALTER TABLE '.$components['TABLE'].' '.$components['action'].' '.($components['FIELD']?$components['FIELD']:$components['KEY']);
......
* @return string Select field string
* @see parseFieldList()
*/
function compileFieldList($selectFields) {
public function compileFieldList($selectFields) {
// Prepare buffer variable:
$outputParts = array();
......
* @return string Table name string
* @see parseFromTables()
*/
function compileFromTables($tablesArray) {
public function compileFromTables($tablesArray) {
// Prepare buffer variable:
$outputParts = array();
......
* @return string WHERE clause as string.
* @see explodeWhereClause()
*/
function compileWhereClause($clauseArray) {
public function compileWhereClause($clauseArray) {
// Prepare buffer variable:
$output='';
......
* @param array Field definition parts
* @return string Field definition string
*/
function compileFieldCfg($fieldCfg) {
protected function compileFieldCfg($fieldCfg) {
// Set type:
$cfg = $fieldCfg['fieldType'];
......
* @param string SQL string to verify parsability of
* @return mixed Returns array with string 1 and 2 if error, otherwise false
*/
function debug_parseSQLpart($part,$str) {
public function debug_parseSQLpart($part, $str) {
$retVal = false;
switch($part) {
......
* @param boolean If true, the strings are compared insensitive to case
* @return mixed Returns array with string 1 and 2 if error, otherwise false
*/
function debug_parseSQLpartCompare($str,$newStr,$caseInsensitive=FALSE) {
public function debug_parseSQLpartCompare($str, $newStr, $caseInsensitive = FALSE) {
if ($caseInsensitive) {
$str1 = strtoupper($str);
$str2 = strtoupper($newStr);
......
* @param string SQL query
* @return string Query if all is well, otherwise exit.
*/
function debug_testSQL($SQLquery) {
public function debug_testSQL($SQLquery) {
// Getting result array:
$parseResult = $this->parseSQL($SQLquery);
(2-2/2)