Example #1
0
 /**
  * Returns all attributes or a specific one
  * 
  * @param BaseQuery 						$query
  * @param string 							$key
  * @return mixed
  */
 protected function attributes(BaseQuery $query, $key = null)
 {
     $attributes = array_filter($query->attributes());
     foreach ($attributes as $queryKey => &$value) {
         if ($queryKey === 'wheres' && is_array($value)) {
             foreach ($value as &$where) {
                 if (isset($where[1]) && $where[1] instanceof BaseQuery) {
                     $where[1] = $this->attributes($where[1]);
                 }
             }
         }
         if ($queryKey === 'joins' && is_array($value)) {
             foreach ($value as &$join) {
                 if (isset($join[2]) && $join[2] instanceof BaseQuery) {
                     $join[2] = $this->attributes($join[2]);
                 }
             }
         }
     }
     if (!is_null($key)) {
         if (!isset($attributes[$key])) {
             return null;
         }
         return $attributes[$key];
     }
     return $attributes;
 }
Example #2
0
 /**
  * Translate the given query object and return the results as
  * argument array
  *
  * @param ClanCats\Hydrahon\BaseQuery                 $query
  * @return array
  */
 public function translate(BaseQuery $query)
 {
     // retrive the query attributes
     $this->attributes = $query->attributes();
     // handle SQL SELECT queries
     if ($query instanceof Select) {
         $queryString = $this->translateSelect();
     } elseif ($query instanceof Insert) {
         $queryString = $this->translateInsert();
     } elseif ($query instanceof Update) {
         $queryString = $this->translateUpdate();
     } elseif ($query instanceof Delete) {
         $queryString = $this->translateDelete();
     } elseif ($query instanceof Drop) {
         $queryString = $this->translateDrop();
     } elseif ($query instanceof Truncate) {
         $queryString = $this->translateTruncate();
     } elseif ($query instanceof Exists) {
         $queryString = $this->translateExists();
     } else {
         throw new Exception('Unknown query type. Cannot translate: ' . get_class($query));
     }
     // get the query parameters and reset
     $queryParameters = $this->parameters;
     $this->clearParameters();
     return array($queryString, $queryParameters);
 }
Example #3
0
 /**
  * Inherit property values from parent query
  * 
  * @param BaseQuery             $parent
  * @return void
  */
 protected function inheritFromParent(BaseQuery $parent)
 {
     parent::inheritFromParent($parent);
     if (isset($parent->database)) {
         $this->database = $parent->database;
     }
     if (isset($parent->table)) {
         $this->table = $parent->table;
     }
 }