Example #1
0
 /**
  * @return SimDAL_Query
  */
 protected function _getQuery()
 {
     if (is_null($this->_query)) {
         $this->_query = new SimDAL_Query($this, SimDAL_Query::TYPE_SELECT, $this->_getSession()->getMapper());
         $this->_query->from($this->_getSession()->getMapper()->getMappingForEntityClass($this->_getAssociation()->getClass()));
         $parentKey = $this->_getAssociation()->getParentKey();
         $parentKey_getter = 'get' . $parentKey;
         $value = $this->_getParent()->{$parentKey_getter}();
         if (is_null($value)) {
             $this->_query = null;
             return false;
         }
         $this->_query->whereColumn($this->_getAssociation()->getForeignKey())->equals($value);
     }
     return $this->_query;
 }
Example #2
0
 public function setMock(SimDAL_Query $query, $result, $count = 0)
 {
     if (!isset($this->_mockQueries[$query->getHash()])) {
         $this->_mockQueries[$query->getHash()] = array();
     }
     $this->_mockQueries[$query->getHash()]['result'] = $result;
     $this->_mockQueries[$query->getHash()]['count'] = $count;
 }
Example #3
0
 protected function _processWhereSets(SimDAL_Query $query)
 {
     $sets = array();
     /* @var $set SimDAL_Query_Set */
     foreach ($query->getSets() as $set) {
         $column = $set->getColumn();
         $value = $set->getValue();
         $set = $this->_processWhereColumn($column->getTable(), $column->getColumn());
         $set .= ' = ';
         if ($value instanceof SimDAL_Mapper_Entity) {
             $set .= $this->_processWhereColumn($value->getTable(), $value->getColumn());
         } else {
             $set .= $this->_transformData($column->getColumn(), $value, $column->getClass());
         }
         $sets[] = $set;
     }
     return $sets;
 }
Example #4
0
 protected function _queryToString(SimDAL_Query $query)
 {
     $sql = 'SELECT * FROM ' . $query->getFrom();
     foreach ($query->getJoins() as $join) {
         $sql .= $join->getJoinType() . ' ' . $join->getTable() . ' ON ';
         foreach ($join->getWheres() as $where) {
             $method = '_process' . $where->getProcessMethod();
             $sql = $this->{$method}($where);
         }
     }
     $wheres = array();
     foreach ($query->getWheres() as $where) {
         $method = '_process' . $where->getProcessMethod();
         $wheres[] = $this->{$method}($where);
     }
     if (count($wheres) > 0) {
         $sql .= ' WHERE ' . implode(' AND ', $wheres);
     }
     return $sql;
 }