示例#1
0
 /**
  * Set the table object, to re-establish a live connection
  * to the database for a Row that has been de-serialized.
  *
  * @param JO_Db_Table_Abstract $table
  * @return boolean
  * @throws JO_Db_Table_Row_Exception
  */
 public function setTable(JO_Db_Table_Abstract $table = null)
 {
     if ($table == null) {
         $this->_table = null;
         $this->_connected = false;
         return false;
     }
     $tableClass = get_class($table);
     if (!$table instanceof $this->_tableClass) {
         require_once 'JO/Db/Table/Row/Exception.php';
         throw new JO_Db_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)) {
         require_once 'JO/Db/Table/Row/Exception.php';
         throw new JO_Db_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) {
         require_once 'JO/Db/Table/Row/Exception.php';
         throw new JO_Db_Table_Row_Exception("The specified Table '{$tableClass}' does not have the same primary key as the Row");
     }
     $this->_connected = true;
     return true;
 }
示例#2
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|JO_Db_Expr|JO_Db_Table_Abstract $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|JO_Db_Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return JO_Db_Table_Select This JO_Db_Table_Select object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof JO_Db_Table_Abstract) {
         $info = $name->info();
         $name = $info[JO_Db_Table_Abstract::NAME];
         if (isset($info[JO_Db_Table_Abstract::SCHEMA])) {
             $schema = $info[JO_Db_Table_Abstract::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }