BUGFIX Fixed support for SS 3.0 with SQLQuery changes in 9938b64cf6ed0e05583633f1b894f89bd1e9f71f

This commit is contained in:
Sean Harvey 2012-04-27 17:16:51 +12:00
parent b6082a023e
commit c7ae517c99

View File

@ -1186,9 +1186,7 @@ class MSSQLDatabase extends SS_Database {
* Convert a SQLQuery object into a SQL statement. * Convert a SQLQuery object into a SQL statement.
*/ */
public function sqlQueryToString(SQLQuery $sqlQuery) { public function sqlQueryToString(SQLQuery $sqlQuery) {
if($sqlQuery->orderby && strtoupper(trim($sqlQuery->orderby)) == 'RAND()') $sqlQuery->orderby = "NEWID()"; // get the limit and offset
//Get the limit and offset
$limit=''; $limit='';
$offset='0'; $offset='0';
if(is_array($sqlQuery->limit)){ if(is_array($sqlQuery->limit)){
@ -1248,11 +1246,38 @@ class MSSQLDatabase extends SS_Database {
$text .= implode(", ", $sqlQuery->select); $text .= implode(", ", $sqlQuery->select);
} }
if($sqlQuery->from) $text .= " FROM " . implode(" ", $sqlQuery->from); if($sqlQuery->from) $text .= ' FROM ' . implode(' ', $sqlQuery->from);
if($sqlQuery->where) $text .= " WHERE (" . $sqlQuery->getFilter(). ")";
if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby); // method_exists is done here for legacy reasons, so we can use this on SS 2.4 and 3.0
if($sqlQuery->having) $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )"; if($sqlQuery->where) {
if(!$nestedQuery && $sqlQuery->orderby) $text .= " ORDER BY " . $sqlQuery->orderby; if(method_exists($sqlQuery, 'prepareSelect')) {
$text .= ' WHERE (' . $sqlQuery->prepareSelect() . ')';
} else {
$text .= ' WHERE (' . $sqlQuery->getFilter() . ')';
}
}
if($sqlQuery->groupby) {
if(method_exists($sqlQuery, 'prepareGroupBy')) {
$text .= ' GROUP BY ' . $sqlQuery->prepareGroupBy();
} else {
$text .= ' GROUP BY ' . implode(', ', $sqlQuery->groupby);
}
}
if($sqlQuery->having) {
if(method_exists($sqlQuery, 'prepareHaving')) {
$text .= ' HAVING ( ' . $sqlQuery->prepareHaving() . ' )';
} else {
$text .= ' HAVING ( ' . implode(' ) AND ( ', $sqlQuery->having) . ' )';
}
}
if(!$nestedQuery && $sqlQuery->orderby) {
if(method_exists($sqlQuery, 'prepareOrderBy')) {
$text .= ' ORDER BY ' . $sqlQuery->prepareOrderBy();
} else {
$text .= ' ORDER BY ' . $sqlQuery->orderby;
}
}
// $suffixText is used by the nested queries to create an offset limit // $suffixText is used by the nested queries to create an offset limit
if($suffixText) $text .= $suffixText; if($suffixText) $text .= $suffixText;