[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/t3lib/ -> class.t3lib_sqlparser.php (sommaire)

TYPO3 SQL parser $Id: class.t3lib_sqlparser.php 1573 2006-06-30 12:47:46Z k-fish $

Author: Kasper Skaarhoj <kasperYYYY@typo3.com>
Poids: 1743 lignes (58 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

t3lib_sqlparser:: (35 méthodes):
  parseSQL()
  parseSELECT()
  parseUPDATE()
  parseINSERT()
  parseDELETE()
  parseEXPLAIN()
  parseCREATETABLE()
  parseALTERTABLE()
  parseDROPTABLE()
  parseCREATEDATABASE()
  parseFieldList()
  parseFromTables()
  parseWhereClause()
  parseFieldDef()
  nextPart()
  getValue()
  getValueInQuotes()
  parseStripslashes()
  compileAddslashes()
  parseError()
  trimSQL()
  compileSQL()
  compileSELECT()
  compileUPDATE()
  compileINSERT()
  compileDELETE()
  compileCREATETABLE()
  compileALTERTABLE()
  compileFieldList()
  compileFromTables()
  compileWhereClause()
  compileFieldCfg()
  debug_parseSQLpart()
  debug_parseSQLpartCompare()
  debug_testSQL()


Classe: t3lib_sqlparser  - X-Ref

TYPO3 SQL parser class.

parseSQL($parseString)   X-Ref
Parses any single SQL query

param: string        SQL query
return: array        Result array with all the parts in - or error message string

parseSELECT($parseString)   X-Ref
Parsing SELECT query

param: string        SQL string with SELECT query to parse
return: mixed        Returns array with components of SELECT query on success, otherwise an error message string.

parseUPDATE($parseString)   X-Ref
Parsing UPDATE query

param: string        SQL string with UPDATE query to parse
return: mixed        Returns array with components of UPDATE query on success, otherwise an error message string.

parseINSERT($parseString)   X-Ref
Parsing INSERT query

param: string        SQL string with INSERT query to parse
return: mixed        Returns array with components of INSERT query on success, otherwise an error message string.

parseDELETE($parseString)   X-Ref
Parsing DELETE query

param: string        SQL string with DELETE query to parse
return: mixed        Returns array with components of DELETE query on success, otherwise an error message string.

parseEXPLAIN($parseString)   X-Ref
Parsing EXPLAIN query

param: string        SQL string with EXPLAIN query to parse
return: mixed        Returns array with components of EXPLAIN query on success, otherwise an error message string.

parseCREATETABLE($parseString)   X-Ref
Parsing CREATE TABLE query

param: string        SQL string starting with CREATE TABLE
return: mixed        Returns array with components of CREATE TABLE query on success, otherwise an error message string.

parseALTERTABLE($parseString)   X-Ref
Parsing ALTER TABLE query

param: string        SQL string starting with ALTER TABLE
return: mixed        Returns array with components of ALTER TABLE query on success, otherwise an error message string.

parseDROPTABLE($parseString)   X-Ref
Parsing DROP TABLE query

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.

parseCREATEDATABASE($parseString)   X-Ref
Parsing CREATE DATABASE query

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.

parseFieldList(&$parseString, $stopRegex='')   X-Ref
Parsing the fields in the "SELECT [$selectFields] FROM" part of a query into an array.
The output from this function can be compiled back into a field list with ->compileFieldList()
Will detect the keywords "DESC" and "ASC" after the table name; thus is can be used for parsing the more simply ORDER BY and GROUP BY field lists as well!

param: string        The string with fieldnames, eg. "title, uid AS myUid, max(tstamp), count(*)" etc. NOTICE: passed by reference!
param: string        Regular expressing to STOP parsing, eg. '^(FROM)([[:space:]]*)'
return: array        If successful parsing, returns an array, otherwise an error string.

parseFromTables(&$parseString, $stopRegex='')   X-Ref
Parsing the tablenames in the "FROM [$parseString] WHERE" part of a query into an array.
The success of this parsing determines if that part of the query is supported by TYPO3.

param: string        list of tables, eg. "pages, tt_content" or "pages A, pages B". NOTICE: passed by reference!
param: string        Regular expressing to STOP parsing, eg. '^(WHERE)([[:space:]]*)'
return: array        If successful parsing, returns an array, otherwise an error string.

parseWhereClause(&$parseString, $stopRegex='')   X-Ref
Parsing the WHERE clause fields in the "WHERE [$parseString] ..." part of a query into a multidimensional array.
The success of this parsing determines if that part of the query is supported by TYPO3.

param: string        WHERE clause to parse. NOTICE: passed by reference!
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.

parseFieldDef(&$parseString, $stopRegex='')   X-Ref
Parsing the WHERE clause fields in the "WHERE [$parseString] ..." part of a query into a multidimensional array.
The success of this parsing determines if that part of the query is supported by TYPO3.

param: string        WHERE clause to parse. NOTICE: passed by reference!
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.

nextPart(&$parseString,$regex,$trimAll=FALSE)   X-Ref
Strips off a part of the parseString and returns the matching part.
Helper function for the parsing methods.

param: string        Parse string; if $regex finds anything the value of the first () level will be stripped of the string in the beginning. Further $parseString is left-trimmed (on success). Notice; parsestring is passed by reference.
param: string        Regex to find a matching part in the beginning of the string. Rules: You MUST start the regex with "^" (finding stuff in the beginning of string) and the result of the first parenthesis is what will be returned to you (and stripped of the string). Eg. '^(AND|OR|&&)[[:space:]]+' will return AND, OR or && if found and having one of more whitespaces after it, plus shorten $parseString with that match and any space after (by ltrim())
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.

getValue(&$parseString,$comparator='')   X-Ref
Finds value in beginning of $parseString, returns result and strips it of parseString

param: string        The parseString, eg. "(0,1,2,3) ..." or "('asdf','qwer') ..." or "1234 ..." or "'My string value here' ..."
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)

getValueInQuotes(&$parseString,$quote)   X-Ref
Get value in quotes from $parseString.
NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed

param: string        String from which to find value in quotes. Notice that $parseString is passed by reference and is shortend by the output of this function.
param: string        The quote used; input either " or '
return: string        The value, passed through stripslashes() !

parseStripslashes($str)   X-Ref
Strip slashes function used for parsing
NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed

param: string        Input string
return: string        Output string

compileAddslashes($str)   X-Ref
Add slashes function used for compiling queries
NOTICE: If a query being parsed was prepared for another database than MySQL this function should probably be changed

param: string        Input string
return: string        Output string

parseError($msg,$restQuery)   X-Ref
Setting the internal error message value, $this->parse_error and returns that value.

param: string        Input error message
param: string        Remaining query to parse.
return: string        Error message.

trimSQL($str)   X-Ref
Trimming SQL as preparation for parsing.
";" in the end is stripped of.
White space is trimmed away around the value
A single space-char is added in the end

param: string        Input string
return: string        Output string

compileSQL($components)   X-Ref
Compiles an SQL query from components

param: array        Array of SQL query components
return: string        SQL query

compileSELECT($components)   X-Ref
Compiles a SELECT statement from components array

param: array        Array of SQL query components
return: string        SQL SELECT query

compileUPDATE($components)   X-Ref
Compiles an UPDATE statement from components array

param: array        Array of SQL query components
return: string        SQL UPDATE query

compileINSERT($components)   X-Ref
Compiles an INSERT statement from components array

param: array        Array of SQL query components
return: string        SQL INSERT query

compileDELETE($components)   X-Ref
Compiles an DELETE statement from components array

param: array        Array of SQL query components
return: string        SQL DELETE query

compileCREATETABLE($components)   X-Ref
Compiles a CREATE TABLE statement from components array

param: array        Array of SQL query components
return: string        SQL CREATE TABLE query

compileALTERTABLE($components)   X-Ref
Compiles an ALTER TABLE statement from components array

param: array        Array of SQL query components
return: string        SQL ALTER TABLE query

compileFieldList($selectFields)   X-Ref
Compiles a "SELECT [output] FROM..:" field list based on input array (made with ->parseFieldList())
Can also compile field lists for ORDER BY and GROUP BY.

param: array        Array of select fields, (made with ->parseFieldList())
return: string        Select field string

compileFromTables($tablesArray)   X-Ref
Compiles a "FROM [output] WHERE..:" table list based on input array (made with ->parseFromTables())

param: array        Array of table names, (made with ->parseFromTables())
return: string        Table name string

compileWhereClause($clauseArray)   X-Ref
Implodes an array of WHERE clause configuration into a WHERE clause.
NOTICE: MIGHT BY A TEMPORARY FUNCTION. Use for debugging only!
BUT IT IS NEEDED FOR DBAL - MAKE IT PERMANENT?!?!

param: array        WHERE clause configuration
return: string        WHERE clause as string.

compileFieldCfg($fieldCfg)   X-Ref
Compile field definition

param: array        Field definition parts
return: string        Field definition string

debug_parseSQLpart($part,$str)   X-Ref
Check parsability of input SQL part string; Will parse and re-compile after which it is compared

param: string        Part definition of string; "SELECT" = fieldlist (also ORDER BY and GROUP BY), "FROM" = table list, "WHERE" = Where clause.
param: string        SQL string to verify parsability of
return: mixed        Returns array with string 1 and 2 if error, otherwise false

debug_parseSQLpartCompare($str,$newStr,$caseInsensitive=FALSE)   X-Ref
Compare two query strins by stripping away whitespace.

param: string        SQL String 1
param: string        SQL string 2
param: boolean        If true, the strings are compared insensitive to case
return: mixed        Returns array with string 1 and 2 if error, otherwise false

debug_testSQL($SQLquery)   X-Ref
Performs the ultimate test of the parser: Direct a SQL query in; You will get it back (through the parsed and re-compiled) if no problems, otherwise the script will print the error and exit

param: string        SQL query
return: string        Query if all is well, otherwise exit.



Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics