Constants

TOKEN_TYPE_WHITESPACE

TOKEN_TYPE_WHITESPACE = 0

TOKEN_TYPE_WORD

TOKEN_TYPE_WORD = 1

TOKEN_TYPE_QUOTE

TOKEN_TYPE_QUOTE = 2

TOKEN_TYPE_BACKTICK_QUOTE

TOKEN_TYPE_BACKTICK_QUOTE = 3

TOKEN_TYPE_RESERVED

TOKEN_TYPE_RESERVED = 4

TOKEN_TYPE_RESERVED_TOPLEVEL

TOKEN_TYPE_RESERVED_TOPLEVEL = 5

TOKEN_TYPE_RESERVED_NEWLINE

TOKEN_TYPE_RESERVED_NEWLINE = 6

TOKEN_TYPE_BOUNDARY

TOKEN_TYPE_BOUNDARY = 7

TOKEN_TYPE_COMMENT

TOKEN_TYPE_COMMENT = 8

TOKEN_TYPE_BLOCK_COMMENT

TOKEN_TYPE_BLOCK_COMMENT = 9

TOKEN_TYPE_NUMBER

TOKEN_TYPE_NUMBER = 10

TOKEN_TYPE_ERROR

TOKEN_TYPE_ERROR = 11

TOKEN_TYPE_VARIABLE

TOKEN_TYPE_VARIABLE = 12

TOKEN_TYPE

TOKEN_TYPE = 0

TOKEN_VALUE

TOKEN_VALUE = 1

Properties

$quote_attributes

$quote_attributes : 

Type

$backtick_quote_attributes

$backtick_quote_attributes : 

Type

$reserved_attributes

$reserved_attributes : 

Type

$boundary_attributes

$boundary_attributes : 

Type

$number_attributes

$number_attributes : 

Type

$word_attributes

$word_attributes : 

Type

$error_attributes

$error_attributes : 

Type

$comment_attributes

$comment_attributes : 

Type

$variable_attributes

$variable_attributes : 

Type

$pre_attributes

$pre_attributes : 

Type

$cli

$cli : 

Type

$cli_quote

$cli_quote : 

Type

$cli_backtick_quote

$cli_backtick_quote : 

Type

$cli_reserved

$cli_reserved : 

Type

$cli_boundary

$cli_boundary : 

Type

$cli_number

$cli_number : 

Type

$cli_word

$cli_word : 

Type

$cli_error

$cli_error : 

Type

$cli_comment

$cli_comment : 

Type

$cli_functions

$cli_functions : 

Type

$cli_variable

$cli_variable : 

Type

$tab

$tab : 

Type

$use_pre

$use_pre : 

Type

$max_cachekey_size

$max_cachekey_size : 

Type

$reserved

$reserved : 

Type

$reserved_toplevel

$reserved_toplevel : 

Type

$reserved_newline

$reserved_newline : 

Type

$functions

$functions : 

Type

$boundaries

$boundaries : 

Type

$init

$init : 

Type

$regex_boundaries

$regex_boundaries : 

Type

$regex_reserved

$regex_reserved : 

Type

$regex_reserved_newline

$regex_reserved_newline : 

Type

$regex_reserved_toplevel

$regex_reserved_toplevel : 

Type

$regex_function

$regex_function : 

Type

$token_cache

$token_cache : 

Type

$cache_hits

$cache_hits : 

Type

$cache_misses

$cache_misses : 

Type

Methods

getCacheStats()

getCacheStats() : Array

Get stats about the token cache

Returns

Array —

An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes

format()

format(String  $string, boolean  $highlight = true) : String

Format the whitespace in a SQL string to make it easier to read.

Parameters

String $string

The SQL string

boolean $highlight

If true, syntax highlighting will also be performed

Returns

String —

The SQL string with HTML styles and formatting wrapped in a

 tag

highlight()

highlight(String  $string) : String

Add syntax highlighting to a SQL string

Parameters

String $string

The SQL string

Returns

String —

The SQL string with HTML styles applied

splitQuery()

splitQuery(String  $string) : Array

Split a SQL string into multiple queries.

Uses ";" as a query delimiter.

Parameters

String $string

The SQL string

Returns

Array —

An array of individual query strings without trailing semicolons

removeComments()

removeComments(String  $string) : String

Remove all comments from a SQL string

Parameters

String $string

The SQL string

Returns

String —

The SQL string without comments

compress()

compress(String  $string) : String

Compress a query by collapsing white space and removing comments

Parameters

String $string

The SQL string

Returns

String —

The SQL string without comments

init()

init() 

Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words.

getNextToken()

getNextToken(String  $string, array  $previous = null) : Array

Return the next token and token type in a SQL string.

Quoted strings, comments, reserved words, whitespace, and punctuation are all their own tokens.

Parameters

String $string

The SQL string

array $previous

The result of the previous getNextToken() call

Returns

Array —

An associative array containing the type and value of the token.

getQuotedString()

getQuotedString(  $string) 

Parameters

$string

tokenize()

tokenize(String  $string) : Array

Takes a SQL string and breaks it into tokens.

Each token is an associative array with type and value.

Parameters

String $string

The SQL string

Returns

Array —

An array of tokens.

highlightToken()

highlightToken(Array  $token) : String

Highlights a token depending on its type.

Parameters

Array $token

An associative array containing type and value.

Returns

String —

HTML code of the highlighted token.

highlightQuote()

highlightQuote(String  $value) : String

Highlights a quoted string

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightBacktickQuote()

highlightBacktickQuote(String  $value) : String

Highlights a backtick quoted string

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightReservedWord()

highlightReservedWord(String  $value) : String

Highlights a reserved word

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightBoundary()

highlightBoundary(String  $value) : String

Highlights a boundary token

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightNumber()

highlightNumber(String  $value) : String

Highlights a number

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightError()

highlightError(String  $value) : String

Highlights an error

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightComment()

highlightComment(String  $value) : String

Highlights a comment

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightWord()

highlightWord(String  $value) : String

Highlights a word token

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

highlightVariable()

highlightVariable(String  $value) : String

Highlights a variable token

Parameters

String $value

The token's value

Returns

String —

HTML code of the highlighted token.

quote_regex()

quote_regex(String  $a) : String

Helper function for building regular expressions for reserved words and boundary characters

Parameters

String $a

The string to be quoted

Returns

String —

The quoted string

output()

output(String  $string) : String

Helper function for building string output

Parameters

String $string

The string to be quoted

Returns

String —

The quoted string

is_cli()

is_cli()