Пример #1
0
 /**
  * Sets the primary table name and retrieves the table schema.
  *
  * @param \Micro\Database\Table\TableAbstract $adapter
  * @return \Micro\Database\Select This \Micro\Database\Select object.
  */
 public function setTable(TableAbstract $table)
 {
     $this->_adapter = $table->getAdapter();
     $this->_info = $table->info();
     $this->_table = $table;
     return $this;
 }
Пример #2
0
 public function rowsetToObjects($rowset)
 {
     $results = [];
     if (!is_array($rowset) && !$rowset instanceof RowsetAbstract) {
         return [];
     }
     if (count($rowset) === 0) {
         return [];
     }
     $primary = $this->table->info('primary');
     $primary = current($primary);
     foreach ($rowset as $row) {
         $results[$row->{$primary}] = $this->rowToObject($row);
     }
     return $results;
 }
Пример #3
0
 /**
  * Set the table object, to re-establish a live connection
  * to the database for a Row that has been de-serialized.
  *
  * @param \Micro\Database\Table\TableAbstract $table
  * @return boolean
  * @throws Exception
  */
 public function setTable(TableAbstract $table = null)
 {
     if ($table == null) {
         $this->_table = null;
         $this->_connected = false;
         return false;
     }
     $tableClass = get_class($table);
     if (!$table instanceof $this->_tableClass) {
         throw new Exception("The specified Table is of class {$tableClass}, expecting class to be instance of {$this->_tableClass}");
     }
     $this->_table = $table;
     $this->_tableClass = $tableClass;
     $info = $this->_table->info();
     if ($info['cols'] != array_keys($this->_data)) {
         throw new Exception('The specified Table does not have the same columns as the Row');
     }
     if (!array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
         throw new Exception("The specified Table '{$tableClass}' does not have the same primary key as the Row");
     }
     $this->_connected = true;
     return true;
 }
Пример #4
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|\Micro\Database\Expr|\Micro\Database\Table\TableAbstract $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|\Micro\Database\Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return \Micro\Database\Table\Select This \Micro\Database\Table\Select object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof TableAbstract) {
         $info = $name->info();
         $name = $info[TableAbstract::NAME];
         if (isset($info[TableAbstract::SCHEMA])) {
             $schema = $info[TableAbstract::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }