/**
  * Generate the "join" part of the sql
  *
  * @return string
  */
 protected function _generateJoinSQL()
 {
     $sql = ' FROM ' . B2DB::getTablePrefix() . $this->fromtable->getB2DBName() . ' ' . $this->fromtable->getB2DBAlias();
     foreach ($this->jointables as $a_jt) {
         $sql .= ' ' . $a_jt['jointype'] . ' ' . B2DB::getTablePrefix() . $a_jt['jointable']->getB2DBName() . ' ' . $a_jt['jointable']->getB2DBAlias();
         $sql .= ' ON (' . $a_jt['col1'] . self::DB_EQUALS . $a_jt['col2'];
         foreach ($a_jt['criterias'] as $a_crit) {
             $sql .= ' AND ';
             $a_crit = new B2DBCriterion($a_crit[0], $a_crit[1]);
             $sql .= $this->_parseCriterion($a_crit);
         }
         $sql .= ')';
     }
     return $sql;
 }
Exemplo n.º 2
0
 /**
  * Perform upgrade for a table, by comparing one table to an old version
  * of the same table
  *
  * @param B2DBTable $old_table
  */
 public function upgrade(B2DBTable $old_table)
 {
     if ($old_table->getVersion() != $this->getVersion() - 1) {
         throw new B2DBException('Cannot upgrade from ' . get_class($old_table) . ' version ' . $old_table->getVersion() . ', must be version ' . ($this->getVersion() - 1));
     }
     $old_columns = $old_table->getColumns();
     $new_columns = $this->getColumns();
     $added_columns = array_diff_key($new_columns, $old_columns);
     $altered_columns = array_diff($old_columns, $new_columns);
     $dropped_columns = array_keys(array_diff_key($old_columns, $new_columns));
     $sqls = array();
     foreach ($added_columns as $column => $details) {
         $sqls[] = $this->_getAddColumnSQL($column, $details);
     }
     if (count($sqls)) {
         foreach ($sqls as $sqlStmt) {
             $statement = B2DBStatement::getPreparedStatement($sqlStmt);
             $res = $statement->performQuery('alter');
         }
     }
     $this->_migrateData($old_table);
     $sqls = array();
     foreach ($altered_columns as $column) {
         $sqls[] = $this->_getAlterColumnSQL($column, $new_columns[$column]);
     }
     foreach ($dropped_columns as $column) {
         $sqls[] = $this->_getDropColumnSQL($column);
     }
     if (count($sqls)) {
         foreach ($sqls as $sqlStmt) {
             $statement = B2DBStatement::getPreparedStatement($sqlStmt);
             $res = $statement->performQuery('alter');
         }
     }
 }