private static function _setSubSelectQuery($pSubQueryTables, $pPhpObject)
 {
     if (isset($pPhpObject->subQuery)) {
         // TODO
     } else {
         $lSelectQuery = new SelectQuery($pSubQueryTables[0]['right_table'], $pSubQueryTables[0]['right_table_alias']);
         for ($i = 1; $i < count($pSubQueryTables); $i++) {
             $lJoinTable = $pSubQueryTables[$i];
             $lSelectQuery->addTable($lJoinTable["right_table"], $lJoinTable["right_table_alias"], SelectQuery::LEFT_JOIN, $lJoinTable["right_column"], $lJoinTable["left_column"], $lJoinTable["left_table"]);
         }
     }
     $lFirstQueryTable = $pSubQueryTables[0];
     $lFirstTableName = array_key_exists('right_table_alias', $lFirstQueryTable) && !is_null($lFirstQueryTable['right_table_alias']) ? $lFirstQueryTable['right_table_alias'] : $lFirstQueryTable['right_table'];
     $lLastQueryTable = $pSubQueryTables[count($pSubQueryTables) - 1];
     $lLastTableName = array_key_exists('right_table_alias', $lLastQueryTable) && !is_null($lLastQueryTable['right_table_alias']) ? $lLastQueryTable['right_table_alias'] : $lLastQueryTable['right_table'];
     $lFirstColumnId = $lFirstQueryTable['right_column'][0];
     $lSelectQuery->setFirstTableCurrentTable()->addSelectColumn($lFirstColumnId)->addGroupColumn($lFirstColumnId);
     if (isset($pPhpObject->havingLogicalJunction)) {
         $lSubLogicalJunction = self::phpObjectToHavingLogicalJunction($pPhpObject->havingLogicalJunction, $lFirstTableName, $lFirstColumnId, $lLastTableName, $lLastQueryTable["right_model"]);
     } else {
         self::_completeHavingLiteral($pPhpObject->havingLiteral, $lFirstTableName, $lFirstColumnId, $lLastTableName, $lLastQueryTable["right_model"]);
         $lSubLogicalJunction = new HavingLogicalJunction(LogicalJunction::CONJUNCTION);
         $lSubLogicalJunction->addLiteral(HavingLiteral::phpObjectToHavingLiteral($pPhpObject->havingLiteral));
     }
     $lSelectQuery->setHavingLogicalJunction($lSubLogicalJunction);
     return $lSelectQuery;
 }
 /**
  * prepare, execute and return result of query
  * @param SelectQuery $pSelectQuery
  * @throws Exception
  * @return array
  */
 public function executeQuery($pSelectQuery)
 {
     list($lQuery, $lValues) = $pSelectQuery->export();
     try {
         //var_dump("\n\n".vsprintf(str_replace('?', "%s", $lQuery), $lValues));
         $lQueryId = $this->prepareQuery($lQuery, $lValues);
         $this->doQueryWithId($lQueryId);
         $lResult = $this->fetchAllWithId($lQueryId);
     } catch (Exception $e) {
         trigger_error(var_export($e->getMessage(), true));
         throw new Exception($e->getMessage());
     }
     return $lResult;
 }
 private function _loadObjectFromDatabase($pObject, $pSelectColumns, $pWhereColumns, $lLogicalJunctionType)
 {
     $lSuccess = false;
     if (!array_key_exists($this->getValue("database")->getValue("id"), self::$sDbObjectById)) {
         $this->_initDbObject();
     }
     if (!$this->mInitialized) {
         $this->_initColumnsProperties($pObject->getModel());
     }
     $lLinkedLiteral = new LogicalJunction($lLogicalJunctionType);
     foreach ($pWhereColumns as $lColumn => $lValue) {
         $lLinkedLiteral->addLiteral(new Literal($this->getValue("name"), $lColumn, "=", $lValue));
     }
     $lSelectQuery = new SelectQuery($this->getValue("name"));
     $lSelectQuery->setWhereLogicalJunction($lLinkedLiteral);
     foreach ($pSelectColumns as $lColumn) {
         $lSelectQuery->addSelectColumn($lColumn);
     }
     $lResult = self::$sDbObjectById[$this->getValue("database")->getValue("id")]->executeQuery($lSelectQuery);
     $lIsModelArray = $pObject->getModel() instanceof ModelArray;
     if (is_array($lResult) && ($lIsModelArray || count($lResult) == 1)) {
         if (!$lIsModelArray) {
             $lResult = $lResult[0];
         }
         if (empty($pSelectColumns)) {
             $pObject->fromSqlDataBase($lResult, self::getDatabaseConnectionTimeZone());
         } else {
             $pObject->fromSqlDataBaseId($lResult, self::getDatabaseConnectionTimeZone());
         }
         $lSuccess = true;
     }
     return $lSuccess;
 }