Bug #21368 » 12351.diff
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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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='') {
|
||
private 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) {
|
||
private function getValueInQuotes(&$parseString, $quote) {
|
||
$parts = explode($quote,substr($parseString,1));
|
||
$buffer = '';
|
||
... | ... | |
* @param string Input string
|
||
* @return string Output string
|
||
*/
|
||
function parseStripslashes($str) {
|
||
private 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) {
|
||
private 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) {
|
||
private 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) {
|
||
private function compileSELECT($components) {
|
||
// Initialize:
|
||
$where = $this->compileWhereClause($components['WHERE']);
|
||
... | ... | |
* @return string SQL UPDATE query
|
||
* @see parseUPDATE()
|
||
*/
|
||
function compileUPDATE($components) {
|
||
private 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) {
|
||
private 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);
|
t3lib/class.t3lib_sqlengine.php (working copy) | ||
---|---|---|
* @param object Parent object
|
||
* @return void
|
||
*/
|
||
function init($config, $pObj) {
|
||
public function init($config, $pObj) {
|
||
}
|
||
/**
|
||
... | ... | |
*
|
||
* @return void
|
||
*/
|
||
function resetStatusVars() {
|
||
public function resetStatusVars() {
|
||
$this->errorStatus = '';
|
||
$this->lastInsertedId = 0;
|
||
$this->lastAffectedRows = 0;
|
||
... | ... | |
* @param array $fInfo Field configuration data
|
||
* @return mixed The processed input value
|
||
*/
|
||
function processAccordingToConfig(&$value,$fInfo) {
|
||
private function processAccordingToConfig(&$value, $fInfo) {
|
||
$options = $this->parseFieldDef($fInfo['Type']);
|
||
switch(strtolower($options['fieldType'])) {
|
||
... | ... | |
* @param array Field values as key=>value pairs.
|
||
* @return boolean TRUE on success and FALSE on failure (error is set internally)
|
||
*/
|
||
function exec_INSERTquery($table,$fields_values) {
|
||
public function exec_INSERTquery($table, $fields_values) {
|
||
// Initialize
|
||
$this->resetStatusVars();
|
||
... | ... | |
* @param array Field values as key=>value pairs.
|
||
* @return boolean TRUE on success and FALSE on failure (error is set internally)
|
||
*/
|
||
function exec_UPDATEquery($table,$where,$fields_values) {
|
||
public function exec_UPDATEquery($table, $where, $fields_values) {
|
||
// Initialize:
|
||
$this->resetStatusVars();
|
||
... | ... | |
* @param string WHERE clause
|
||
* @return boolean TRUE on success and FALSE on failure (error is set internally)
|
||
*/
|
||
function exec_DELETEquery($table,$where) {
|
||
public function exec_DELETEquery($table, $where) {
|
||
// Initialize:
|
||
$this->resetStatusVars();
|
||
... | ... | |
* @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
|
||
* @return object Returns result object, but if errors, returns false
|
||
*/
|
||
function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit) {
|
||
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) {
|
||
// Initialize:
|
||
$this->resetStatusVars();
|
||
... | ... | |
* @param string Query to execute
|
||
* @return object Result object or false if error
|
||
*/
|
||
function sql_query($query) {
|
||
public function sql_query($query) {
|
||
$res = t3lib_div::makeInstance('t3lib_sqlengine_resultobj');
|
||
$res->result = array();
|
||
return $res;
|
||
... | ... | |
*
|
||
* @return string Error message, if any
|
||
*/
|
||
function sql_error() {
|
||
public function sql_error() {
|
||
return $this->errorStatus;
|
||
}
|
||
... | ... | |
*
|
||
* @return integer Last unique id created.
|
||
*/
|
||
function sql_insert_id() {
|
||
public function sql_insert_id() {
|
||
return $this->lastInsertedId;
|
||
}
|
||
... | ... | |
*
|
||
* @return integer Last amount of affected rows.
|
||
*/
|
||
function sql_affected_rows() {
|
||
public function sql_affected_rows() {
|
||
return $this->lastAffectedRows;
|
||
}
|
||
... | ... | |
* @param string Input String
|
||
* @return string String, with quotes escaped
|
||
*/
|
||
function quoteStr($str) {
|
||
public function quoteStr($str) {
|
||
return addslashes($str);
|
||
}
|
||
... | ... | |
* @return array Tables in an array (tablename is in both key and value)
|
||
* @todo Should return table details in value! see t3lib_db::admin_get_tables()
|
||
*/
|
||
function admin_get_tables() {
|
||
public function admin_get_tables() {
|
||
$whichTables = array();
|
||
return $whichTables;
|
||
}
|
||
... | ... | |
* @param string Table name
|
||
* @return array Field information in an associative array with fieldname => field row
|
||
*/
|
||
function admin_get_fields($tableName) {
|
||
public function admin_get_fields($tableName) {
|
||
$output = array();
|
||
return $output;
|
||
}
|
||
... | ... | |
* @param string Table name
|
||
* @return array Key information in a numeric array
|
||
*/
|
||
function admin_get_keys($tableName) {
|
||
public function admin_get_keys($tableName) {
|
||
$output = array();
|
||
return $output;
|
||
}
|
||
... | ... | |
* @param string Query to execute
|
||
* @return pointer Result pointer
|
||
*/
|
||
function admin_query($query) {
|
||
public function admin_query($query) {
|
||
return $this->sql_query($query);
|
||
}
|
||
... | ... | |
* @return void
|
||
* @todo Table locking tools?
|
||
*/
|
||
function readDataSource($table) {
|
||
public function readDataSource($table) {
|
||
$this->data[$table] = array();
|
||
}
|
||
... | ... | |
* @return void
|
||
* @todo Table locking tools?
|
||
*/
|
||
function saveDataSource($table) {
|
||
public function saveDataSource($table) {
|
||
debug($this->data[$table]);
|
||
}
|
||
... | ... | |
* @param array Where clause parsed into array
|
||
* @return array Array of keys pointing to result rows in $this->data[$table]
|
||
*/
|
||
function selectFromData($table,$where) {
|
||
public function selectFromData($table, $where) {
|
||
$output = array();
|
||
if (is_array($this->data[$table])) {
|
||
... | ... | |
* @return void Data array passed by reference
|
||
* @see selectFromData()
|
||
*/
|
||
function select_evalSingle($table,$config,&$itemKeys) {
|
||
public function select_evalSingle($table,$config,&$itemKeys) {
|
||
$neg = preg_match('/^AND[[:space:]]+NOT$/',trim($config['operator']));
|
||
if (is_array($config['sub'])) {
|
||
... | ... | |
* @param string Fieldlist (commaseparated)
|
||
* @return array Result array with "rows"
|
||
*/
|
||
function getResultSet($keys, $table, $fieldList) {
|
||
public function getResultSet($keys, $table, $fieldList) {
|
||
$fields = t3lib_div::trimExplode(',',$fieldList);
|
||
$output = array();
|
||
... | ... | |
* @param array Result set array (array of rows)
|
||
* @return string HTML table
|
||
*/
|
||
function debug_printResultSet($array) {
|
||
public function debug_printResultSet($array) {
|
||
if (count($array)) {
|
||
$tRows=array();
|
||
... | ... | |
*
|
||
* @return integer
|
||
*/
|
||
function sql_num_rows() {
|
||
public function sql_num_rows() {
|
||
return count($this->result);
|
||
}
|
||
... | ... | |
*
|
||
* @return array Associative array
|
||
*/
|
||
function sql_fetch_assoc() {
|
||
public function sql_fetch_assoc() {
|
||
$row = current($this->result);
|
||
next($this->result);
|
||
return $row;
|
||
... | ... | |
*
|
||
* @return array Numerical array
|
||
*/
|
||
function sql_fetch_row() {
|
||
public function sql_fetch_row() {
|
||
$resultRow = $this->sql_fetch_assoc();
|
||
if (is_array($resultRow)) {
|
||
... | ... | |
* @param integer Position pointer.
|
||
* @return boolean Returns true on success
|
||
*/
|
||
function sql_data_seek($pointer) {
|
||
public function sql_data_seek($pointer) {
|
||
reset($this->result);
|
||
for ($a=0;$a<$pointer;$a++) {
|
||
next($this->result);
|
||
... | ... | |
*
|
||
* @return string Blank string, not supported (it seems)
|
||
*/
|
||
function sql_field_type() {
|
||
public function sql_field_type() {
|
||
return '';
|
||
}
|
||
}
|