Skip to content
Snippets Groups Projects
Commit 783b2e4f authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

No commit message

No commit message
parent 1f64f7cb
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,11 @@ class DataAccessService_Database ...@@ -19,6 +19,11 @@ class DataAccessService_Database
return $newTable; return $newTable;
} }
function addColumn($tableName, $columnName, $columnType)
{
return $this->tables[$tableName]->addColumn($columnName, $columnType);
}
function addRelation($parentTable, $childTable, $parentColumns, $childColumns) function addRelation($parentTable, $childTable, $parentColumns, $childColumns)
{ {
$newRelation = new DataAccessService_Database_Relation($parentTable, $childTable, $parentColumns, $childColumns); $newRelation = new DataAccessService_Database_Relation($parentTable, $childTable, $parentColumns, $childColumns);
...@@ -29,13 +34,26 @@ class DataAccessService_Database ...@@ -29,13 +34,26 @@ class DataAccessService_Database
function getData($dataObject, $where=false) function getData($dataObject, $where=false)
{ {
$parentObject = $dataObject->getParentObject(); $parentObject = $dataObject->getParentObject();
$objectElement = $dataObject->getSchemaElement();
$tableName = $objectElement->name;
// Select Expression // Select Expression
$selectExpression = $this->makeSelectExpression(); $selectExpressionParts = array();
foreach ($this->tables[$tableName]->columns as $columnName => $column) {
// DEFAULT, FIXED
if($column->fixed) {
$fixedValue = $this->enclose($column->fixed, $column->type);
$selectExpressionPart = $fixedValue;
} elseif($column->{'default'}) {
$defaultValue = $this->enclose($column->{'default'}, $column->type);
$selectExpressionPart = "COALESCE(" . $tableName . "." . $column->name . ", " . $defaultValue . ") AS " . $column->name;
} else {
$selectExpressionPart = $tableName . "." . $column->name;
}
$selectExpressionParts[] = $selectExpressionPart;
}
$selectExpression = implode(', ', $selectExpressionParts);
// Tables
$fromExpression = $this->makeFromExpression();
// Where // Where
$whereExpressionParts = array('1=1'); $whereExpressionParts = array('1=1');
if($parentObject && count($this->relations)) { if($parentObject && count($this->relations)) {
...@@ -47,7 +65,7 @@ class DataAccessService_Database ...@@ -47,7 +65,7 @@ class DataAccessService_Database
$whereExpression = implode(' and ', $whereExpressionParts); $whereExpression = implode(' and ', $whereExpressionParts);
$query = "SELECT " . $selectExpression; $query = "SELECT " . $selectExpression;
$query .= " FROM " . $fromExpression; $query .= " FROM " . $tableName;
$query .= " WHERE " . $whereExpression; $query .= " WHERE " . $whereExpression;
//echo "<pre>DAS = " . print_r($this,true) . "</pre>"; //echo "<pre>DAS = " . print_r($this,true) . "</pre>";
...@@ -83,15 +101,6 @@ class DataAccessService_Database ...@@ -83,15 +101,6 @@ class DataAccessService_Database
return implode(', ', $selectExpressionParts); return implode(', ', $selectExpressionParts);
} }
private function makeFromExpression()
{
$fromExpressionParts = array();
foreach($this->tables as $tableName => $table) {
$fromExpressionParts[] = $tableName;
}
return implode(', ', $fromExpressionParts);
}
private function makeRelationExpression($tableName, $parentObject) { private function makeRelationExpression($tableName, $parentObject) {
$relation = $this->relations[0]; $relation = $this->relations[0];
$relationExpressionParts = array(); $relationExpressionParts = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment