BUGFIX Allow omitting FROM clause in sqlQueryToString()

This commit is contained in:
Ingo Schommer 2011-05-19 11:36:39 +12:00
parent f7fd2d46da
commit 2e1dc517e6

View File

@ -1010,14 +1010,13 @@ class SQLite3Database 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->from) return '';
$distinct = $sqlQuery->distinct ? "DISTINCT " : ""; $distinct = $sqlQuery->distinct ? "DISTINCT " : "";
if($sqlQuery->delete) { if($sqlQuery->delete) {
$text = "DELETE "; $text = "DELETE ";
} else if($sqlQuery->select) { } else if($sqlQuery->select) {
$text = "SELECT $distinct" . implode(", ", $sqlQuery->select); $text = "SELECT $distinct" . implode(", ", $sqlQuery->select);
} }
$text .= " FROM " . implode(" ", $sqlQuery->from); if($sqlQuery->from) $text .= " FROM " . implode(" ", $sqlQuery->from);
if($sqlQuery->where) $text .= " WHERE (" . $sqlQuery->getFilter(). ")"; if($sqlQuery->where) $text .= " WHERE (" . $sqlQuery->getFilter(). ")";
if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby); if($sqlQuery->groupby) $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);