예제 #1
0
 /**
  * Gera um comando SQL de select no banco de dados
  * @param array $columns Vetor com as colunas utilizadas na consulta
  * @param string $table Nome da tabela
  * @param mixed $where Array associativo no formato wherearray, um objeto Where ou uma string
  * @param mixed $extra Array ou Expression Se $where for uma string $extra será considerado parâmetros
  * @example 
  *   var_dump($query->select(['cp1', 'cp2'], "tabela1", ['where' => ['id' => 33]]));
  *   //Saida: array(
  *      'status' => true,
  *      'sql' => 'SELECT cp1,cp2 FROM tabela1 WHERE id = ?',
  *      'values' => array(33)
  *    )
  * 
  * @return array No formato queryresult
  */
 public function select($columns, $table, $where = array(), $extra = array())
 {
     $table = $this->proccessTable($table);
     if (!$this->validateTable($table)) {
         return $this->returnQueryResultError('O nome da tabela é inválido');
     }
     if (empty($columns)) {
         return $this->returnQueryResultError('Deve ser informado pelo menos uma coluna');
     }
     if (!is_array($columns)) {
         $columns = array($columns);
     }
     if (is_string($where) && !empty($where)) {
         $result = array('sql' => $where, 'values' => $extra);
     } else {
         if (!empty($where)) {
             if (is_array($extra)) {
                 $extra['where'] = $where;
             } else {
                 if (is_a($extra, 'Expression')) {
                     $extra->setWhere($where);
                 }
             }
         }
         $result = $this->proccessQuery(Expression::getInstance($extra));
     }
     $sql = 'SELECT ' . implode(',', $columns) . ' FROM ' . $table . ' ' . $result['sql'];
     return $this->getQueryResult($sql, $result['values']);
 }
예제 #2
0
 /**
  * @covers Expression::getInstance
  * @todo   Implement testGetInstance().
  */
 public function testGetInstance()
 {
     $this->object = Expression::getInstance(array('x' => 'y'));
     $this->assertFalse($this->object->hasWhere(), 'Falha ao possuir o WHERE');
     $this->assertEquals($this->object, Expression::getInstance($this->object));
 }