public function testShouldReturnRolesTable() { $query = new Query('roles'); $result = $query->getTable(); $expected = 'roles'; $this->assertEquals($expected, $result); }
public final function query(Query $query) { $result = $this->queryRaw($query->toDialectString($this->getDialect())); if ($query instanceof InsertQuery && !empty($this->sequencePool[$name = $query->getTable() . '_id'])) { $id = current($this->sequencePool[$name]); Assert::isTrue($id instanceof Identifier, 'identifier was lost in the way'); $id->setId($this->getInsertId())->finalize(); unset($this->sequencePool[$name][key($this->sequencePool[$name])]); } return $result; }
/** * Throws UnexpectedValueException if the row class, either gleaned from Query::getTable() or * provided directly, does not exist. * Throws UnexpectedValueException if the above class does not have Model in its ancestry. * * @param Query $query * @param string $class = null */ public function __construct(Query $query, $class = null) { if ($class) { $this->class = trim($class); } else { $this->class = trim(StringFormat::className($query->getTable())); } if (!class_exists($this->class)) { throw new UnexpectedValueException(sprintf('Class "%s" does not exist.', $this->class)); } if (!is_a($this->class, 'Model', true)) { throw new UnexpectedValueException(sprintf('Class "%s" does not inherit from Model.', $this->class)); } $this->query = $query; }
/** * @group subquery * @covers Query::getTable */ function testGetTableTwoWordsWithAlias() { $q = new Query('SELECT testing', 'alias'); $this->assertEquals('SELECT testing', $q->getTable()); }
public function install(array $options = array()) { $toret = false; $this->error_msg = false; if ($this->checkConnection()) { $drop_table = array_key_exists('drop_table', $options) ? $options['drop_table'] : false; $query = $this->getInstallSQL(); if ($query) { if ($drop_table) { $table = $this->getSource(); $drop_query = new CustomQuery('DROP TABLE IF EXISTS ' . Query::getTable($this) . '', array('connection' => $this->db)); $drop_query->execute(); Backend::addNotice('Dropping table ' . $table); if (!empty($drop_query->error_msg)) { $this->error_msg = $drop_query->error_msg; } } $query = new CustomQuery($query, array('connection' => $this->db)); $toret = $query->execute(); if (!empty($query->error_msg)) { $this->error_msg = $query->error_msg; } } else { if (class_exists('BackendError', false)) { BackendError::add(get_class($this) . ': No Install SQL', 'install'); } $this->error_msg = 'No Install SQL for ' . class_name($this); } } else { if (class_exists('BackendError', false)) { BackendError::add(get_class($this) . ': DB Connection Error', 'install'); } $this->error_msg = 'DB Connection error'; } return $toret; }
function join($type, $table, $conditions, array $options = array()) { $this->query = false; $type = strtoupper($type); if (!in_array($type, array('RIGHT', 'LEFT', 'INNER', 'OUTER'))) { throw new Exception('Unsupported Join Type'); } if (!is_array($conditions)) { $conditions = array($conditions); } if (!array_key_exists($type, $this->joins)) { $this->joins[$type] = array(); } if ($table instanceof Query) { $table = $table->__toString(); if (array_key_exists('alias', $options)) { $table = '(' . $table . ') AS ' . Query::enclose($options['alias']); } else { trigger_error('Joined sub queries should have aliases', E_USER_ERROR); } } else { $table = Query::getTable($table); if (array_key_exists('alias', $options)) { $table = Query::enclose($table) . ' AS ' . Query::enclose($options['alias']); } } if (array_key_exists($table, $this->joins[$type])) { $this->joins[$type][$table] = array_merge($this->joins[$type][$table], $conditions); } else { $this->joins[$type][$table] = $conditions; } return $this; }