MysqlQueryBuilder

Trait for MySQL Query Building.

since

2.0.0

package

Joomla Framework

Methods

__toString

Magic function to convert the query to a string.

__toString() : 
since

2.0.0

Response

stringThe completed query.

castAs

Casts a value to a char.

castAs( type,  value,  length = null) : 

Ensure that the value is properly quoted before passing to the method.

Usage: $query->select($query->castAs('CHAR', 'a'));

since

1.0

Arguments

type

stringThe type of string to cast as.

value

stringThe value to cast as a char.

length

stringThe value to cast as a char.

Response

stringSQL statement to cast the value as a char type.

concatenate

Concatenates an array of column names or values.

concatenate(string||string|int values, string|null separator = null) : 
since

2.0.0

Arguments

values

array<string|int, string>An array of values to concatenate.

separator

string|nullAs separator to place between each value.

Response

stringThe concatenated values.

findInSet

Find a value in a varchar used like a set.

findInSet( value,  set) : 

Ensure that the value is an integer before passing to the method.

Usage: $query->findInSet((int) $parent->id, 'a.assigned_cat_ids')

since

2.0.0

Arguments

value

stringThe value to search for.

set

stringThe set of values.

Response

stringA representation of the MySQL find_in_set() function for the driver.

groupConcat

Aggregate function to get input values concatenated into a string, separated by delimiter

groupConcat( expression,  separator = ',') : 

Usage: $query->groupConcat('id', ',');

since

2.0.0

Arguments

expression

stringThe expression to apply concatenation to, this may be a column name or complex SQL statement.

separator

stringThe delimiter of each concatenated value

Response

stringInput values concatenated into a string, separated by delimiter

processLimit

Method to modify a query already in string format with the needed additions to make the query limited to a particular number of results, or start at a particular offset.

processLimit( query,  limit,  offset) : 
since

2.0.0

Arguments

query

stringThe query in string format

limit

intThe limit for the result set

offset

intThe offset for the result set

Response

string

quote

Method to quote and optionally escape a string to database requirements for insertion into the database.

quote(array|string text,  escape = true) : 
abstract

This method is provided for use where the query object is passed to a function for modification. If you have direct access to the database object, it is recommended you use the quote method directly.

Note that 'q' is an alias for this method as it is in DatabaseDriver.

Usage: $query->quote('fulltext'); $query->q('fulltext'); $query->q(array('option', 'fulltext'));

since

2.0.0

throws

RuntimeExceptionif the internal db property is not a valid object.

Arguments

text

array<string|int, mixed>|stringA string or an array of strings to quote.

escape

boolTrue (default) to escape the string, false to leave it unchanged.

Response

stringThe quoted input string.

rand

Get the function to return a random floating-point value

rand() : 

Usage: $query->rand();

since

2.0.0

Response

string

regexp

Get the regular expression operator

regexp( value) : 

Usage: $query->where('field ' . $query->regexp($search));

since

2.0.0

Arguments

value

stringThe regex pattern.

Response

string

selectRowNumber

Return the number of the current row.

selectRowNumber( orderBy,  orderColumnAlias) : 

Usage: $query->select('id'); $query->selectRowNumber('ordering,publish_up DESC', 'new_ordering'); $query->from('#__content');

since

2.0.0

throws

RuntimeException

todo

Remove this method when the database version requirements have been raised to >= 8.0.0 for MySQL and >= 10.2.0 for MariaDB so the ROW_NUMBER() window function can be used in any case.

Arguments

orderBy

stringAn expression of ordering for window function.

orderColumnAlias

stringAn alias for new ordering column.

Response

$this