Query Building Class.
Located in /libraries/joomla/database/query.php (line 148)
Class | Description |
---|---|
![]() |
Query Building Class. |
![]() |
PDO Query Building Class. |
![]() |
Query Building Class. |
![]() |
Query Building Class. |
Class constructor.
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'));
Casts a value to a char.
Ensure that the value is properly quoted before passing to the method.
Usage: $query->select($query->castAsChar('a'));
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'));
Clear data from the query or a specific clause of the query.
Adds a column, or array of column names that would be used for an INSERT INTO statement.
Concatenates an array of column names or values.
Usage: $query->select($query->concatenate(array('a', 'b')));
Gets the current date and time.
Usage: $query->where('published_up < '.$query->currentTimestamp());
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.
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.
Used to get a string to extract day from date column.
Usage: $query->select($query->day($query->quoteName('dateColumn')));
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');
Creates a formatted dump of the query for debugging purposes.
Usage: echo $query->dump();
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.
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'));
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:
Invariable Types:
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.
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');
Add a grouping column to the GROUP clause of the query.
Usage: $query->group('id');
A conditions to the HAVING clause of the query.
Usage: $query->group('id')->having('COUNT(id) > 5');
Used to get a string to extract hour from date column.
Usage: $query->select($query->hour($query->quoteName('dateColumn')));
Add an INNER JOIN clause to the query.
Usage: $query->innerJoin('b ON b.id = a.id')->innerJoin('c ON c.id = b.id');
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'));
Add a JOIN clause to the query.
Usage: $query->join('INNER', 'b ON b.id = a.id);
Add a LEFT JOIN clause to the query.
Usage: $query->leftJoin('b ON b.id = a.id')->leftJoin('c ON c.id = b.id');
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');
Used to get a string to extract minute from date column.
Usage: $query->select($query->minute($query->quoteName('dateColumn')));
Used to get a string to extract month from date column.
Usage: $query->select($query->month($query->quoteName('dateColumn')));
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());
Add a ordering column to the ORDER clause of the query.
Usage: $query->order('foo')->order('bar'); $query->order(array('foo','bar'));
Add an OUTER JOIN clause to the query.
Usage: $query->outerJoin('b ON b.id = a.id')->outerJoin('c ON c.id = b.id');
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'));
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');
Add a RIGHT JOIN clause to the query.
Usage: $query->rightJoin('b ON b.id = a.id')->rightJoin('c ON c.id = b.id');
Used to get a string to extract seconds from date column.
Usage: $query->select($query->second($query->quoteName('dateColumn')));
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'));
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');
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');
Add a query to UNION 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('SELECT name FROM #__foo','distinct') $query->union(array('SELECT name FROM #__foo','SELECT name FROM #__bar'))
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('SELECT name FROM #__foo','distinct') $query->union(array('SELECT name FROM #__foo','SELECT name FROM #__bar'))
Add a query to UNION DISTINCT with the current query. Simply a proxy to Union with the Distinct clause.
Usage: $query->unionDistinct('SELECT name FROM #__foo')
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(...);
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'));
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'));
Used to get a string to extract year from date column.
Usage: $query->select($query->year($query->quoteName('dateColumn')));
Magic method to provide method alias support for quote() and quoteName().
Method to provide deep copy support to nested objects and arrays when cloning.
Magic function to get protected variable value
Magic function to convert the query to a string.
Documentation generated on Tue, 19 Nov 2013 15:11:32 +0100 by phpDocumentor 1.4.3