class Doctrine_Query_Tokenizer (View source)

Doctrine_Query_Tokenizer

Methods

array
tokenizeQuery(string $query)

Splits the given dql query into an array where keys represent different query part names and values are arrays splitted using sqlExplode method

string
bracketTrim(string $str, string $e1 = '(', string $e2 = ')')

Trims brackets from string

array
bracketExplode(string $str, string $d = ' ', string $e1 = '(', string $e2 = ')')

Explodes a sql expression respecting bracket placement.

array
quoteExplode(string $str, string $d = ' ')

Explode quotes from string

array
sqlExplode(string $str, string $d = ' ', string $e1 = '(', string $e2 = ')')

Explodes a string into array using custom brackets and quote delimeters

array
clauseExplode(string $str, array $d, string $e1 = '(', string $e2 = ')')

Explodes a string into array using custom brackets and quote delimeters Each array element is a array of length 2 where the first entry contains the term, and the second entry contains the corresponding delimiter

array
quotedStringExplode($str)

Explodes the given string by

Details

array tokenizeQuery(string $query)

Splits the given dql query into an array where keys represent different query part names and values are arrays splitted using sqlExplode method

example:

parameter: $query = "SELECT u.* FROM User u WHERE u.name LIKE ?" returns: array( 'select' => array('u.*'), 'from' => array('User', 'u'), 'where' => array('u.name', 'LIKE', '?') );

Parameters

string $query DQL query

Return Value

array An array containing the query string parts

Exceptions

Doctrine_Query_Exception If some generic parsing error occurs

string bracketTrim(string $str, string $e1 = '(', string $e2 = ')')

Trims brackets from string

Parameters

string $str String to remove the brackets
string $e1 First bracket, usually '('
string $e2 Second bracket, usually ')'

Return Value

string

array bracketExplode(string $str, string $d = ' ', string $e1 = '(', string $e2 = ')')

Explodes a sql expression respecting bracket placement.

This method transform a sql expression in an array of simple clauses, while observing the parentheses precedence.

Note: bracketExplode always trims the returned pieces

$str = (age < 20 AND age > 18) AND email LIKE '[email protected]' $clauses = $tokenizer->bracketExplode($str, ' AND ', '(', ')'); // array("(age < 20 AND age > 18)", "email LIKE '[email protected]'")

Parameters

string $str String to be bracket exploded
string $d Delimeter which explodes the string
string $e1 First bracket, usually '('
string $e2 Second bracket, usually ')'

Return Value

array

array quoteExplode(string $str, string $d = ' ')

Explode quotes from string

Note: quoteExplode always trims the returned pieces

example:

parameters: $str = email LIKE '[email protected]' $d = ' LIKE '

would return an array: array("email", "LIKE", "'[email protected]'")

Parameters

string $str String to be quote exploded
string $d Delimeter which explodes the string

Return Value

array

array sqlExplode(string $str, string $d = ' ', string $e1 = '(', string $e2 = ')')

Explodes a string into array using custom brackets and quote delimeters

Note: sqlExplode trims all returned parts

example:

parameters: $str = "(age < 20 AND age > 18) AND name LIKE 'John Doe'" $d = ' ' $e1 = '(' $e2 = ')'

would return an array: array( '(age < 20 AND age > 18)', 'name', 'LIKE', 'John Doe' );

Parameters

string $str String to be SQL exploded
string $d Delimeter which explodes the string
string $e1 First bracket, usually '('
string $e2 Second bracket, usually ')'

Return Value

array

array clauseExplode(string $str, array $d, string $e1 = '(', string $e2 = ')')

Explodes a string into array using custom brackets and quote delimeters Each array element is a array of length 2 where the first entry contains the term, and the second entry contains the corresponding delimiter

example:

parameters: $str = "(age < 20 AND age > 18) AND name LIKE 'John'+' Doe'" $d = array(' ', '+') $e1 = '(' $e2 = ')'

would return an array: array( array('(age < 20 AND age > 18)', ' '), array('AND', ' '), array('name', ' '), array('LIKE', ' '), array('John', '+'), array(' Doe', '') );

Parameters

string $str String to be clause exploded
array $d Delimeter which explodes the string
string $e1 First bracket, usually '('
string $e2 Second bracket, usually ')'

Return Value

array

array quotedStringExplode($str)

Explodes the given string by

example:

paramters: $str ="'a' AND name = 'John O\'Connor'"

returns array("", "'a'", " AND name = ", "'John O\'Connor'")

Note the trailing empty string. In the result, all even elements are quoted strings.

Parameters

$str the string to split

Return Value

array