public
string
|
#
__call( string $method, array $args )
Magic method to provide method alias support for quote() and quoteName().
Magic method to provide method alias support for quote() and quoteName().
Parameters
- $method
string - $method The called method.
- $args
array - $args The array of arguments passed to the method.
Returns
string - The aliased method's return value or null.
Since
11.1
|
public
|
|
public
string
|
#
__toString( )
Magic function to convert the query to a string.
Magic function to convert the query to a string.
Returns
string - The completed query.
Since
11.1
|
public
mixed
|
#
__get( string $name )
Magic function to get protected variable value
Magic function to get protected variable value
Parameters
- $name
string - $name The name of the variable.
Returns
mixed
Since
11.1
|
public
JDatabaseQuery
|
#
call( mixed $columns )
Add a single column, or array of columns to the CALL clause of the query.
Add a single column, or array of columns to the CALL clause of the query.
Note that you must not mix insert, update, delete and select method calls
when building a query. The call method can, however, be called multiple times in
the same query.
Usage: $query->call('a.')->call('b.id');
$query->call(array('a.', 'b.id'));
Parameters
- $columns
mixed - $columns A string or an array of field names.
Returns
Since
12.1
|
public
string
|
#
castAsChar( string $value )
Casts a value to a char.
Ensure that the value is properly quoted before passing to the method.
Usage: $query->select($query->castAsChar('a'));
Parameters
- $value
string - $value The value to cast as a char.
Returns
string - Returns the cast value.
Since
11.1
|
public
string
|
#
charLength( string $field, string $operator = null, string $condition = null )
Gets the number of characters in a string.
Gets the number of characters in a string.
Note, use 'length' to find the number of bytes in a string.
Usage: $query->select($query->charLength('a'));
Parameters
- $field
string - $field A value.
- $operator
string - $operator Comparison operator between charLength integer value and $condition
- $condition
string - $condition Integer value to compare charLength with.
Returns
string - The required char length call.
Since
11.1
|
public
JDatabaseQuery
|
#
clear( string $clause = null )
Clear data from the query or a specific clause of the query.
Clear data from the query or a specific clause of the query.
Parameters
- $clause
string - $clause Optionally, the name of the clause to clear, or nothing to clear the
whole query.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
columns( mixed $columns )
Adds a column, or array of column names that would be used for an INSERT INTO
statement.
Adds a column, or array of column names that would be used for an INSERT INTO
statement.
Parameters
- $columns
mixed - $columns A column name, or array of column names.
Returns
Since
11.1
|
public
string
|
#
concatenate( array $values, string $separator = null )
Concatenates an array of column names or values.
Concatenates an array of column names or values.
Usage: $query->select($query->concatenate(array('a', 'b')));
Parameters
- $values
array - $values An array of values to concatenate.
- $separator
string - $separator As separator to place between each value.
Returns
string - The concatenated values.
Since
11.1
|
public
string
|
#
currentTimestamp( )
Gets the current date and time.
Gets the current date and time.
Usage: $query->where('published_up <
'.$query->currentTimestamp());
Returns
string
Since
11.1
|
public
string
|
#
dateFormat( )
Returns a PHP date() function compliant date format for the database
driver.
Returns a PHP date() function compliant date format for the database
driver.
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 getDateFormat method directly.
Returns
string - The format string.
Since
11.1
|
public
string
|
#
dump( )
Creates a formatted dump of the query for debugging purposes.
Creates a formatted dump of the query for debugging purposes.
Usage: echo $query->dump();
Returns
string
Since
11.3
|
public
JDatabaseQuery
|
#
delete( string $table = null )
Add a table name to the DELETE clause of the query.
Add a table name to the DELETE clause of the query.
Note that you must not mix insert, update, delete and select method calls
when building a query.
Usage: $query->delete('#__a')->where('id = 1');
Parameters
- $table
string - $table The name of the table to delete from.
Returns
Since
11.1
|
public
string
|
#
escape( string $text, boolean $extra = false )
Method to escape a string for usage in an SQL statement.
Method to escape a string for usage in an SQL statement.
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 escape method directly.
Note that 'e' is an alias for this method as it is in JDatabaseDriver.
Parameters
- $text
string - $text The string to be escaped.
- $extra
boolean - $extra Optional parameter to provide extra escaping.
Returns
string - The escaped string.
Throws
Since
11.1
|
public
JDatabaseQuery
|
#
exec( mixed $columns )
Add a single column, or array of columns to the EXEC clause of the query.
Add a single column, or array of columns to the EXEC clause of the query.
Note that you must not mix insert, update, delete and select method calls
when building a query. The exec method can, however, be called multiple times in
the same query.
Usage: $query->exec('a.')->exec('b.id');
$query->exec(array('a.', 'b.id'));
Parameters
- $columns
mixed - $columns A string or an array of field names.
Returns
Since
12.1
|
public
JDatabaseQuery
|
#
from( mixed $tables, string $subQueryAlias = null )
Add a table to the FROM clause of the query.
Add a table to the FROM clause of the query.
Note that while an array of tables can be provided, it is recommended you use
explicit joins.
Usage: $query->select('*')->from('#__a');
Parameters
- $tables
mixed - $tables A string or array of table names. This can be a JDatabaseQuery object
(or a child of it) when used as a subquery in FROM clause along with a value for
$subQueryAlias.
- $subQueryAlias
string - $subQueryAlias Alias used when $tables is a JDatabaseQuery.
Returns
Throws
Since
11.1
|
public
string
|
#
year( string $date )
Used to get a string to extract year from date column.
Used to get a string to extract year from date column.
Usage:
$query->select($query->year($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing year to be extracted.
Returns
string - Returns string to extract year from a date.
Since
12.1
|
public
string
|
#
month( string $date )
Used to get a string to extract month from date column.
Used to get a string to extract month from date column.
Usage:
$query->select($query->month($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing month to be extracted.
Returns
string - Returns string to extract month from a date.
Since
12.1
|
public
string
|
#
day( string $date )
Used to get a string to extract day from date column.
Used to get a string to extract day from date column.
Usage:
$query->select($query->day($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing day to be extracted.
Returns
string - Returns string to extract day from a date.
Since
12.1
|
public
string
|
#
hour( string $date )
Used to get a string to extract hour from date column.
Used to get a string to extract hour from date column.
Usage:
$query->select($query->hour($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing hour to be extracted.
Returns
string - Returns string to extract hour from a date.
Since
12.1
|
public
string
|
#
minute( string $date )
Used to get a string to extract minute from date column.
Used to get a string to extract minute from date column.
Usage:
$query->select($query->minute($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing minute to be extracted.
Returns
string - Returns string to extract minute from a date.
Since
12.1
|
public
string
|
#
second( string $date )
Used to get a string to extract seconds from date column.
Used to get a string to extract seconds from date column.
Usage:
$query->select($query->second($query->quoteName('dateColumn')));
Parameters
- $date
string - $date Date column containing second to be extracted.
Returns
string - Returns string to extract second from a date.
Since
12.1
|
public
JDatabaseQuery
|
#
group( mixed $columns )
Add a grouping column to the GROUP clause of the query.
Add a grouping column to the GROUP clause of the query.
Usage: $query->group('id');
Parameters
- $columns
mixed - $columns A string or array of ordering columns.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
having( mixed $conditions, string $glue = 'AND' )
A conditions to the HAVING clause of the query.
A conditions to the HAVING clause of the query.
Usage: $query->group('id')->having('COUNT(id) > 5');
Parameters
- $conditions
mixed - $conditions A string or array of columns.
- $glue
string - $glue The glue by which to join the conditions. Defaults to AND.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
innerJoin( string $condition )
Add an INNER JOIN clause to the query.
Add an INNER JOIN clause to the query.
Usage: $query->innerJoin('b ON b.id = a.id')->innerJoin('c ON c.id =
b.id');
Parameters
- $condition
string - $condition The join condition.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
insert( mixed $table, boolean $incrementField = false )
Add a table name to the INSERT clause of the query.
Add a table name to the INSERT clause of the query.
Note that you must not mix insert, update, delete and select method calls
when building a query.
Usage: $query->insert('#__a')->set('id = 1');
$query->insert('#__a')->columns('id,
title')->values('1,2')->values('3,4');
$query->insert('#__a')->columns('id, title')->values(array('1,2',
'3,4'));
Parameters
- $table
mixed - $table The name of the table to insert data into.
- $incrementField
boolean - $incrementField The name of the field to auto increment.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
join( string $type, string $conditions )
Add a JOIN clause to the query.
Add a JOIN clause to the query.
Usage: $query->join('INNER', 'b ON b.id = a.id);
Parameters
- $type
string - $type The type of join. This string is prepended to the JOIN keyword.
- $conditions
string - $conditions A string or array of conditions.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
leftJoin( string $condition )
Add a LEFT JOIN clause to the query.
Add a LEFT JOIN clause to the query.
Usage: $query->leftJoin('b ON b.id = a.id')->leftJoin('c ON c.id =
b.id');
Parameters
- $condition
string - $condition The join condition.
Returns
Since
11.1
|
public
integer
|
#
length( string $value )
Get the length of a string in bytes.
Get the length of a string in bytes.
Note, use 'charLength' to find the number of characters in a string.
Usage: query->where($query->length('a').' > 3');
Parameters
- $value
string - $value The string to measure.
Returns
integer
Since
11.1
|
public
string
|
#
nullDate( boolean $quoted = true )
Get the null or zero representation of a timestamp for the database
driver.
Get the null or zero representation of a timestamp for the database
driver.
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 nullDate method directly.
Usage: $query->where('modified_date <> '.$query->nullDate());
Parameters
- $quoted
boolean - $quoted Optionally wraps the null date in database quotes (true by default).
Returns
string - Null or zero representation of a timestamp.
Since
11.1
|
public
JDatabaseQuery
|
#
order( mixed $columns )
Add an ordering column to the ORDER clause of the query.
Add an ordering column to the ORDER clause of the query.
Usage: $query->order('foo')->order('bar');
$query->order(array('foo','bar'));
Parameters
- $columns
mixed - $columns A string or array of ordering columns.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
outerJoin( string $condition )
Add an OUTER JOIN clause to the query.
Add an OUTER JOIN clause to the query.
Usage: $query->outerJoin('b ON b.id = a.id')->outerJoin('c ON c.id =
b.id');
Parameters
- $condition
string - $condition The join condition.
Returns
Since
11.1
|
public
string
|
#
quote( mixed $text, boolean $escape = true )
Method to quote and optionally escape a string to database requirements for
insertion into the database.
Method to quote and optionally escape a string to database requirements for
insertion into the database.
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 JDatabaseDriver.
Usage: $query->quote('fulltext'); $query->q('fulltext');
$query->q(array('option', 'fulltext'));
Parameters
- $text
mixed - $text A string or an array of strings to quote.
- $escape
boolean - $escape True to escape the string, false to leave it unchanged.
Returns
string - The quoted input string.
Throws
Since
11.1
|
public
mixed
|
#
quoteName( mixed $name, mixed $as = null )
Wrap an SQL statement identifier name such as column, table or database names
in quotes to prevent injection risks and reserved word conflicts.
Wrap an SQL statement identifier name such as column, table or database names
in quotes to prevent injection risks and reserved word conflicts.
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 quoteName method directly.
Note that 'qn' is an alias for this method as it is in JDatabaseDriver.
Usage: $query->quoteName('#__a'); $query->qn('#__a');
Parameters
- $name
mixed - $name The identifier name to wrap in quotes, or an array of identifier names to
wrap in quotes. Each type supports dot-notation name.
- $as
mixed - $as The AS query part associated to $name. It can be string or array, in latter
case it has to be same length of $name; if is null there will not be any AS part
for string or array element.
Returns
mixed - The quote wrapped name, same type of $name.
Throws
Since
11.1
|
public
JDatabaseQuery
|
#
rightJoin( string $condition )
Add a RIGHT JOIN clause to the query.
Add a RIGHT JOIN clause to the query.
Usage: $query->rightJoin('b ON b.id = a.id')->rightJoin('c ON c.id =
b.id');
Parameters
- $condition
string - $condition The join condition.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
select( mixed $columns )
Add a single column, or array of columns to the SELECT clause of the
query.
Add a single column, or array of columns to the SELECT clause of the
query.
Note that you must not mix insert, update, delete and select method calls
when building a query. The select method can, however, be called multiple times
in the same query.
Usage: $query->select('a.')->select('b.id');
$query->select(array('a.', 'b.id'));
Parameters
- $columns
mixed - $columns A string or an array of field names.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
set( mixed $conditions, string $glue = ',' )
Add a single condition string, or an array of strings to the SET clause of
the query.
Add a single condition string, or an array of strings to the SET clause of
the query.
Usage: $query->set('a = 1')->set('b = 2'); $query->set(array('a =
1', 'b = 2');
Parameters
- $conditions
mixed - $conditions A string or array of string conditions.
- $glue
string - $glue The glue by which to join the condition strings. Defaults to ,. Note that
the glue is set on first use and cannot be changed.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
setQuery( mixed $sql )
Allows a direct query to be provided to the database driver's setQuery()
method, but still allow queries to have bounded variables.
Allows a direct query to be provided to the database driver's setQuery()
method, but still allow queries to have bounded variables.
Usage: $query->setQuery('select * from #__users');
Parameters
- $sql
mixed - $sql An SQL Query
Returns
Since
12.1
|
public
JDatabaseQuery
|
#
update( string $table )
Add a table name to the UPDATE clause of the query.
Add a table name to the UPDATE clause of the query.
Note that you must not mix insert, update, delete and select method calls
when building a query.
Usage: $query->update('#__foo')->set(...);
Parameters
- $table
string - $table A table to update.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
values( string $values )
Adds a tuple, or array of tuples that would be used as values for an INSERT
INTO statement.
Adds a tuple, or array of tuples that would be used as values for an INSERT
INTO statement.
Usage: $query->values('1,2,3')->values('4,5,6');
$query->values(array('1,2,3', '4,5,6'));
Parameters
- $values
string - $values A single tuple, or array of tuples.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
where( mixed $conditions, string $glue = 'AND' )
Add a single condition, or an array of conditions to the WHERE clause of the
query.
Add a single condition, or an array of conditions to the WHERE clause of the
query.
Usage: $query->where('a = 1')->where('b = 2');
$query->where(array('a = 1', 'b = 2'));
Parameters
- $conditions
mixed - $conditions A string or array of where conditions.
- $glue
string - $glue The glue by which to join the conditions. Defaults to AND. Note that the
glue is set on first use and cannot be changed.
Returns
Since
11.1
|
public
JDatabaseQuery
|
#
extendWhere( string $outerGlue, mixed $conditions, string $innerGlue = 'AND' )
Extend the WHERE clause with a single condition or an array of conditions,
with a potentially different logical operator from the one in the current WHERE
clause.
Extend the WHERE clause with a single condition or an array of conditions,
with a potentially different logical operator from the one in the current WHERE
clause.
Usage: $query->where(array('a = 1', 'b = 2'))->extendWhere('XOR',
array('c = 3', 'd = 4')); will produce: WHERE ((a = 1 AND b = 2) XOR (c = 3 AND
d = 4)
Parameters
- $outerGlue
string - $outerGlue The glue by which to join the conditions to the current WHERE
conditions.
- $conditions
mixed - $conditions A string or array of WHERE conditions.
- $innerGlue
string - $innerGlue The glue by which to join the conditions. Defaults to AND.
Returns
Since
3.6
|
public
JDatabaseQuery
|
#
orWhere( mixed $conditions, string $glue = 'AND' )
Extend the WHERE clause with an OR and a single condition or an array of
conditions.
Extend the WHERE clause with an OR and a single condition or an array of
conditions.
Usage: $query->where(array('a = 1', 'b = 2'))->orWhere(array('c = 3',
'd = 4')); will produce: WHERE ((a = 1 AND b = 2) OR (c = 3 AND d = 4)
Parameters
- $conditions
mixed - $conditions A string or array of WHERE conditions.
- $glue
string - $glue The glue by which to join the conditions. Defaults to AND.
Returns
Since
3.6
|
public
JDatabaseQuery
|
#
andWhere( mixed $conditions, string $glue = 'OR' )
Extend the WHERE clause with an AND and a single condition or an array of
conditions.
Extend the WHERE clause with an AND and a single condition or an array of
conditions.
Usage: $query->where(array('a = 1', 'b = 2'))->andWhere(array('c = 3',
'd = 4')); will produce: WHERE ((a = 1 AND b = 2) AND (c = 3 OR d = 4)
Parameters
- $conditions
mixed - $conditions A string or array of WHERE conditions.
- $glue
string - $glue The glue by which to join the conditions. Defaults to OR.
Returns
Since
3.6
|
public
|
#
__clone( )
Method to provide deep copy support to nested objects and arrays when
cloning.
Method to provide deep copy support to nested objects and arrays when
cloning.
Since
11.3
|
public
JDatabaseQuery
|
#
union( mixed $query, boolean $distinct = false, string $glue = '' )
Add a query to UNION with the current query. Multiple unions each require
separate statements and create an array of unions.
Add a query to UNION with the current query. Multiple unions each require
separate statements and create an array of unions.
Usage (the $query base query MUST be a select query):
$query->union('SELECT name FROM #__foo') $query->union('SELECT name FROM
#__foo', true) $query->union(array('SELECT name FROM #__foo','SELECT name
FROM #__bar')) $query->union($query2)->union($query3)
$query->union(array($query2, $query3))
Parameters
- $query
mixed - $query The JDatabaseQuery object or string to union.
- $distinct
boolean - $distinct True to only return distinct rows from the union.
- $glue
string - $glue The glue by which to join the conditions.
Returns
Since
12.1
Link
|
public
JDatabaseQuery
|
#
unionDistinct( mixed $query, string $glue = '' )
Add a query to UNION DISTINCT with the current query. Simply a proxy to union
with the DISTINCT keyword.
Add a query to UNION DISTINCT with the current query. Simply a proxy to union
with the DISTINCT keyword.
Usage: $query->unionDistinct('SELECT name FROM #__foo')
Parameters
- $query
mixed - $query The JDatabaseQuery object or string to union.
- $glue
string - $glue The glue by which to join the conditions.
Returns
Since
12.1
See
|
public
string
|
#
format( string $format )
Find and replace sprintf-like tokens in a format string. Each token takes one
of the following forms:
%% - A literal percent character.
%[t] - Where [t] is a type specifier.
%[n]$[x] - Where [n] is an argument specifier and [t] is a type specifier.
Find and replace sprintf-like tokens in a format string. Each token takes one
of the following forms: %% - A literal percent character. %[t] - Where [t] is a
type specifier. %[n]$[x] - Where [n] is an argument specifier and [t] is a type
specifier.
Types: a - Numeric: Replacement text is coerced to a numeric type but not
quoted or escaped. e - Escape: Replacement text is passed to $this->escape().
E - Escape (extra): Replacement text is passed to $this->escape() with true
as the second argument. n - Name Quote: Replacement text is passed to
$this->quoteName(). q - Quote: Replacement text is passed to
$this->quote(). Q - Quote (no escape): Replacement text is passed to
$this->quote() with false as the second argument. r - Raw: Replacement text
is used as-is. (Be careful)
Date Types:
- Replacement text automatically quoted (use uppercase for Name Quote).
- Replacement text should be a string in date format or name of a date
column.
y/Y - Year m/M - Month d/D - Day h/H - Hour i/I - Minute s/S - Second
Invariable Types:
- Takes no argument.
- Argument index not incremented.
t - Replacement text is the result of $this->currentTimestamp(). z -
Replacement text is the result of $this->nullDate(false). Z - Replacement
text is the result of $this->nullDate(true).
Usage: $query->format('SELECT %1$n FROM %2$n WHERE %3$n = %4$a', 'foo',
'#__foo', 'bar', 1); Returns: SELECT foo FROM #__foo
WHERE bar = 1
Notes: The argument specifier is optional but recommended for clarity. The
argument index used for unspecified tokens is incremented only when used.
Parameters
- $format
string - $format The formatting string.
Returns
string - Returns a string produced according to the formatting string.
Since
12.3
|
public
string
|
#
dateAdd( mixed $date, string $interval, string $datePart )
Add to the current date and time. Usage:
$query->select($query->dateAdd()); Prefixing the interval with a -
(negative sign) will cause subtraction to be used. Note: Not all drivers support
all units.
Add to the current date and time. Usage:
$query->select($query->dateAdd()); Prefixing the interval with a -
(negative sign) will cause subtraction to be used. Note: Not all drivers support
all units.
Parameters
- $date
mixed - $date The date to add to. May be date or datetime
- $interval
string - $interval The string representation of the appropriate number of units
- $datePart
string - $datePart The part of the date to perform the addition on
Returns
string - The string with the appropriate sql for addition of dates
Since
13.1
Link
|
public
JDatabaseQuery
|
#
unionAll( mixed $query, boolean $distinct = false, string $glue = '' )
Add a query to UNION ALL with the current query. Multiple unions each require
separate statements and create an array of unions.
Add a query to UNION ALL with the current query. Multiple unions each require
separate statements and create an array of unions.
Usage: $query->union('SELECT name FROM #__foo')
$query->union(array('SELECT name FROM #__foo','SELECT name FROM #__bar'))
Parameters
- $query
mixed - $query The JDatabaseQuery object or string to union.
- $distinct
boolean - $distinct Not used - ignored.
- $glue
string - $glue Not used - ignored.
Returns
Since
13.1
See
|
protected
|
#
validateRowNumber( string $orderBy, string $orderColumnAlias )
Validate arguments which are passed to selectRowNumber method and set up
common variables.
Validate arguments which are passed to selectRowNumber method and set up
common variables.
Parameters
- $orderBy
string - $orderBy An expression of ordering for window function.
- $orderColumnAlias
string - $orderColumnAlias An alias for new ordering column.
Throws
Since
3.7.0
|
public
JDatabaseQuery
|
#
selectRowNumber( string $orderBy, string $orderColumnAlias )
Return the number of the current row.
Return the number of the current row.
Usage: $query->select('id');
$query->selectRowNumber('ordering,publish_up DESC', 'new_ordering');
$query->from('#__content');
Parameters
- $orderBy
string - $orderBy An expression of ordering for window function.
- $orderColumnAlias
string - $orderColumnAlias An alias for new ordering column.
Returns
Throws
Since
3.7.0
|