mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fix SQLQuery::queriedTables() and added test.
This commit is contained in:
parent
397d19f23b
commit
6915e58a39
@ -230,7 +230,7 @@ class SQLQuery {
|
|||||||
public function queriedTables() {
|
public function queriedTables() {
|
||||||
$tables = array();
|
$tables = array();
|
||||||
foreach($this->from as $key => $tableClause) {
|
foreach($this->from as $key => $tableClause) {
|
||||||
if(is_array($tableClause)) $table = $tableClause['table'];
|
if(is_array($tableClause)) $table = '"'.$tableClause['table'].'"';
|
||||||
else if(is_string($tableClause) && preg_match('/JOIN +("[^"]+") +(AS|ON) +/i', $tableClause, $matches)) $table = $matches[1];
|
else if(is_string($tableClause) && preg_match('/JOIN +("[^"]+") +(AS|ON) +/i', $tableClause, $matches)) $table = $matches[1];
|
||||||
else $table = $tableClause;
|
else $table = $tableClause;
|
||||||
|
|
||||||
@ -455,6 +455,9 @@ class SQLQuery {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function sql() {
|
function sql() {
|
||||||
|
// TODO: Don't require this internal-state manipulate-and-preserve - let sqlQueryToString() handle the new syntax
|
||||||
|
$origFrom = $this->from;
|
||||||
|
|
||||||
// Build from clauses
|
// Build from clauses
|
||||||
foreach($this->from as $alias => $join) {
|
foreach($this->from as $alias => $join) {
|
||||||
// $join can be something like this array structure
|
// $join can be something like this array structure
|
||||||
@ -468,9 +471,11 @@ class SQLQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$sql = DB::getConn()->sqlQueryToString($this);
|
$sql = DB::getConn()->sqlQueryToString($this);
|
||||||
if($this->replacementsOld) $sql = str_replace($this->replacementsOld, $this->replacementsNew, $sql);
|
if($this->replacementsOld) $sql = str_replace($this->replacementsOld, $this->replacementsNew, $sql);
|
||||||
|
|
||||||
|
$this->from = $origFrom;
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +230,18 @@ class VersionedTest extends SapphireTest {
|
|||||||
'Models w/o Versioned can have their own Version field.'
|
'Models w/o Versioned can have their own Version field.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that SQLQuery::queriedTables() applies the version-suffixes properly.
|
||||||
|
*/
|
||||||
|
public function testQueriedTables() {
|
||||||
|
Versioned::reading_stage('Live');
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'VersionedTest_DataObject_Live',
|
||||||
|
'VersionedTest_Subclass_Live',
|
||||||
|
), DataObject::get('VersionedTest_DataObject')->dataQuery()->query()->queriedTables());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user