Ejemplo n.º 1
0
 protected function _loadAndReturnRow($position)
 {
     if (!isset($this->_data[$position])) {
         throw new Exception("Data for provided position does not exist");
     }
     // do we already have a row object for this position?
     if (empty($this->_rows[$position])) {
         $this->_rows[$position] = new $this->_rowClass(array('table' => $this->_table, 'data' => $this->_data[$position], 'stored' => $this->_stored, 'readOnly' => $this->_readOnly));
         if ($this->_table instanceof \libDb\Table\AbstractTable) {
             $info = $this->_table->info();
             if ($this->_rows[$position] instanceof \libDb\Table\Row\RowAbstract) {
                 if ($info['cols'] == array_keys($this->_data[$position])) {
                     $this->_rows[$position]->setTable($this->getTable());
                 }
             }
         } else {
             $this->_rows[$position]->setTable(null);
         }
     }
     // return the row object
     return $this->_rows[$position];
 }
Ejemplo n.º 2
0
 /**
  * Set the table object, to re-establish a live connection
  * to the database for a Row that has been de-serialized.
  *
  * @param \libDb\Table\AbstractTable $table
  * @return boolean
  * @throws \libDb\Table\Row\Exception
  */
 public function setTable(libDb\Adapter\AbstractAdapter $table = null)
 {
     if ($table == null) {
         $this->_table = null;
         $this->_connected = false;
         return false;
     }
     $tableClass = get_class($table);
     if (!$table instanceof $this->_tableClass) {
         throw new \libDb\Table\Row\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 \libDb\Table\Row\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 \libDb\Table\Row\Exception("The specified Table '{$tableClass}' does not have the same primary key as the Row");
     }
     $this->_connected = true;
     return true;
 }
Ejemplo n.º 3
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|\libDb\Expr|AbstractTable $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|\libDb\Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return Select This  object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof AbstractTable) {
         $info = $name->info();
         $name = $info[AbstractTable::NAME];
         if (isset($info[AbstractTable::SCHEMA])) {
             $schema = $info[AbstractTable::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }