mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #1352 from chillu/pulls/postgres-fixes
Postgres fixes
This commit is contained in:
commit
ceb7e3c8a8
@ -139,6 +139,8 @@ class DataQuery {
|
||||
|
||||
/**
|
||||
* Ensure that the query is ready to execute.
|
||||
*
|
||||
* @return SQLQuery
|
||||
*/
|
||||
public function getFinalisedQuery($queriedColumns = null) {
|
||||
if(!$queriedColumns) $queriedColumns = $this->queriedColumns;
|
||||
@ -277,16 +279,14 @@ class DataQuery {
|
||||
|
||||
if(isset($databaseFields[$parts[0]])) {
|
||||
$qualCol = "\"$baseClass\".\"{$parts[0]}\"";
|
||||
|
||||
// remove original sort
|
||||
unset($orderby[$k]);
|
||||
|
||||
// add new columns sort
|
||||
$orderby[$qualCol] = $dir;
|
||||
|
||||
} else {
|
||||
$qualCol = "\"$parts[0]\"";
|
||||
}
|
||||
|
||||
// remove original sort
|
||||
unset($orderby[$k]);
|
||||
// add new columns sort
|
||||
$orderby[$qualCol] = $dir;
|
||||
|
||||
// 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()
|
||||
@ -419,7 +419,7 @@ class DataQuery {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HAVING clause of this query
|
||||
* Set the HAVING clause of this query.
|
||||
*
|
||||
* @param String $having Escaped SQL statement
|
||||
*/
|
||||
@ -458,10 +458,10 @@ class DataQuery {
|
||||
*
|
||||
* <code>
|
||||
* // the entire predicate as a single string
|
||||
* $query->where("Column = 'Value'");
|
||||
* $query->where("\"Column\" = 'Value'");
|
||||
*
|
||||
* // multiple predicates as an array
|
||||
* $query->where(array("Column = 'Value'", "Column != 'Value'"));
|
||||
* $query->where(array("\"Column\" = 'Value'", "\"Column\" != 'Value'"));
|
||||
* </code>
|
||||
*
|
||||
* @param string|array $where Predicate(s) to set, as escaped SQL statements.
|
||||
@ -476,7 +476,7 @@ class DataQuery {
|
||||
/**
|
||||
* Set a WHERE with OR.
|
||||
*
|
||||
* @example $dataQuery->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
|
||||
* @example $dataQuery->whereAny(array("\"Monkey\" = 'Chimp'", "\"Color\" = 'Brown'"));
|
||||
* @see where()
|
||||
*
|
||||
* @param array $filter Escaped SQL statement.
|
||||
@ -778,10 +778,10 @@ class DataQuery_SubGroup extends DataQuery {
|
||||
*
|
||||
* <code>
|
||||
* // the entire predicate as a single string
|
||||
* $query->where("Column = 'Value'");
|
||||
* $query->where("\"Column\" = 'Value'");
|
||||
*
|
||||
* // multiple predicates as an array
|
||||
* $query->where(array("Column = 'Value'", "Column != 'Value'"));
|
||||
* $query->where(array("\"Column\" = 'Value'", "\"Column\" != 'Value'"));
|
||||
* </code>
|
||||
*
|
||||
* @param string|array $where Predicate(s) to set, as escaped SQL statements.
|
||||
@ -796,7 +796,7 @@ class DataQuery_SubGroup extends DataQuery {
|
||||
/**
|
||||
* Set a WHERE with OR.
|
||||
*
|
||||
* @example $dataQuery->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
|
||||
* @example $dataQuery->whereAny(array("\"Monkey\" = 'Chimp'", "\"Color\" = 'Brown'"));
|
||||
* @see where()
|
||||
*
|
||||
* @param array $filter Escaped SQL statement.
|
||||
|
@ -750,6 +750,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Returns the SELECT clauses ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @param array $select Select columns
|
||||
* @param boolean $distinct Distinct select?
|
||||
* @return string
|
||||
@ -770,6 +772,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Return the FROM clause ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlFromToString($from) {
|
||||
@ -778,6 +782,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Returns the WHERE clauses ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlWhereToString($where, $connective) {
|
||||
@ -786,6 +792,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Returns the ORDER BY clauses ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlOrderByToString($orderby) {
|
||||
@ -800,6 +808,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Returns the GROUP BY clauses ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlGroupByToString($groupby) {
|
||||
@ -808,6 +818,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Returns the HAVING clauses ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlHavingToString($having) {
|
||||
@ -816,6 +828,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Return the LIMIT clause ready for inserting into a query.
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sqlLimitToString($limit) {
|
||||
@ -847,6 +861,8 @@ abstract class SS_Database {
|
||||
|
||||
/**
|
||||
* Convert a SQLQuery object into a SQL statement
|
||||
* Caution: Expects correctly quoted and escaped SQL fragments.
|
||||
*
|
||||
* @param $query SQLQuery
|
||||
*/
|
||||
public function sqlQueryToString(SQLQuery $query) {
|
||||
|
@ -180,6 +180,7 @@ class ManyManyList extends RelationList {
|
||||
$from = $query->getFrom();
|
||||
unset($from[$this->joinTable]);
|
||||
$query->setFrom($from);
|
||||
$query->setDistinct(false);
|
||||
|
||||
// Use a sub-query as SQLite does not support setting delete targets in
|
||||
// joined queries.
|
||||
|
@ -1071,6 +1071,7 @@ class SQLQuery {
|
||||
$clone->setOrderBy($this->orderby);
|
||||
$clone->setGroupBy($this->groupby);
|
||||
if($alias) {
|
||||
$clone->setSelect(array());
|
||||
$clone->selectField($column, $alias);
|
||||
} else {
|
||||
$clone->setSelect($column);
|
||||
|
@ -242,7 +242,7 @@ class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
||||
)
|
||||
);
|
||||
|
||||
private static $default_sort = 'FirstName';
|
||||
private static $default_sort = '"FirstName"';
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
@ -266,7 +266,7 @@ class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly
|
||||
'People' => 'GridFieldDetailFormTest_Person'
|
||||
);
|
||||
|
||||
private static $default_sort = 'Name';
|
||||
private static $default_sort = '"Name"';
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
@ -290,7 +290,7 @@ class GridFieldDetailFormTest_Category extends DataObject implements TestOnly {
|
||||
'People' => 'GridFieldDetailFormTest_Person'
|
||||
);
|
||||
|
||||
private static $default_sort = 'Name';
|
||||
private static $default_sort = '"Name"';
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
@ -1161,7 +1161,7 @@ class DataObjectTest_Team extends DataObject implements TestOnly {
|
||||
)
|
||||
);
|
||||
|
||||
private static $default_sort = "Title";
|
||||
private static $default_sort = '"Title"';
|
||||
|
||||
public function MyTitle() {
|
||||
return 'Team ' . $this->Title;
|
||||
|
@ -374,7 +374,7 @@ class SQLQueryTest extends SapphireTest {
|
||||
public function testAggregate() {
|
||||
$query = new SQLQuery();
|
||||
$query->setFrom('"SQLQueryTest_DO"');
|
||||
$query->setGroupBy("Common");
|
||||
$query->setGroupBy('"Common"');
|
||||
|
||||
$queryClone = $query->aggregate('COUNT(*)', 'cnt');
|
||||
$result = $queryClone->execute();
|
||||
|
Loading…
x
Reference in New Issue
Block a user