mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Moved deprecation of SQLQuery to 4.0
This commit is contained in:
parent
2aa1c1e11e
commit
19549d620f
@ -1819,7 +1819,7 @@ class LeftAndMainMarkingFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SQLSelect(
|
return new SQLQuery(
|
||||||
array("ParentID", "ID"),
|
array("ParentID", "ID"),
|
||||||
'SiteTree',
|
'SiteTree',
|
||||||
$where
|
$where
|
||||||
|
@ -144,9 +144,9 @@ class PaginatedList extends SS_ListDecorator {
|
|||||||
* Sets the page length, page start and total items from a query object's
|
* Sets the page length, page start and total items from a query object's
|
||||||
* limit, offset and unlimited count. The query MUST have a limit clause.
|
* limit, offset and unlimited count. The query MUST have a limit clause.
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query
|
* @param SQLQuery $query
|
||||||
*/
|
*/
|
||||||
public function setPaginationFromQuery(SQLSelect $query) {
|
public function setPaginationFromQuery(SQLQuery $query) {
|
||||||
if ($limit = $query->getLimit()) {
|
if ($limit = $query->getLimit()) {
|
||||||
$this->setPageLength($limit['limit']);
|
$this->setPageLength($limit['limit']);
|
||||||
$this->setPageStart($limit['start']);
|
$this->setPageStart($limit['start']);
|
||||||
|
@ -132,7 +132,7 @@ To set it back to be non-HTTP only, you need to set the `$httpOnly` argument to
|
|||||||
* Implementation of a parameterised query framework eliminating the need to manually escape variables for
|
* Implementation of a parameterised query framework eliminating the need to manually escape variables for
|
||||||
use in SQL queries. This has been integrated into nearly every level of the database ORM.
|
use in SQL queries. This has been integrated into nearly every level of the database ORM.
|
||||||
* Refactor of database connectivity classes into separate components linked together through dependency injection
|
* Refactor of database connectivity classes into separate components linked together through dependency injection
|
||||||
* Refactor of `SQLQuery` into separate objects for each query type: `SQLSelect`, `SQLDelete`, `SQLUpdate` and `SQLInsert`
|
* Refactor of `SQLQuery` into separate objects for each query type: `SQLQuery`, `SQLDelete`, `SQLUpdate` and `SQLInsert`
|
||||||
* Rename of API methods to conform to coding conventions
|
* Rename of API methods to conform to coding conventions
|
||||||
* PDO is now a standard connector, and is available for all database interfaces
|
* PDO is now a standard connector, and is available for all database interfaces
|
||||||
* Additional database and query generation tools
|
* Additional database and query generation tools
|
||||||
@ -156,18 +156,18 @@ To set it back to be non-HTTP only, you need to set the `$httpOnly` argument to
|
|||||||
|
|
||||||
### Update code that uses SQLQuery
|
### Update code that uses SQLQuery
|
||||||
|
|
||||||
SQLQuery is still implemented, but now extends the new SQLSelect class and has some methods
|
SQLQuery has been changed. Previously this class was used for both selecting and deleting, but
|
||||||
deprecated. Previously this class was used for both selecting and deleting, but these
|
deletion is now handled by the new SQLDelete class.
|
||||||
have been superceded by the specialised SQLSelect and SQLDelete classes. Additionally,
|
|
||||||
3.2 now provides SQLUpdate and SQLInsert to generate parameterised query friendly
|
Additionally, 3.2 now provides SQLUpdate and SQLInsert to generate parameterised query friendly
|
||||||
data updates.
|
data updates.
|
||||||
|
|
||||||
SQLSelect, SQLDelete and SQLUpdate all inherit from SQLConditionalExpression, which
|
SQLQuery, SQLDelete and SQLUpdate all inherit from SQLConditionalExpression, which
|
||||||
implements toSelect, toDelete, and toUpdate to generate basic transformations
|
implements toSelect, toDelete, and toUpdate to generate basic transformations
|
||||||
between query types.
|
between query types.
|
||||||
|
|
||||||
In the past SQLQuery->setDelete(true) would be used to turn a select into a delete,
|
In the past SQLQuery->setDelete(true) would be used to turn a select into a delete,
|
||||||
although now a new SQLDelete object should be created from a separate SQLSelect.
|
although now a new SQLDelete object should be created from the original SQLQuery.
|
||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
@ -192,24 +192,18 @@ Alternatively:
|
|||||||
|
|
||||||
:::php
|
:::php
|
||||||
<?php
|
<?php
|
||||||
$query = SQLSelect::create()
|
$query = SQLQuery::create()
|
||||||
->setFrom('"SiteTree"')
|
->setFrom('"SiteTree"')
|
||||||
->setWhere(array('"SiteTree"."ShowInMenus"' => 0))
|
->setWhere(array('"SiteTree"."ShowInMenus"' => 0))
|
||||||
->toDelete();
|
->toDelete();
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
Also, take care for any code or functions which expect an object of type `SQLQuery`, as
|
|
||||||
these references should be replaced with `SQLSelect`. Legacy code which generates
|
|
||||||
`SQLQuery` can still communicate with new code that expects `SQLSelect` as it is a
|
|
||||||
subclass of `SQLSelect`, but the inverse is not true.
|
|
||||||
|
|
||||||
### Update code that interacts with SQL strings to use parameters
|
### Update code that interacts with SQL strings to use parameters
|
||||||
|
|
||||||
The Silverstripe ORM (object relation model) has moved from using escaped SQL strings
|
The Silverstripe ORM (object relation model) has moved from using escaped SQL strings
|
||||||
to query the database, to a combination of parameterised SQL expressions alongside
|
to query the database, to a combination of parameterised SQL expressions alongside
|
||||||
a related list of parameter values. As a result of this, it is necessary to assume
|
a related list of parameter values. As a result of this, it is necessary to assume
|
||||||
that any `SQLSelect` object (previously `SQLQuery`) may, and will usually, have
|
that any `SQLQuery` object may, and will usually, have un-injected parameters.
|
||||||
un-injected parameters.
|
|
||||||
|
|
||||||
All database queries performed through `DataList`, `DataQuery` and `SQLQuery` will continue
|
All database queries performed through `DataList`, `DataQuery` and `SQLQuery` will continue
|
||||||
to work, as will those through `DataObject::get()` (which returns a filterable `DataList`).
|
to work, as will those through `DataObject::get()` (which returns a filterable `DataList`).
|
||||||
@ -250,49 +244,7 @@ Examples of areas where queries should be upgraded are below:
|
|||||||
array($parentTitle)
|
array($parentTitle)
|
||||||
);
|
);
|
||||||
|
|
||||||
2. #### Querying the database through `SQLQuery` (deprecated)
|
2. #### Querying the database through `DataList`, `DataQuery`, `SQLQuery`, and `DataObject`
|
||||||
|
|
||||||
Before:
|
|
||||||
|
|
||||||
Note: Use of SQLQuery would generate a deprecation notice if left un-upgraded.
|
|
||||||
|
|
||||||
:::php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$query = new SQLQuery('*', '"SiteTree"', "\"URLSegment\" = '".Convert::raw2sql($testURL)."'");
|
|
||||||
|
|
||||||
$query->addWhere(array(
|
|
||||||
'"ParentID" = \''.intval($parentID).'\'',
|
|
||||||
'"ID" IN (SELECT "PageID" FROM "MyObject")'
|
|
||||||
));
|
|
||||||
|
|
||||||
$query->addWhere("\"Title\" LIKE '%".Convert::raw2sql($myText)."' OR \"Title\" LIKE '".Convert::raw2sql($myText)."%'");
|
|
||||||
|
|
||||||
After, substituting `SQLSelect` for the deprecated `SQLQuery`:
|
|
||||||
|
|
||||||
Note: The inclusion of properly ANSI quoted symbols with the table name included,
|
|
||||||
as per best coding practices.
|
|
||||||
|
|
||||||
:::php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$query = SQLSelect::create('*', '"SiteTree"', array('"SiteTree"."URLSegment" = ?' => $testURL));
|
|
||||||
|
|
||||||
$query->addWhere(array(
|
|
||||||
'"SiteTree"."ParentID"' => // Note that the " = ?" is optional for simple comparison
|
|
||||||
array( // Syntax for parameter casting for supporting databases
|
|
||||||
'value' => $parentID,
|
|
||||||
'type' => 'integer'
|
|
||||||
),
|
|
||||||
'"SiteTree"."ID" IN (SELECT "MyObject"."PageID" FROM "MyObject")' // Raw SQL condition with no parameters
|
|
||||||
));
|
|
||||||
|
|
||||||
// Multiple parameters may be assigned for a single query (this should not be associative)
|
|
||||||
$query->addWhere(array(
|
|
||||||
'"SiteTree"."Title" LIKE %? OR "SiteTree"."Title" LIKE %?' => array($myText, $myText)
|
|
||||||
));
|
|
||||||
|
|
||||||
3. #### Querying the database through `DataList`, `DataQuery`, and `DataObject`
|
|
||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
@ -318,10 +270,10 @@ Examples of areas where queries should be upgraded are below:
|
|||||||
'"Title" = ?', $title
|
'"Title" = ?', $title
|
||||||
);
|
);
|
||||||
|
|
||||||
4. #### Interaction with `DataList::sql()`, `DataQuery::sql()`, `SQLSelect::sql()`, or `SQLSelect::getJoins()` methods
|
3. #### Interaction with `DataList::sql()`, `DataQuery::sql()`, `SQLQuery::sql()`, or `SQLQuery::getJoins()` methods
|
||||||
|
|
||||||
The place where legacy code would almost certainly fail is any code that calls
|
The place where legacy code would almost certainly fail is any code that calls
|
||||||
`SQLQuery::sql`, `DataList::sql`, `DataQuery::sql` or `SQLSelect::getJoins()`, as the api requires that user
|
DataList::sql`, `DataQuery::sql`, `SQLQuery::sql` or `SQLQuery::getJoins()`, as the api requires that user
|
||||||
code passes in an argument here to retrieve SQL parameters by value.
|
code passes in an argument here to retrieve SQL parameters by value.
|
||||||
|
|
||||||
User code that assumes parameterless queries will likely fail, and need to be
|
User code that assumes parameterless queries will likely fail, and need to be
|
||||||
@ -334,7 +286,7 @@ Examples of areas where queries should be upgraded are below:
|
|||||||
|
|
||||||
// Generate query
|
// Generate query
|
||||||
$argument = 'whatever';
|
$argument = 'whatever';
|
||||||
$query = SQLSelect::create()
|
$query = SQLQuery::create()
|
||||||
->setFrom('"SiteTree"')
|
->setFrom('"SiteTree"')
|
||||||
->setWhere(array("\"SiteTree\".\"Title\" LIKE '" . Convert::raw2sql($argument) . "'"));
|
->setWhere(array("\"SiteTree\".\"Title\" LIKE '" . Convert::raw2sql($argument) . "'"));
|
||||||
|
|
||||||
@ -352,7 +304,7 @@ Examples of areas where queries should be upgraded are below:
|
|||||||
|
|
||||||
// Generate query
|
// Generate query
|
||||||
$argument = 'whatever';
|
$argument = 'whatever';
|
||||||
$query = SQLSelect::create()
|
$query = SQLQuery::create()
|
||||||
->setFrom('"SiteTree"')
|
->setFrom('"SiteTree"')
|
||||||
->setWhere(array('"SiteTree"."Title" LIKE ?' => $argument));
|
->setWhere(array('"SiteTree"."Title" LIKE ?' => $argument));
|
||||||
|
|
||||||
@ -381,46 +333,7 @@ Examples of areas where queries should be upgraded are below:
|
|||||||
)
|
)
|
||||||
DB::prepared_query('DELETE FROM "MyObject" WHERE ParentID = ? OR IsValid = ?', $parameters);
|
DB::prepared_query('DELETE FROM "MyObject" WHERE ParentID = ? OR IsValid = ?', $parameters);
|
||||||
|
|
||||||
5. #### Update implementations of augmentSQL
|
4. ### Update code that interacts with the DB schema
|
||||||
|
|
||||||
Since this method now takes a `SQLSelect` as a first parameter, existing code referencing the deprecated `SQLQuery`
|
|
||||||
type will raise a PHP error.
|
|
||||||
|
|
||||||
Furthermore, it's important to note that even though the signature of `SQLSelect::getWhere` is similar to the old
|
|
||||||
`SQLQuery::getWhere` the result will actually be an associative array of SQL fragments mapped to arrays of
|
|
||||||
parameters, and any transformation of these values will require parameters to be maintained.
|
|
||||||
|
|
||||||
If your code doesn't modify the parameters then `SQLSelect::getWhereParameterised` can be used in order to return
|
|
||||||
these SQL statements as a simple array of strings. The resulting parameters are still maintained, but are
|
|
||||||
instead be returned by referenced through the first parameter to this method.
|
|
||||||
|
|
||||||
E.g.
|
|
||||||
|
|
||||||
Before:
|
|
||||||
|
|
||||||
:::php
|
|
||||||
function augmentSQL(SQLQuery $query, DataQuery $dataQuery = null) {
|
|
||||||
$locale = Translatable::get_current_locale();
|
|
||||||
if(!preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere()))) {
|
|
||||||
$qry = sprintf('"Locale" = \'%s\'', Convert::raw2sql($locale));
|
|
||||||
$query->addWhere($qry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
After:
|
|
||||||
|
|
||||||
:::php
|
|
||||||
function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
|
|
||||||
$locale = Translatable::get_current_locale();
|
|
||||||
if(!preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhereParameterised($parameters)))) {
|
|
||||||
$query->addWhere(array(
|
|
||||||
'"Locale"' => $locale
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### Update code that interacts with the DB schema
|
|
||||||
|
|
||||||
Updating database schema is now done by `updateSchema` with a callback, rather than relying
|
Updating database schema is now done by `updateSchema` with a callback, rather than relying
|
||||||
on user code to call `beginSchemaUpdate` and `endSchemaUpdate` around the call.
|
on user code to call `beginSchemaUpdate` and `endSchemaUpdate` around the call.
|
||||||
@ -546,4 +459,4 @@ coding conventions. E.g. `DB::requireTable` is now `DB::require_table`
|
|||||||
* create_table_options now uses constants as API specific filters rather than strings.
|
* create_table_options now uses constants as API specific filters rather than strings.
|
||||||
This is in order to promote better referencing of elements across the codebase.
|
This is in order to promote better referencing of elements across the codebase.
|
||||||
See `FulltextSearchable->enable` for example.
|
See `FulltextSearchable->enable` for example.
|
||||||
* `FormField` subclasses must now use `validate(Validator $validator)` as the interface has changed for this function
|
* `FormField` subclasses must now use `validate(Validator $validator)` as the interface has changed for this function
|
||||||
|
52
docs/en/changelogs/4.0.0.md
Normal file
52
docs/en/changelogs/4.0.0.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# 4.0.0 (unreleased)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
### Framework
|
||||||
|
|
||||||
|
* Deprecate `SQLQuery` in favour `SQLSelect`
|
||||||
|
|
||||||
|
## Upgrading
|
||||||
|
|
||||||
|
### Update code that uses SQLQuery
|
||||||
|
|
||||||
|
SQLQuery is still implemented, but now extends the new SQLSelect class and has some methods
|
||||||
|
deprecated. Previously this class was used for both selecting and deleting, but these
|
||||||
|
have been superceded by the specialised SQLSelect and SQLDelete classes.
|
||||||
|
|
||||||
|
Take care for any code or functions which expect an object of type `SQLQuery`, as
|
||||||
|
these references should be replaced with `SQLSelect`. Legacy code which generates
|
||||||
|
`SQLQuery` can still communicate with new code that expects `SQLSelect` as it is a
|
||||||
|
subclass of `SQLSelect`, but the inverse is not true.
|
||||||
|
|
||||||
|
### Update implementations of augmentSQL
|
||||||
|
|
||||||
|
Since this method now takes a `SQLSelect` as a first parameter, existing code referencing the deprecated `SQLQuery`
|
||||||
|
type will raise a PHP error.
|
||||||
|
|
||||||
|
E.g.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
|
||||||
|
$locale = Translatable::get_current_locale();
|
||||||
|
if(!preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere()))) {
|
||||||
|
$qry = sprintf('"Locale" = \'%s\'', Convert::raw2sql($locale));
|
||||||
|
$query->addWhere($qry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
|
||||||
|
$locale = Translatable::get_current_locale();
|
||||||
|
if(!preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhereParameterised($parameters)))) {
|
||||||
|
$query->addWhere(array(
|
||||||
|
'"Locale"' => $locale
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -9,6 +9,8 @@ For information on how to upgrade to newer versions consult the [upgrading](/ins
|
|||||||
|
|
||||||
## Stable Releases
|
## Stable Releases
|
||||||
|
|
||||||
|
* [4.0.0](4.0.0) - Unreleased
|
||||||
|
|
||||||
* [3.2.0](3.2.0) - Unreleased
|
* [3.2.0](3.2.0) - Unreleased
|
||||||
|
|
||||||
* [3.1.8](3.1.8) - 18 November 2014
|
* [3.1.8](3.1.8) - 18 November 2014
|
||||||
|
@ -225,8 +225,8 @@ The other queries that you will want to customise are the selection queries,
|
|||||||
called by get & get_one. For example, the Versioned object has code to redirect
|
called by get & get_one. For example, the Versioned object has code to redirect
|
||||||
every request to ClassName_live, if you are browsing the live site.
|
every request to ClassName_live, if you are browsing the live site.
|
||||||
|
|
||||||
To do this, define the **augmentSQL(SQLSelect $query)** method. Again, the $query object is passed by reference and can
|
To do this, define the **augmentSQL(SQLQuery &$query)** method. Again, the $query object is passed by reference and can
|
||||||
be modified as needed by your method. Instead of a manipulation array, we have a `[api:SQLSelect]` object.
|
be modified as needed by your method. Instead of a manipulation array, we have a `[api:SQLQuery]` object.
|
||||||
|
|
||||||
### Additional methods
|
### Additional methods
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ Reference articles complement our auto-generated [API docs](http://api.silverstr
|
|||||||
* [Site Reports](site-reports): Tabular reports in a specialized CMS interface
|
* [Site Reports](site-reports): Tabular reports in a specialized CMS interface
|
||||||
* [SiteConfig](siteconfig): Global configuration stored in the database
|
* [SiteConfig](siteconfig): Global configuration stored in the database
|
||||||
* [SiteTree](sitetree): Base class for a "page" in the CMS
|
* [SiteTree](sitetree): Base class for a "page" in the CMS
|
||||||
* [SQLSelect](sqlquery): Wrapper around a SQL query allowing modification before execution
|
* [SQLQuery](sqlquery): Wrapper around a SQL query allowing modification before execution
|
||||||
* [StaticPublisher](staticpublisher): Export a page tree as static HTML for better performance and portability
|
* [StaticPublisher](staticpublisher): Export a page tree as static HTML for better performance and portability
|
||||||
* [TableField](tablefield): Add and edit records with inline edits in this form field
|
* [TableField](tablefield): Add and edit records with inline edits in this form field
|
||||||
* [TableListField](tablelistfield): View and delete records in the CMS
|
* [TableListField](tablelistfield): View and delete records in the CMS
|
||||||
|
@ -6,7 +6,7 @@ Manages searching of properties on one or more `[api:DataObject]` types, based o
|
|||||||
`[api:SearchContext]` is intentionally decoupled from any controller-logic,
|
`[api:SearchContext]` is intentionally decoupled from any controller-logic,
|
||||||
it just receives a set of search parameters and an object class it acts on.
|
it just receives a set of search parameters and an object class it acts on.
|
||||||
|
|
||||||
The default output of a `[api:SearchContext]` is either a `[api:SQLSelect]` object for further refinement, or a
|
The default output of a `[api:SearchContext]` is either a `[api:SQLQuery]` object for further refinement, or a
|
||||||
`[api:DataObject]` instance.
|
`[api:DataObject]` instance.
|
||||||
|
|
||||||
In case you need multiple contexts, consider namespacing your request parameters by using `FieldList->namespace()` on
|
In case you need multiple contexts, consider namespacing your request parameters by using `FieldList->namespace()` on
|
||||||
@ -86,7 +86,7 @@ method, we're building our own `getCustomSearchContext()` variant.
|
|||||||
### Pagination
|
### Pagination
|
||||||
|
|
||||||
For pagination records on multiple pages, you need to wrap the results in a
|
For pagination records on multiple pages, you need to wrap the results in a
|
||||||
`PaginatedList` object. This object is also passed the generated `SQLSelect`
|
`PaginatedList` object. This object is also passed the generated `SQLQuery`
|
||||||
in order to read page limit information. It is also passed the current
|
in order to read page limit information. It is also passed the current
|
||||||
`SS_HTTPRequest` object so it can read the current page from a GET var.
|
`SS_HTTPRequest` object so it can read the current page from a GET var.
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# SQL Select
|
# SQLQuery
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ the following three statements are functionally equivalent:
|
|||||||
:::php
|
:::php
|
||||||
// Through raw SQL
|
// Through raw SQL
|
||||||
$count = DB::query('SELECT COUNT(*) FROM "Member"')->value();
|
$count = DB::query('SELECT COUNT(*) FROM "Member"')->value();
|
||||||
// Through SQLSelect abstraction layer
|
// Through SQLQuery abstraction layer
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$count = $query->setFrom('Member')->setSelect('COUNT(*)')->value();
|
$count = $query->setFrom('Member')->setSelect('COUNT(*)')->value();
|
||||||
// Through the ORM
|
// Through the ORM
|
||||||
$count = Member::get()->count();
|
$count = Member::get()->count();
|
||||||
@ -45,7 +45,7 @@ how to properly prepare user input and variables for use in queries
|
|||||||
|
|
||||||
### SELECT
|
### SELECT
|
||||||
|
|
||||||
Selection can be done by creating an instance of `SQLSelect`, which allows
|
Selection can be done by creating an instance of `SQLQuery`, which allows
|
||||||
management of all elements of a SQL SELECT query, including columns, joined tables,
|
management of all elements of a SQL SELECT query, including columns, joined tables,
|
||||||
conditional filters, grouping, limiting, and sorting.
|
conditional filters, grouping, limiting, and sorting.
|
||||||
|
|
||||||
@ -54,36 +54,36 @@ E.g.
|
|||||||
:::php
|
:::php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$sqlSelect = new SQLSelect();
|
$sqlQuery = new SQLQuery();
|
||||||
$sqlSelect->setFrom('Player');
|
$sqlQuery->setFrom('Player');
|
||||||
$sqlSelect->selectField('FieldName', 'Name');
|
$sqlQuery->selectField('FieldName', 'Name');
|
||||||
$sqlSelect->selectField('YEAR("Birthday")', 'Birthyear');
|
$sqlQuery->selectField('YEAR("Birthday")', 'Birthyear');
|
||||||
$sqlSelect->addLeftJoin('Team','"Player"."TeamID" = "Team"."ID"');
|
$sqlQuery->addLeftJoin('Team','"Player"."TeamID" = "Team"."ID"');
|
||||||
$sqlSelect->addWhere(array('YEAR("Birthday") = ?' => 1982));
|
$sqlQuery->addWhere(array('YEAR("Birthday") = ?' => 1982));
|
||||||
// $sqlSelect->setOrderBy(...);
|
// $sqlQuery->setOrderBy(...);
|
||||||
// $sqlSelect->setGroupBy(...);
|
// $sqlQuery->setGroupBy(...);
|
||||||
// $sqlSelect->setHaving(...);
|
// $sqlQuery->setHaving(...);
|
||||||
// $sqlSelect->setLimit(...);
|
// $sqlQuery->setLimit(...);
|
||||||
// $sqlSelect->setDistinct(true);
|
// $sqlQuery->setDistinct(true);
|
||||||
|
|
||||||
// Get the raw SQL (optional) and parameters
|
// Get the raw SQL (optional) and parameters
|
||||||
$rawSQL = $sqlSelect->sql($parameters);
|
$rawSQL = $sqlQuery->sql($parameters);
|
||||||
|
|
||||||
// Execute and return a Query object
|
// Execute and return a Query object
|
||||||
$result = $sqlSelect->execute();
|
$result = $sqlQuery->execute();
|
||||||
|
|
||||||
// Iterate over results
|
// Iterate over results
|
||||||
foreach($result as $row) {
|
foreach($result as $row) {
|
||||||
echo $row['BirthYear'];
|
echo $row['BirthYear'];
|
||||||
}
|
}
|
||||||
|
|
||||||
The result of `SQLSelect::execute()` is an array lightly wrapped in a database-specific subclass of `[api:SS_Query]`.
|
The result of `SQLQuery::execute()` is an array lightly wrapped in a database-specific subclass of `[api:SS_Query]`.
|
||||||
This class implements the *Iterator*-interface, and provides convenience-methods for accessing the data.
|
This class implements the *Iterator*-interface, and provides convenience-methods for accessing the data.
|
||||||
|
|
||||||
### DELETE
|
### DELETE
|
||||||
|
|
||||||
Deletion can be done either by calling `DB::query`/`DB::prepared_query` directly,
|
Deletion can be done either by calling `DB::query`/`DB::prepared_query` directly,
|
||||||
by creating a `SQLDelete` object, or by transforming a `SQLSelect` into a `SQLDelete`
|
by creating a `SQLDelete` object, or by transforming a `SQLQuery` into a `SQLDelete`
|
||||||
object instead.
|
object instead.
|
||||||
|
|
||||||
For example, creating a `SQLDelete` object
|
For example, creating a `SQLDelete` object
|
||||||
@ -96,12 +96,12 @@ For example, creating a `SQLDelete` object
|
|||||||
->setWhere(array('"SiteTree"."ShowInMenus"' => 0));
|
->setWhere(array('"SiteTree"."ShowInMenus"' => 0));
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
Alternatively, turning an existing `SQLSelect` into a delete
|
Alternatively, turning an existing `SQLQuery` into a delete
|
||||||
|
|
||||||
:::php
|
:::php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$query = SQLSelect::create()
|
$query = SQLQuery::create()
|
||||||
->setFrom('"SiteTree"')
|
->setFrom('"SiteTree"')
|
||||||
->setWhere(array('"SiteTree"."ShowInMenus"' => 0))
|
->setWhere(array('"SiteTree"."ShowInMenus"' => 0))
|
||||||
->toDelete();
|
->toDelete();
|
||||||
@ -220,12 +220,12 @@ e.g. when you want a single column rather than a full-blown object representatio
|
|||||||
Example: Get the count from a relationship.
|
Example: Get the count from a relationship.
|
||||||
|
|
||||||
:::php
|
:::php
|
||||||
$sqlSelect = new SQLSelect();
|
$sqlQuery = new SQLQuery();
|
||||||
$sqlSelect->setFrom('Player');
|
$sqlQuery->setFrom('Player');
|
||||||
$sqlSelect->addSelect('COUNT("Player"."ID")');
|
$sqlQuery->addSelect('COUNT("Player"."ID")');
|
||||||
$sqlSelect->addWhere(array('"Team"."ID"' => 99));
|
$sqlQuery->addWhere(array('"Team"."ID"' => 99));
|
||||||
$sqlSelect->addLeftJoin('Team', '"Team"."ID" = "Player"."TeamID"');
|
$sqlQuery->addLeftJoin('Team', '"Team"."ID" = "Player"."TeamID"');
|
||||||
$count = $sqlSelect->execute()->value();
|
$count = $sqlQuery->execute()->value();
|
||||||
|
|
||||||
Note that in the ORM, this call would be executed in an efficient manner as well:
|
Note that in the ORM, this call would be executed in an efficient manner as well:
|
||||||
|
|
||||||
@ -240,14 +240,14 @@ This can be useful for creating dropdowns.
|
|||||||
Example: Show player names with their birth year, but set their birth dates as values.
|
Example: Show player names with their birth year, but set their birth dates as values.
|
||||||
|
|
||||||
:::php
|
:::php
|
||||||
$sqlSelect = new SQLSelect();
|
$sqlQuery = new SQLQuery();
|
||||||
$sqlSelect->setFrom('Player');
|
$sqlQuery->setFrom('Player');
|
||||||
$sqlSelect->setSelect('Birthdate');
|
$sqlQuery->setSelect('Birthdate');
|
||||||
$sqlSelect->selectField('CONCAT("Name", ' - ', YEAR("Birthdate")', 'NameWithBirthyear');
|
$sqlQuery->selectField('CONCAT("Name", ' - ', YEAR("Birthdate")', 'NameWithBirthyear');
|
||||||
$map = $sqlSelect->execute()->map();
|
$map = $sqlQuery->execute()->map();
|
||||||
$field = new DropdownField('Birthdates', 'Birthdates', $map);
|
$field = new DropdownField('Birthdates', 'Birthdates', $map);
|
||||||
|
|
||||||
Note that going through SQLSelect is just necessary here
|
Note that going through SQLQuery is just necessary here
|
||||||
because of the custom SQL value transformation (`YEAR()`).
|
because of the custom SQL value transformation (`YEAR()`).
|
||||||
An alternative approach would be a custom getter in the object definition.
|
An alternative approach would be a custom getter in the object definition.
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ For example:
|
|||||||
:::php
|
:::php
|
||||||
$members = Member::get()->where(array('"FirstName" = ?' => 'Sam'));
|
$members = Member::get()->where(array('"FirstName" = ?' => 'Sam'));
|
||||||
|
|
||||||
If using `SQLSelect` you should use `addWhere`, `setWhere`, `addWhereAny`, or `setWhereAny` to modify the query.
|
If using `SQLQuery` you should use `addWhere`, `setWhere`, `addWhereAny`, or `setWhereAny` to modify the query.
|
||||||
|
|
||||||
Using the parameterised query syntax you can either provide a single variable as a parameter, an array of parameters
|
Using the parameterised query syntax you can either provide a single variable as a parameter, an array of parameters
|
||||||
if the SQL has multiple value placeholders, or simply pass an indexed array of strings for literal SQL.
|
if the SQL has multiple value placeholders, or simply pass an indexed array of strings for literal SQL.
|
||||||
@ -443,7 +443,7 @@ E.g.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = SQLSelect::create()
|
$query = SQLQuery::create()
|
||||||
->setFrom('"MyObject"')
|
->setFrom('"MyObject"')
|
||||||
->setWhere($condition = new RandomCondition());
|
->setWhere($condition = new RandomCondition());
|
||||||
$condition->field = '"Score"';
|
$condition->field = '"Score"';
|
||||||
|
@ -33,7 +33,7 @@ Example:
|
|||||||
$records = DataObject::get_by_id('MyClass', 3);
|
$records = DataObject::get_by_id('MyClass', 3);
|
||||||
$records = DataObject::get_one('MyClass', array('"ID" = ?' => 3));
|
$records = DataObject::get_one('MyClass', array('"ID" = ?' => 3));
|
||||||
$records = MyClass::get()->byID(3);
|
$records = MyClass::get()->byID(3);
|
||||||
$records = SQLSelect::create()->addWhere(array('"ID"' => 3))->execute();
|
$records = SQLQuery::create()->addWhere(array('"ID"' => 3))->execute();
|
||||||
|
|
||||||
Parameterised updates and inserts are also supported, but the syntax is a little different
|
Parameterised updates and inserts are also supported, but the syntax is a little different
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ As a rule of thumb, whenever you're creating SQL queries (or just chunks of SQL)
|
|||||||
but there may be cases where you need to take care of escaping yourself. See [coding-conventions](/misc/coding-conventions)
|
but there may be cases where you need to take care of escaping yourself. See [coding-conventions](/misc/coding-conventions)
|
||||||
and [datamodel](/topics/datamodel) for ways to parameterise, cast, and convert your data.
|
and [datamodel](/topics/datamodel) for ways to parameterise, cast, and convert your data.
|
||||||
|
|
||||||
* `SQLSelect`
|
* `SQLQuery`
|
||||||
* `DB::query()`
|
* `DB::query()`
|
||||||
* `DB::preparedQuery()`
|
* `DB::preparedQuery()`
|
||||||
* `Director::urlParams()`
|
* `Director::urlParams()`
|
||||||
|
@ -23,9 +23,9 @@ abstract class DataExtension extends Extension {
|
|||||||
/**
|
/**
|
||||||
* Edit the given query object to support queries for this extension
|
* Edit the given query object to support queries for this extension
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query Query to augment.
|
* @param SQLQuery $query Query to augment.
|
||||||
*/
|
*/
|
||||||
public function augmentSQL(SQLSelect $query) {
|
public function augmentSQL(SQLQuery &$query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,12 +182,6 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
* @param string The resulting SQL query (may be paramaterised)
|
* @param string The resulting SQL query (may be paramaterised)
|
||||||
*/
|
*/
|
||||||
public function sql(&$parameters = array()) {
|
public function sql(&$parameters = array()) {
|
||||||
if(func_num_args() == 0) {
|
|
||||||
Deprecation::notice(
|
|
||||||
'3.2',
|
|
||||||
'DataList::sql() now may produce parameters which are necessary to execute this query'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $this->dataQuery->query()->sql($parameters);
|
return $this->dataQuery->query()->sql($parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,8 +189,8 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
* Return a new DataList instance with a WHERE clause added to this list's query.
|
* Return a new DataList instance with a WHERE clause added to this list's query.
|
||||||
*
|
*
|
||||||
* Supports parameterised queries.
|
* Supports parameterised queries.
|
||||||
* See SQLSelect::addWhere() for syntax examples, although DataList
|
* See SQLQuery::addWhere() for syntax examples, although DataList
|
||||||
* won't expand multiple method arguments as SQLSelect does.
|
* won't expand multiple method arguments as SQLQuery does.
|
||||||
*
|
*
|
||||||
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
||||||
* paramaterised queries
|
* paramaterised queries
|
||||||
@ -213,8 +207,8 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
* All conditions provided in the filter will be joined with an OR
|
* All conditions provided in the filter will be joined with an OR
|
||||||
*
|
*
|
||||||
* Supports parameterised queries.
|
* Supports parameterised queries.
|
||||||
* See SQLSelect::addWhere() for syntax examples, although DataList
|
* See SQLQuery::addWhere() for syntax examples, although DataList
|
||||||
* won't expand multiple method arguments as SQLSelect does.
|
* won't expand multiple method arguments as SQLQuery does.
|
||||||
*
|
*
|
||||||
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
||||||
* paramaterised queries
|
* paramaterised queries
|
||||||
@ -279,7 +273,7 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
* order set.
|
* order set.
|
||||||
*
|
*
|
||||||
* @see SS_List::sort()
|
* @see SS_List::sort()
|
||||||
* @see SQLSelect::orderby
|
* @see SQLQuery::orderby
|
||||||
* @example $list = $list->sort('Name'); // default ASC sorting
|
* @example $list = $list->sort('Name'); // default ASC sorting
|
||||||
* @example $list = $list->sort('Name DESC'); // DESC sorting
|
* @example $list = $list->sort('Name DESC'); // DESC sorting
|
||||||
* @example $list = $list->sort('Name', 'ASC');
|
* @example $list = $list->sort('Name', 'ASC');
|
||||||
|
@ -2637,7 +2637,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$groupList = implode(', ', $groups->column("ID"));
|
$groupList = implode(', ', $groups->column("ID"));
|
||||||
|
|
||||||
// TODO Fix relation table hardcoding
|
// TODO Fix relation table hardcoding
|
||||||
$query = new SQLSelect(
|
$query = new SQLQuery(
|
||||||
"\"Page_Can$perm\".PageID",
|
"\"Page_Can$perm\".PageID",
|
||||||
array("\"Page_Can$perm\""),
|
array("\"Page_Can$perm\""),
|
||||||
"GroupID IN ($groupList)");
|
"GroupID IN ($groupList)");
|
||||||
@ -2646,7 +2646,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
|
|
||||||
if($perm == "View") {
|
if($perm == "View") {
|
||||||
// TODO Fix relation table hardcoding
|
// TODO Fix relation table hardcoding
|
||||||
$query = new SQLSelect("\"SiteTree\".\"ID\"", array(
|
$query = new SQLQuery("\"SiteTree\".\"ID\"", array(
|
||||||
"\"SiteTree\"",
|
"\"SiteTree\"",
|
||||||
"LEFT JOIN \"Page_CanView\" ON \"Page_CanView\".\"PageID\" = \"SiteTree\".\"ID\""
|
"LEFT JOIN \"Page_CanView\" ON \"Page_CanView\".\"PageID\" = \"SiteTree\".\"ID\""
|
||||||
), "\"Page_CanView\".\"PageID\" IS NULL");
|
), "\"Page_CanView\".\"PageID\" IS NULL");
|
||||||
@ -2927,7 +2927,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
*
|
*
|
||||||
* @param string $callerClass The class of objects to be returned
|
* @param string $callerClass The class of objects to be returned
|
||||||
* @param string|array $filter A filter to be inserted into the WHERE clause.
|
* @param string|array $filter A filter to be inserted into the WHERE clause.
|
||||||
* Supports parameterised queries. See SQLSelect::addWhere() for syntax examples.
|
* Supports parameterised queries. See SQLQuery::addWhere() for syntax examples.
|
||||||
* @param string|array $sort A sort expression to be inserted into the ORDER
|
* @param string|array $sort A sort expression to be inserted into the ORDER
|
||||||
* BY clause. If omitted, self::$default_sort will be used.
|
* BY clause. If omitted, self::$default_sort will be used.
|
||||||
* @param string $join Deprecated 3.0 Join clause. Use leftJoin($table, $joinClause) instead.
|
* @param string $join Deprecated 3.0 Join clause. Use leftJoin($table, $joinClause) instead.
|
||||||
@ -2982,7 +2982,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
*
|
*
|
||||||
* @param string $callerClass The class of objects to be returned
|
* @param string $callerClass The class of objects to be returned
|
||||||
* @param string|array $filter A filter to be inserted into the WHERE clause.
|
* @param string|array $filter A filter to be inserted into the WHERE clause.
|
||||||
* Supports parameterised queries. See SQLSelect::addWhere() for syntax examples.
|
* Supports parameterised queries. See SQLQuery::addWhere() for syntax examples.
|
||||||
* @param boolean $cache Use caching
|
* @param boolean $cache Use caching
|
||||||
* @param string $orderby A sort expression to be inserted into the ORDER BY clause.
|
* @param string $orderby A sort expression to be inserted into the ORDER BY clause.
|
||||||
*
|
*
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An object representing a query of data from the DataObject's supporting database.
|
* An object representing a query of data from the DataObject's supporting database.
|
||||||
* Acts as a wrapper over {@link SQLSelect} and performs all of the query generation.
|
* Acts as a wrapper over {@link SQLQuery} and performs all of the query generation.
|
||||||
* Used extensively by {@link DataList}.
|
* Used extensively by {@link DataList}.
|
||||||
*
|
*
|
||||||
* Unlike DataList, modifiers on DataQuery modify the object rather than returning a clone.
|
* Unlike DataList, modifiers on DataQuery modify the object rather than returning a clone.
|
||||||
@ -19,7 +19,7 @@ class DataQuery {
|
|||||||
protected $dataClass;
|
protected $dataClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var SQLSelect
|
* @var SQLQuery
|
||||||
*/
|
*/
|
||||||
protected $query;
|
protected $query;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class DataQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link SQLSelect} object that represents the current query; note that it will
|
* Return the {@link SQLQuery} object that represents the current query; note that it will
|
||||||
* be a clone of the object.
|
* be a clone of the object.
|
||||||
*/
|
*/
|
||||||
public function query() {
|
public function query() {
|
||||||
@ -103,7 +103,7 @@ class DataQuery {
|
|||||||
// As each condition is a single length array, do a single
|
// As each condition is a single length array, do a single
|
||||||
// iteration to extract the predicate and parameters
|
// iteration to extract the predicate and parameters
|
||||||
foreach($condition as $predicate => $parameters) {
|
foreach($condition as $predicate => $parameters) {
|
||||||
// @see SQLSelect::addWhere for why this is required here
|
// @see SQLQuery::addWhere for why this is required here
|
||||||
if(strpos($predicate, $fieldExpression) !== false) {
|
if(strpos($predicate, $fieldExpression) !== false) {
|
||||||
unset($where[$i]);
|
unset($where[$i]);
|
||||||
$matched = true;
|
$matched = true;
|
||||||
@ -146,7 +146,7 @@ class DataQuery {
|
|||||||
$baseClass = array_shift($tableClasses);
|
$baseClass = array_shift($tableClasses);
|
||||||
|
|
||||||
// Build our intial query
|
// Build our intial query
|
||||||
$this->query = new SQLSelect(array());
|
$this->query = new SQLQuery(array());
|
||||||
$this->query->setDistinct(true);
|
$this->query->setDistinct(true);
|
||||||
|
|
||||||
if($sort = singleton($this->dataClass)->stat('default_sort')) {
|
if($sort = singleton($this->dataClass)->stat('default_sort')) {
|
||||||
@ -167,7 +167,7 @@ class DataQuery {
|
|||||||
* Ensure that the query is ready to execute.
|
* Ensure that the query is ready to execute.
|
||||||
*
|
*
|
||||||
* @param array|null $queriedColumns Any columns to filter the query by
|
* @param array|null $queriedColumns Any columns to filter the query by
|
||||||
* @return SQLSelect The finalised sql query
|
* @return SQLQuery The finalised sql query
|
||||||
*/
|
*/
|
||||||
public function getFinalisedQuery($queriedColumns = null) {
|
public function getFinalisedQuery($queriedColumns = null) {
|
||||||
if(!$queriedColumns) $queriedColumns = $this->queriedColumns;
|
if(!$queriedColumns) $queriedColumns = $this->queriedColumns;
|
||||||
@ -279,7 +279,7 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Ensure that if a query has an order by clause, those columns are present in the select.
|
* Ensure that if a query has an order by clause, those columns are present in the select.
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query
|
* @param SQLQuery $query
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array()) {
|
protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array()) {
|
||||||
@ -322,7 +322,7 @@ class DataQuery {
|
|||||||
// add new columns sort
|
// add new columns sort
|
||||||
$newOrderby[$qualCol] = $dir;
|
$newOrderby[$qualCol] = $dir;
|
||||||
|
|
||||||
// To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()
|
// To-do: Remove this if block once SQLQuery::$select has been refactored to store getSelect()
|
||||||
// format internally; then this check can be part of selectField()
|
// format internally; then this check can be part of selectField()
|
||||||
$selects = $query->getSelect();
|
$selects = $query->getSelect();
|
||||||
if(!isset($selects[$col]) && !in_array($qualCol, $selects)) {
|
if(!isset($selects[$col]) && !in_array($qualCol, $selects)) {
|
||||||
@ -361,12 +361,6 @@ class DataQuery {
|
|||||||
* @return string The resulting SQL query (may be paramaterised)
|
* @return string The resulting SQL query (may be paramaterised)
|
||||||
*/
|
*/
|
||||||
public function sql(&$parameters = array()) {
|
public function sql(&$parameters = array()) {
|
||||||
if(func_num_args() == 0) {
|
|
||||||
Deprecation::notice(
|
|
||||||
'3.2',
|
|
||||||
'DataQuery::sql() now may produce parameters which are necessary to execute this query'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $this->getFinalisedQuery()->sql($parameters);
|
return $this->getFinalisedQuery()->sql($parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +439,7 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Update the SELECT clause of the query with the columns from the given table
|
* Update the SELECT clause of the query with the columns from the given table
|
||||||
*/
|
*/
|
||||||
protected function selectColumnsFromTable(SQLSelect &$query, $tableClass, $columns = null) {
|
protected function selectColumnsFromTable(SQLQuery &$query, $tableClass, $columns = null) {
|
||||||
// Add SQL for multi-value fields
|
// Add SQL for multi-value fields
|
||||||
$databaseFields = DataObject::database_fields($tableClass, false);
|
$databaseFields = DataObject::database_fields($tableClass, false);
|
||||||
$compositeFields = DataObject::composite_fields($tableClass, false);
|
$compositeFields = DataObject::composite_fields($tableClass, false);
|
||||||
@ -514,8 +508,8 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Adds a WHERE clause.
|
* Adds a WHERE clause.
|
||||||
*
|
*
|
||||||
* @see SQLSelect::addWhere() for syntax examples, although DataQuery
|
* @see SQLQuery::addWhere() for syntax examples, although DataQuery
|
||||||
* won't expand multiple arguments as SQLSelect does.
|
* won't expand multiple arguments as SQLQuery does.
|
||||||
*
|
*
|
||||||
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
||||||
* paramaterised queries
|
* paramaterised queries
|
||||||
@ -531,8 +525,8 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Append a WHERE with OR.
|
* Append a WHERE with OR.
|
||||||
*
|
*
|
||||||
* @see SQLSelect::addWhere() for syntax examples, although DataQuery
|
* @see SQLQuery::addWhere() for syntax examples, although DataQuery
|
||||||
* won't expand multiple method arguments as SQLSelect does.
|
* won't expand multiple method arguments as SQLQuery does.
|
||||||
*
|
*
|
||||||
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
* @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
|
||||||
* paramaterised queries
|
* paramaterised queries
|
||||||
@ -548,7 +542,7 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Set the ORDER BY clause of this query
|
* Set the ORDER BY clause of this query
|
||||||
*
|
*
|
||||||
* @see SQLSelect::orderby()
|
* @see SQLQuery::orderby()
|
||||||
*
|
*
|
||||||
* @param String $sort Column to sort on (escaped SQL statement)
|
* @param String $sort Column to sort on (escaped SQL statement)
|
||||||
* @param String $direction Direction ("ASC" or "DESC", escaped SQL statement)
|
* @param String $direction Direction ("ASC" or "DESC", escaped SQL statement)
|
||||||
@ -770,7 +764,7 @@ class DataQuery {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $field Select statement identifier, either the unquoted column name,
|
* @param String $field Select statement identifier, either the unquoted column name,
|
||||||
* the full composite SQL statement, or the alias set through {@link SQLSelect->selectField()}.
|
* the full composite SQL statement, or the alias set through {@link SQLQuery->selectField()}.
|
||||||
* @return String The expression used to query this field via this DataQuery
|
* @return String The expression used to query this field via this DataQuery
|
||||||
*/
|
*/
|
||||||
protected function expressionForField($field) {
|
protected function expressionForField($field) {
|
||||||
@ -835,7 +829,7 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Represents a subgroup inside a WHERE clause in a {@link DataQuery}
|
* Represents a subgroup inside a WHERE clause in a {@link DataQuery}
|
||||||
*
|
*
|
||||||
* Stores the clauses for the subgroup inside a specific {@link SQLSelect} object.
|
* Stores the clauses for the subgroup inside a specific {@link SQLQuery} object.
|
||||||
* All non-where methods call their DataQuery versions, which uses the base
|
* All non-where methods call their DataQuery versions, which uses the base
|
||||||
* query object.
|
* query object.
|
||||||
*
|
*
|
||||||
@ -848,7 +842,7 @@ class DataQuery_SubGroup extends DataQuery implements SQLConditionGroup {
|
|||||||
public function __construct(DataQuery $base, $connective) {
|
public function __construct(DataQuery $base, $connective) {
|
||||||
$this->dataClass = $base->dataClass;
|
$this->dataClass = $base->dataClass;
|
||||||
$this->query = $base->query;
|
$this->query = $base->query;
|
||||||
$this->whereQuery = new SQLSelect();
|
$this->whereQuery = new SQLQuery();
|
||||||
$this->whereQuery->setConnective($connective);
|
$this->whereQuery->setConnective($connective);
|
||||||
|
|
||||||
$base->where($this);
|
$base->where($this);
|
||||||
|
@ -38,15 +38,6 @@ class Hierarchy extends DataExtension {
|
|||||||
*/
|
*/
|
||||||
private static $node_threshold_leaf = 250;
|
private static $node_threshold_leaf = 250;
|
||||||
|
|
||||||
public function augmentSQL(SQLSelect $query) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function augmentDatabase() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function augmentWrite(&$manipulation) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get_extra_config($class, $extension, $args) {
|
public static function get_extra_config($class, $extension, $args) {
|
||||||
return array(
|
return array(
|
||||||
'has_one' => array('Parent' => $class)
|
'has_one' => array('Parent' => $class)
|
||||||
|
@ -220,7 +220,7 @@ class ManyManyList extends RelationList {
|
|||||||
// With the current query, simply add the foreign and local conditions
|
// With the current query, simply add the foreign and local conditions
|
||||||
// The query can be a bit odd, especially if custom relation classes
|
// The query can be a bit odd, especially if custom relation classes
|
||||||
// don't join expected tables (@see Member_GroupSet for example).
|
// don't join expected tables (@see Member_GroupSet for example).
|
||||||
$query = new SQLSelect("*", "\"{$this->joinTable}\"");
|
$query = new SQLQuery("*", "\"{$this->joinTable}\"");
|
||||||
$query->addWhere($foreignFilter);
|
$query->addWhere($foreignFilter);
|
||||||
$query->addWhere(array(
|
$query->addWhere(array(
|
||||||
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
|
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
|
||||||
@ -365,7 +365,7 @@ class ManyManyList extends RelationList {
|
|||||||
// @todo Optimize into a single query instead of one per extra field
|
// @todo Optimize into a single query instead of one per extra field
|
||||||
if($this->extraFields) {
|
if($this->extraFields) {
|
||||||
foreach($this->extraFields as $fieldName => $dbFieldSpec) {
|
foreach($this->extraFields as $fieldName => $dbFieldSpec) {
|
||||||
$query = new SQLSelect("\"{$fieldName}\"", "\"{$this->joinTable}\"");
|
$query = new SQLQuery("\"{$fieldName}\"", "\"{$this->joinTable}\"");
|
||||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||||
$query->setWhere($filter);
|
$query->setWhere($filter);
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,10 +162,10 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
* Amend freshly created DataQuery objects with versioned-specific
|
* Amend freshly created DataQuery objects with versioned-specific
|
||||||
* information.
|
* information.
|
||||||
*
|
*
|
||||||
* @param SQLSelect
|
* @param SQLQuery
|
||||||
* @param DataQuery
|
* @param DataQuery
|
||||||
*/
|
*/
|
||||||
public function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuery) {
|
public function augmentDataQueryCreation(SQLQuery &$query, DataQuery &$dataQuery) {
|
||||||
$parts = explode('.', Versioned::get_reading_mode());
|
$parts = explode('.', Versioned::get_reading_mode());
|
||||||
|
|
||||||
if($parts[0] == 'Archive') {
|
if($parts[0] == 'Archive') {
|
||||||
@ -182,10 +182,10 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Augment the the SQLSelect that is created by the DataQuery
|
* Augment the the SQLQuery that is created by the DataQuery
|
||||||
* @todo Should this all go into VersionedDataQuery?
|
* @todo Should this all go into VersionedDataQuery?
|
||||||
*/
|
*/
|
||||||
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
|
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
|
||||||
if(!$dataQuery || !$dataQuery->getQueryParam('Versioned.mode')) {
|
if(!$dataQuery || !$dataQuery->getQueryParam('Versioned.mode')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -329,11 +329,11 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
/**
|
/**
|
||||||
* For lazy loaded fields requiring extra sql manipulation, ie versioning.
|
* For lazy loaded fields requiring extra sql manipulation, ie versioning.
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query
|
* @param SQLQuery $query
|
||||||
* @param DataQuery $dataQuery
|
* @param DataQuery $dataQuery
|
||||||
* @param DataObject $dataObject
|
* @param DataObject $dataObject
|
||||||
*/
|
*/
|
||||||
public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) {
|
public function augmentLoadLazyFields(SQLQuery &$query, DataQuery &$dataQuery = null, $dataObject) {
|
||||||
// The VersionedMode local variable ensures that this decorator only applies to
|
// The VersionedMode local variable ensures that this decorator only applies to
|
||||||
// queries that have originated from the Versioned object, and have the Versioned
|
// queries that have originated from the Versioned object, and have the Versioned
|
||||||
// metadata set on the query object. This prevents regular queries from
|
// metadata set on the query object. This prevents regular queries from
|
||||||
|
@ -150,10 +150,10 @@ interface CompositeDBField {
|
|||||||
/**
|
/**
|
||||||
* Add all columns which are defined through {@link requireField()}
|
* Add all columns which are defined through {@link requireField()}
|
||||||
* and {@link $composite_db}, or any additional SQL that is required
|
* and {@link $composite_db}, or any additional SQL that is required
|
||||||
* to get to these columns. Will mostly just write to the {@link SQLSelect->select}
|
* to get to these columns. Will mostly just write to the {@link SQLQuery->select}
|
||||||
* array.
|
* array.
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query
|
* @param SQLQuery $query
|
||||||
*/
|
*/
|
||||||
public function addToQuery(&$query);
|
public function addToQuery(&$query);
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Set a WHERE clause.
|
* Set a WHERE clause.
|
||||||
*
|
*
|
||||||
* @see SQLSelect::addWhere() for syntax examples
|
* @see SQLQuery::addWhere() for syntax examples
|
||||||
*
|
*
|
||||||
* @param mixed $where Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
* @param mixed $where Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
||||||
* @param mixed $where,... Unlimited additional predicates
|
* @param mixed $where,... Unlimited additional predicates
|
||||||
@ -468,7 +468,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see SQLSelect::addWhere()
|
* @see SQLQuery::addWhere()
|
||||||
*
|
*
|
||||||
* @param mixed $filters Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
* @param mixed $filters Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
||||||
* @param mixed $filters,... Unlimited additional predicates
|
* @param mixed $filters,... Unlimited additional predicates
|
||||||
@ -482,7 +482,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see SQLSelect::addWhere()
|
* @see SQLQuery::addWhere()
|
||||||
*
|
*
|
||||||
* @param mixed $filters Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
* @param mixed $filters Predicate(s) to set, as escaped SQL statements or paramaterised queries
|
||||||
* @param mixed $filters,... Unlimited additional predicates
|
* @param mixed $filters,... Unlimited additional predicates
|
||||||
@ -689,12 +689,12 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an SQLSelect object using the currently specified parameters.
|
* Generates an SQLQuery object using the currently specified parameters.
|
||||||
*
|
*
|
||||||
* @return SQLSelect
|
* @return SQLQuery
|
||||||
*/
|
*/
|
||||||
public function toSelect() {
|
public function toSelect() {
|
||||||
$select = new SQLSelect();
|
$select = new SQLQuery();
|
||||||
$this->copyTo($select);
|
$this->copyTo($select);
|
||||||
return $select;
|
return $select;
|
||||||
}
|
}
|
||||||
|
@ -99,13 +99,6 @@ abstract class SQLExpression {
|
|||||||
* @return string The completed SQL query
|
* @return string The completed SQL query
|
||||||
*/
|
*/
|
||||||
public function sql(&$parameters = array()) {
|
public function sql(&$parameters = array()) {
|
||||||
if(func_num_args() == 0) {
|
|
||||||
Deprecation::notice(
|
|
||||||
'3.2',
|
|
||||||
'SQLExpression::sql() now may produce parameters which are necessary to execute this query'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build each component as needed
|
// Build each component as needed
|
||||||
$sql = DB::build_sql($this, $parameters);
|
$sql = DB::build_sql($this, $parameters);
|
||||||
|
|
||||||
|
@ -6,18 +6,18 @@
|
|||||||
*
|
*
|
||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
* @deprecated since version 3.3
|
* @deprecated since version 4.0
|
||||||
*/
|
*/
|
||||||
class SQLQuery extends SQLSelect {
|
class SQLQuery extends SQLSelect {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 3.3
|
* @deprecated since version 4.0
|
||||||
*/
|
*/
|
||||||
public function __construct($select = "*", $from = array(), $where = array(), $orderby = array(),
|
public function __construct($select = "*", $from = array(), $where = array(), $orderby = array(),
|
||||||
$groupby = array(), $having = array(), $limit = array()
|
$groupby = array(), $having = array(), $limit = array()
|
||||||
) {
|
) {
|
||||||
parent::__construct($select, $from, $where, $orderby, $groupby, $having, $limit);
|
parent::__construct($select, $from, $where, $orderby, $groupby, $having, $limit);
|
||||||
Deprecation::notice('3.3', 'Use SQLSelect instead');
|
Deprecation::notice('4.0', 'Use SQLSelect instead');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* SearchContext is intentionally decoupled from any controller-logic,
|
* SearchContext is intentionally decoupled from any controller-logic,
|
||||||
* it just receives a set of search parameters and an object class it acts on.
|
* it just receives a set of search parameters and an object class it acts on.
|
||||||
*
|
*
|
||||||
* The default output of a SearchContext is either a {@link SQLSelect} object
|
* The default output of a SearchContext is either a {@link SQLQuery} object
|
||||||
* for further refinement, or a {@link SS_List} that can be used to display
|
* for further refinement, or a {@link SS_List} that can be used to display
|
||||||
* search results, e.g. in a {@link TableListField} instance.
|
* search results, e.g. in a {@link TableListField} instance.
|
||||||
*
|
*
|
||||||
@ -88,7 +88,7 @@ class SearchContext extends Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo move to SQLSelect
|
* @todo move to SQLQuery
|
||||||
* @todo fix hack
|
* @todo fix hack
|
||||||
*/
|
*/
|
||||||
protected function applyBaseTableFields() {
|
protected function applyBaseTableFields() {
|
||||||
|
@ -1600,7 +1600,7 @@ class Member_GroupSet extends ManyManyList {
|
|||||||
|
|
||||||
// Find directly applied groups
|
// Find directly applied groups
|
||||||
$manyManyFilter = parent::foreignIDFilter($id);
|
$manyManyFilter = parent::foreignIDFilter($id);
|
||||||
$query = new SQLSelect('"Group_Members"."GroupID"', '"Group_Members"', $manyManyFilter);
|
$query = new SQLQuery('"Group_Members"."GroupID"', '"Group_Members"', $manyManyFilter);
|
||||||
$groupIDs = $query->execute()->column();
|
$groupIDs = $query->execute()->column();
|
||||||
|
|
||||||
// Get all ancestors, iteratively merging these into the master set
|
// Get all ancestors, iteratively merging these into the master set
|
||||||
|
@ -95,7 +95,7 @@ class DbDatetimeTest extends FunctionalTest {
|
|||||||
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime('+1 Day', $this->getDbNow())), 'tomorrow',
|
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime('+1 Day', $this->getDbNow())), 'tomorrow',
|
||||||
$offset);
|
$offset);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array());
|
$query->setSelect(array());
|
||||||
$query->selectField($this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes'), 'test')
|
$query->selectField($this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes'), 'test')
|
||||||
->setFrom('"DbDateTimeTest_Team"')
|
->setFrom('"DbDateTimeTest_Team"')
|
||||||
@ -123,7 +123,7 @@ class DbDatetimeTest extends FunctionalTest {
|
|||||||
$result = DB::query('SELECT ' . $clause)->value();
|
$result = DB::query('SELECT ' . $clause)->value();
|
||||||
$this->matchesRoughly($result, -45 * 60, 'now - 45 minutes ahead', $offset);
|
$this->matchesRoughly($result, -45 * 60, 'now - 45 minutes ahead', $offset);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array());
|
$query->setSelect(array());
|
||||||
$query->selectField($this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"'), 'test')
|
$query->selectField($this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"'), 'test')
|
||||||
->setFrom('"DbDateTimeTest_Team"')
|
->setFrom('"DbDateTimeTest_Team"')
|
||||||
|
@ -41,7 +41,7 @@ class PaginatedListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPaginationFromQuery() {
|
public function testSetPaginationFromQuery() {
|
||||||
$query = $this->getMock('SQLSelect');
|
$query = $this->getMock('SQLQuery');
|
||||||
$query->expects($this->once())
|
$query->expects($this->once())
|
||||||
->method('getLimit')
|
->method('getLimit')
|
||||||
->will($this->returnValue(array('limit' => 15, 'start' => 30)));
|
->will($this->returnValue(array('limit' => 15, 'start' => 30)));
|
||||||
|
@ -15,12 +15,12 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public function testEmptyQueryReturnsNothing() {
|
public function testEmptyQueryReturnsNothing() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$this->assertSQLEquals('', $query->sql($parameters));
|
$this->assertSQLEquals('', $query->sql($parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectFromBasicTable() {
|
public function testSelectFromBasicTable() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('MyTable');
|
$query->setFrom('MyTable');
|
||||||
$this->assertSQLEquals("SELECT * FROM MyTable", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT * FROM MyTable", $query->sql($parameters));
|
||||||
$query->addFrom('MyJoin');
|
$query->addFrom('MyJoin');
|
||||||
@ -28,14 +28,14 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectFromUserSpecifiedFields() {
|
public function testSelectFromUserSpecifiedFields() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array("Name", "Title", "Description"));
|
$query->setSelect(array("Name", "Title", "Description"));
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$this->assertSQLEquals("SELECT Name, Title, Description FROM MyTable", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT Name, Title, Description FROM MyTable", $query->sql($parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectWithWhereClauseFilter() {
|
public function testSelectWithWhereClauseFilter() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array("Name","Meta"));
|
$query->setSelect(array("Name","Meta"));
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setWhere("Name = 'Name'");
|
$query->setWhere("Name = 'Name'");
|
||||||
@ -47,14 +47,14 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectWithConstructorParameters() {
|
public function testSelectWithConstructorParameters() {
|
||||||
$query = new SQLSelect(array("Foo", "Bar"), "FooBarTable");
|
$query = new SQLQuery(array("Foo", "Bar"), "FooBarTable");
|
||||||
$this->assertSQLEquals("SELECT Foo, Bar FROM FooBarTable", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT Foo, Bar FROM FooBarTable", $query->sql($parameters));
|
||||||
$query = new SQLSelect(array("Foo", "Bar"), "FooBarTable", array("Foo = 'Boo'"));
|
$query = new SQLQuery(array("Foo", "Bar"), "FooBarTable", array("Foo = 'Boo'"));
|
||||||
$this->assertSQLEquals("SELECT Foo, Bar FROM FooBarTable WHERE (Foo = 'Boo')", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT Foo, Bar FROM FooBarTable WHERE (Foo = 'Boo')", $query->sql($parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectWithChainedMethods() {
|
public function testSelectWithChainedMethods() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect("Name","Meta")->setFrom("MyTable")->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'");
|
$query->setSelect("Name","Meta")->setFrom("MyTable")->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'");
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
"SELECT Name, Meta FROM MyTable WHERE (Name = 'Name') AND (Meta = 'Test')",
|
"SELECT Name, Meta FROM MyTable WHERE (Name = 'Name') AND (Meta = 'Test')",
|
||||||
@ -63,14 +63,14 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testCanSortBy() {
|
public function testCanSortBy() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect("Name","Meta")->setFrom("MyTable")->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'");
|
$query->setSelect("Name","Meta")->setFrom("MyTable")->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'");
|
||||||
$this->assertTrue($query->canSortBy('Name ASC'));
|
$this->assertTrue($query->canSortBy('Name ASC'));
|
||||||
$this->assertTrue($query->canSortBy('Name'));
|
$this->assertTrue($query->canSortBy('Name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectWithChainedFilterParameters() {
|
public function testSelectWithChainedFilterParameters() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array("Name","Meta"))->setFrom("MyTable");
|
$query->setSelect(array("Name","Meta"))->setFrom("MyTable");
|
||||||
$query->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'")->addWhere("Beta != 'Gamma'");
|
$query->setWhere("Name = 'Name'")->addWhere("Meta = 'Test'")->addWhere("Beta != 'Gamma'");
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
@ -85,71 +85,71 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setLimit(99);
|
$query->setLimit(99);
|
||||||
$this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99", $query->sql($parameters));
|
||||||
|
|
||||||
// array limit with start (MySQL specific)
|
// array limit with start (MySQL specific)
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setLimit(99, 97);
|
$query->setLimit(99, 97);
|
||||||
$this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99 OFFSET 97", $query->sql($parameters));
|
$this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99 OFFSET 97", $query->sql($parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectWithOrderbyClause() {
|
public function testSelectWithOrderbyClause() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('MyName');
|
$query->setOrderBy('MyName');
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('MyName desc');
|
$query->setOrderBy('MyName desc');
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('MyName ASC, Color DESC');
|
$query->setOrderBy('MyName ASC, Color DESC');
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color DESC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color DESC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('MyName ASC, Color');
|
$query->setOrderBy('MyName ASC, Color');
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color ASC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color ASC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy(array('MyName' => 'desc'));
|
$query->setOrderBy(array('MyName' => 'desc'));
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy(array('MyName' => 'desc', 'Color'));
|
$query->setOrderBy(array('MyName' => 'desc', 'Color'));
|
||||||
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC, Color ASC', $query->sql($parameters));
|
$this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC, Color ASC', $query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('implode("MyName","Color")');
|
$query->setOrderBy('implode("MyName","Color")');
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
'SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
'SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
||||||
$query->sql($parameters));
|
$query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('implode("MyName","Color") DESC');
|
$query->setOrderBy('implode("MyName","Color") DESC');
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
'SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" DESC',
|
'SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" DESC',
|
||||||
$query->sql($parameters));
|
$query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('RAND()');
|
$query->setOrderBy('RAND()');
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
'SELECT *, RAND() AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
'SELECT *, RAND() AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
||||||
$query->sql($parameters));
|
$query->sql($parameters));
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->addFrom('INNER JOIN SecondTable USING (ID)');
|
$query->addFrom('INNER JOIN SecondTable USING (ID)');
|
||||||
$query->addFrom('INNER JOIN ThirdTable USING (ID)');
|
$query->addFrom('INNER JOIN ThirdTable USING (ID)');
|
||||||
@ -163,7 +163,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testNullLimit() {
|
public function testNullLimit() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setLimit(null);
|
$query->setLimit(null);
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testZeroLimit() {
|
public function testZeroLimit() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setLimit(0);
|
$query->setLimit(0);
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setLimit(0, 99);
|
$query->setLimit(0, 99);
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testNegativeLimit() {
|
public function testNegativeLimit() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setLimit(-10);
|
$query->setLimit(-10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testNegativeOffset() {
|
public function testNegativeOffset() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setLimit(1, -10);
|
$query->setLimit(1, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,12 +220,12 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testNegativeOffsetAndLimit() {
|
public function testNegativeOffsetAndLimit() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setLimit(-10, -10);
|
$query->setLimit(-10, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReverseOrderBy() {
|
public function testReverseOrderBy() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('MyTable');
|
$query->setFrom('MyTable');
|
||||||
|
|
||||||
// default is ASC
|
// default is ASC
|
||||||
@ -258,42 +258,42 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testFiltersOnID() {
|
public function testFiltersOnID() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("ID = 5");
|
$query->setWhere("ID = 5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
"filtersOnID() is true with simple unquoted column name"
|
"filtersOnID() is true with simple unquoted column name"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("ID=5");
|
$query->setWhere("ID=5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
"filtersOnID() is true with simple unquoted column name and no spaces in equals sign"
|
"filtersOnID() is true with simple unquoted column name and no spaces in equals sign"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("Identifier = 5");
|
$query->setWhere("Identifier = 5");
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
"filtersOnID() is false with custom column name (starting with 'id')"
|
"filtersOnID() is false with custom column name (starting with 'id')"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("ParentID = 5");
|
$query->setWhere("ParentID = 5");
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
"filtersOnID() is false with column name ending in 'ID'"
|
"filtersOnID() is false with column name ending in 'ID'"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("MyTable.ID = 5");
|
$query->setWhere("MyTable.ID = 5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
"filtersOnID() is true with table and column name"
|
"filtersOnID() is true with table and column name"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("MyTable.ID = 5");
|
$query->setWhere("MyTable.ID = 5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnID(),
|
$query->filtersOnID(),
|
||||||
@ -302,28 +302,28 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testFiltersOnFK() {
|
public function testFiltersOnFK() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("ID = 5");
|
$query->setWhere("ID = 5");
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$query->filtersOnFK(),
|
$query->filtersOnFK(),
|
||||||
"filtersOnFK() is true with simple unquoted column name"
|
"filtersOnFK() is true with simple unquoted column name"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("Identifier = 5");
|
$query->setWhere("Identifier = 5");
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$query->filtersOnFK(),
|
$query->filtersOnFK(),
|
||||||
"filtersOnFK() is false with custom column name (starting with 'id')"
|
"filtersOnFK() is false with custom column name (starting with 'id')"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("MyTable.ParentID = 5");
|
$query->setWhere("MyTable.ParentID = 5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnFK(),
|
$query->filtersOnFK(),
|
||||||
"filtersOnFK() is true with table and column name"
|
"filtersOnFK() is true with table and column name"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setWhere("MyTable.`ParentID`= 5");
|
$query->setWhere("MyTable.`ParentID`= 5");
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$query->filtersOnFK(),
|
$query->filtersOnFK(),
|
||||||
@ -332,7 +332,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testInnerJoin() {
|
public function testInnerJoin() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('MyTable');
|
$query->setFrom('MyTable');
|
||||||
$query->addInnerJoin('MyOtherTable', 'MyOtherTable.ID = 2');
|
$query->addInnerJoin('MyOtherTable', 'MyOtherTable.ID = 2');
|
||||||
$query->addLeftJoin('MyLastTable', 'MyOtherTable.ID = MyLastTable.ID');
|
$query->addLeftJoin('MyLastTable', 'MyOtherTable.ID = MyLastTable.ID');
|
||||||
@ -343,7 +343,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$query->sql($parameters)
|
$query->sql($parameters)
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('MyTable');
|
$query->setFrom('MyTable');
|
||||||
$query->addInnerJoin('MyOtherTable', 'MyOtherTable.ID = 2', 'table1');
|
$query->addInnerJoin('MyOtherTable', 'MyOtherTable.ID = 2', 'table1');
|
||||||
$query->addLeftJoin('MyLastTable', 'MyOtherTable.ID = MyLastTable.ID', 'table2');
|
$query->addLeftJoin('MyLastTable', 'MyOtherTable.ID = MyLastTable.ID', 'table2');
|
||||||
@ -377,7 +377,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSetWhereAny() {
|
public function testSetWhereAny() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('MyTable');
|
$query->setFrom('MyTable');
|
||||||
|
|
||||||
$query->setWhereAny(array(
|
$query->setWhereAny(array(
|
||||||
@ -391,7 +391,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
|
|
||||||
public function testSelectFirst() {
|
public function testSelectFirst() {
|
||||||
// Test first from sequence
|
// Test first from sequence
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$result = $query->firstRow()->execute();
|
$result = $query->firstRow()->execute();
|
||||||
@ -405,7 +405,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertEquals('Object 1', $records[0]['Name']);
|
$this->assertEquals('Object 1', $records[0]['Name']);
|
||||||
|
|
||||||
// Test first from empty sequence
|
// Test first from empty sequence
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$query->setWhere(array('"Name"' => 'Nonexistent Object'));
|
$query->setWhere(array('"Name"' => 'Nonexistent Object'));
|
||||||
@ -419,7 +419,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertCount(0, $records);
|
$this->assertCount(0, $records);
|
||||||
|
|
||||||
// Test that given the last item, the 'first' in this list matches the last
|
// Test that given the last item, the 'first' in this list matches the last
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$query->setLimit(1, 1);
|
$query->setLimit(1, 1);
|
||||||
@ -436,7 +436,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
|
|
||||||
public function testSelectLast() {
|
public function testSelectLast() {
|
||||||
// Test last in sequence
|
// Test last in sequence
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$result = $query->lastRow()->execute();
|
$result = $query->lastRow()->execute();
|
||||||
@ -450,7 +450,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertEquals('Object 2', $records[0]['Name']);
|
$this->assertEquals('Object 2', $records[0]['Name']);
|
||||||
|
|
||||||
// Test last from empty sequence
|
// Test last from empty sequence
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$query->setWhere(array("\"Name\" = 'Nonexistent Object'"));
|
$query->setWhere(array("\"Name\" = 'Nonexistent Object'"));
|
||||||
@ -464,7 +464,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertCount(0, $records);
|
$this->assertCount(0, $records);
|
||||||
|
|
||||||
// Test that given the first item, the 'last' in this list matches the first
|
// Test that given the first item, the 'last' in this list matches the first
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('"Name"');
|
$query->setOrderBy('"Name"');
|
||||||
$query->setLimit(1);
|
$query->setLimit(1);
|
||||||
@ -483,7 +483,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* Tests aggregate() function
|
* Tests aggregate() function
|
||||||
*/
|
*/
|
||||||
public function testAggregate() {
|
public function testAggregate() {
|
||||||
$query = new SQLSelect('"Common"');
|
$query = new SQLQuery('"Common"');
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setGroupBy('"Common"');
|
$query->setGroupBy('"Common"');
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* Tests that an ORDER BY is only added if a LIMIT is set.
|
* Tests that an ORDER BY is only added if a LIMIT is set.
|
||||||
*/
|
*/
|
||||||
public function testAggregateNoOrderByIfNoLimit() {
|
public function testAggregateNoOrderByIfNoLimit() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('Common');
|
$query->setOrderBy('Common');
|
||||||
$query->setLimit(array());
|
$query->setLimit(array());
|
||||||
@ -506,7 +506,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertEquals(array(), $aggregate->getOrderBy());
|
$this->assertEquals(array(), $aggregate->getOrderBy());
|
||||||
$this->assertEquals(array(), $limit);
|
$this->assertEquals(array(), $limit);
|
||||||
|
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy('Common');
|
$query->setOrderBy('Common');
|
||||||
$query->setLimit(2);
|
$query->setLimit(2);
|
||||||
@ -524,7 +524,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* because a subselect needs to be done to query paginated data.
|
* because a subselect needs to be done to query paginated data.
|
||||||
*/
|
*/
|
||||||
public function testOrderByContainingAggregateAndLimitOffset() {
|
public function testOrderByContainingAggregateAndLimitOffset() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array('"Name"', '"Meta"'));
|
$query->setSelect(array('"Name"', '"Meta"'));
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy(array('MAX("Date")'));
|
$query->setOrderBy(array('MAX("Date")'));
|
||||||
@ -547,7 +547,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
*/
|
*/
|
||||||
public function testOrderByMultiple() {
|
public function testOrderByMultiple() {
|
||||||
if(DB::get_conn() instanceof MySQLDatabase) {
|
if(DB::get_conn() instanceof MySQLDatabase) {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array('"Name"', '"Meta"'));
|
$query->setSelect(array('"Name"', '"Meta"'));
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->setOrderBy(array('MID("Name", 8, 1) DESC', '"Name" ASC'));
|
$query->setOrderBy(array('MID("Name", 8, 1) DESC', '"Name" ASC'));
|
||||||
@ -571,7 +571,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
* Test passing in a LIMIT with OFFSET clause string.
|
* Test passing in a LIMIT with OFFSET clause string.
|
||||||
*/
|
*/
|
||||||
public function testLimitSetFromClauseString() {
|
public function testLimitSetFromClauseString() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect('*');
|
$query->setSelect('*');
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testParameterisedInnerJoins() {
|
public function testParameterisedInnerJoins() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array('"SQLQueryTest_DO"."Name"', '"SubSelect"."Count"'));
|
$query->setSelect(array('"SQLQueryTest_DO"."Name"', '"SubSelect"."Count"'));
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->addInnerJoin(
|
$query->addInnerJoin(
|
||||||
@ -605,7 +605,7 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testParameterisedLeftJoins() {
|
public function testParameterisedLeftJoins() {
|
||||||
$query = new SQLSelect();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array('"SQLQueryTest_DO"."Name"', '"SubSelect"."Count"'));
|
$query->setSelect(array('"SQLQueryTest_DO"."Name"', '"SubSelect"."Count"'));
|
||||||
$query->setFrom('"SQLQueryTest_DO"');
|
$query->setFrom('"SQLQueryTest_DO"');
|
||||||
$query->addLeftJoin(
|
$query->addLeftJoin(
|
||||||
|
@ -322,7 +322,7 @@ class VersionedTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that SQLSelect::queriedTables() applies the version-suffixes properly.
|
* Test that SQLQuery::queriedTables() applies the version-suffixes properly.
|
||||||
*/
|
*/
|
||||||
public function testQueriedTables() {
|
public function testQueriedTables() {
|
||||||
Versioned::reading_stage('Live');
|
Versioned::reading_stage('Live');
|
||||||
|
Loading…
Reference in New Issue
Block a user