Returns the differences definition in $dbSchema as database specific SQL DDL queries.

@param ezcDbSchemaDiff $dbSchemaDiff
@param ezcDbHandler    $db

@return array(string)
162720
public function convertDiffToDDL( ezcDbSchemaDiff $dbSchemaDiff, ezcDbHandler $db = null )
    {
        $this->diffSchema = $dbSchemaDiff;

        // reset queries
        $this->queries = array();
        $this->context = array();

        // Find sequences which require explicit drop statesments, see bug 
        // #16222
        if ( $db !== null )
        {
            $this->generateAdditionalDropSequenceStatements( $dbSchemaDiff, $db );
        }

        $this->generateDiffSchemaAsSql();
        return $this->queries;
    }
1352490
protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
    {
        return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff));
    }
315731
public function getDatabaseSchemata($dbName)
    {
        $sql = "SELECT
            default_character_set_name,
            default_collation_name
            FROM information_schema.SCHEMATA
            WHERE schema_name = %s;";
        $sql = sprintf($sql, $this->quote($dbName));
        $row = $this->pdo->query($sql)->fetch();

        return $row;
    }
330128
def _get_group_difference(self, sp_groups):
        """"""
        db_groups = set(Group.objects.all().values_list('name', flat=True))
        missing_from_db = set(sp_groups).difference(db_groups)
        missing_from_sp = db_groups.difference(sp_groups)

        return (missing_from_db, missing_from_sp)
303074
static function diffField( $field1, $field2, $schema1Type, $schema2Type )
    {
        /* Type is always available */
        if ( $field1['type'] != $field2['type'] )
        {
            return array( 'different-options' => array( 'type' ), 'field-def' => $field2 );
        }

        $test_fields = array( 'default', 'not_null' );
        
        // Ignore length for int types
        if ( $field1['type'] === $field2['type'] && $field1['type'] !== 'int' )
            $test_fields[] = 'length';

        $different_options = array();

        foreach ( $test_fields as $test_field )
        {
            if ( isset( $field1[$test_field] ) )
            {
                if ( !isset( $field2[$test_field] ) ||
                     ( $field1[$test_field] != $field2[$test_field] ) )
                {
                    $different_options[] = $test_field;
                }
            }
            else
            {
                if ( isset( $field2[$test_field] ) && $field2[$test_field] )
                {
                    $different_options[] = $test_field;
                }
            }
        }

        if ( $different_options )
            return array( 'different-options' => $different_options, 'field-def' => $field2 );
        else
            return false;
    }
1235304
public function getApplicableDiff( array $base, Diff $diff ): Diff {
		$throwErrors = $this->throwErrors;
		$this->throwErrors = false;

		$patched = $this->patch( $base, $diff );

		$this->throwErrors = $throwErrors;

		$treatAsMap = $diff->looksAssociative();

		$differ = $treatAsMap ? new MapDiffer( true ) : new ListDiffer();

		$diffOps = $differ->doDiff( $base, $patched );

		$diff = new Diff( $diffOps, $treatAsMap );

		return $diff;
	}
868614
protected function convertFromGenericType( ezcDbSchemaField $fieldDefinition )
    {
        $typeAddition = '';
        if ( in_array( $fieldDefinition->type, array( 'decimal', 'text' ) ) )
        {
            if ( $fieldDefinition->length !== false && $fieldDefinition->length !== 0 )
            {
                $typeAddition = "({$fieldDefinition->length})";
            } 
            else
            {
                $typeAddition = "(4000)"; // default length for varchar2 in Oracle
            }
        }
        if ( $fieldDefinition->type == 'boolean' )
        {
            $typeAddition = "(1)";
            if ( $fieldDefinition->default )
            {
                $fieldDefinition->default = ( $fieldDefinition->default == 'true' ) ? '1': '0';
            }
        }

        if ( !isset( $this->typeMap[$fieldDefinition->type] ) )
        {
            throw new ezcDbSchemaUnsupportedTypeException( 'Oracle', $fieldDefinition->type );
        }
        $type = $this->typeMap[$fieldDefinition->type];

        return "$type$typeAddition";
    }
258151
public function getDbFieldType() : string
    {
        $dbFieldType = $this->config->getProvider('dbFieldType');
        $dbFieldType = new $dbFieldType($this->config);
        $dbFieldType = $dbFieldType->provide();

        return $dbFieldType;
    }
1013621
public static function getDbPropertyNames(array $exclude = [])
    {
        $dbPropertyNames = array_keys(static::$dbProperties);

        return $exclude ? array_diff($dbPropertyNames, $exclude) : $dbPropertyNames;
    }
222737
def _get_changed_diff(self, blueprint, schema):
        
        table = schema.list_table_details(
            self.get_table_prefix() + blueprint.get_table()
        )

        return Comparator().diff_table(
            table, self._get_table_with_column_changes(blueprint, table)
        )
477599
public function find_references($column, $db = ''): array
  {
    $changed = false;
    if ( $db && ($db !== $this->current) ){
      $changed = $this->current;
      $this->change($db);
    }
    $column = $this->cfn($column);
    $bits = explode('.', $column);
    if ( \count($bits) === 2 ){
      array_unshift($bits, $this->current);
    }
    if ( \count($bits) !== 3 ){

      return false;
    }
    $refs = [];
    $schema = $this->modelize();
    $test = function($key) use($bits){
      return ($key['ref_db'] === $bits[0]) && ($key['ref_table'] === $bits[1]) && ($key['ref_column'] === $bits[2]);
    };
    foreach ( $schema as $table => $cfg ){
      foreach ( $cfg['keys'] as $k ){
        if ( $test($k) ){
          $refs[] = $table.'.'.$k['columns'][0];
        }
      }
    }
    if ( $changed ){
      $this->change($changed);
    }
    return $refs;
  }
1315516
public function getStructureDifferences($db, $excepted, $drop = false)
    {
        if (isset($excepted['table'])) {
            $excepted = array($excepted['table'] => $excepted);
        }
        $actions = array();
        foreach ($excepted as $table => $value) {
            $current = $this->getCurrentStructure($db, $table);
            if (count($current) > 0) {
                $dbTable = array_shift($current);
                if ($this->getHash($value) != $this->getHash($dbTable)) {

//                    if(strtolower($value['engine']) != strtolower($dbTable['engine'])) {
//                        $actions[] = array(
//                            'sql' => $this->getChangeEngine($table, $value['engine']),
//                            'action' => 'change_engine'
//                        );
//                    }

                    $subject1 = array($value['fields']);
                    $subject2 = array($dbTable['fields']);

                    foreach ($subject1 as $index => $test1) {
                        $test2 = $subject2[$index];
                        // Search for add and changes
                        foreach ($test1 as $key => $item) {
                            if (isset($test2[$key])) {
                                $item2 = $test2[$key];
                                // possible changes
                                if ($this->getHash($item) !== $this->getHash($item2)) {
                                    $actions[] = array(
                                        'sql' => $this->getAlterChange($table, $item),
                                        'action' => 'alter_field'
                                    );
                                }
                            } else {
                                // create the new instance
                                $actions[] = array('sql' => $this->getAlterAdd($table, $item), 'action' => 'add_field');
                            }
                        }
                        //Search for deletion
                        foreach ($test2 as $key => $item) {
                            if (!isset($test1[$key]) && $drop) {
                                $actions[] = array(
                                    'sql' => $this->getAlterDrop($table, $item, $key),
                                    'action' => 'drop_field'
                                );
                            }
                        }
                    }

                    $test1 = $value['keys'];
                    $test2 = $dbTable['keys'];
                    foreach ($test1 as $key => $item) {
                        if (!$this->haveKey($item, $test2)) {
                            $actions[] = array('sql' => $this->getAddKey($table, $item), 'action' => 'add_key');
                        }
                    }
                    //Search for deletion
                    foreach ($test2 as $key => $item) {
                        if (!$this->haveKey($item, $test1)) {
                            $actions[] = array(
                                'sql' => $this->getDropKey($table, $item),
                                'action' => 'drop_key'
                            );
                        }
                    }

                    $test1 = $value['unique'];
                    $test2 = $dbTable['unique'];
                    foreach ($test1 as $key => $item) {
                        if (!$this->haveUnique($item, $test2)) {
                            $actions[] = array('sql' => $this->getAddKey($table, $item), 'action' => 'add_unique');
                        }
                    }
                    //Search for deletion
                    foreach ($test2 as $key => $item) {
                        if (!$this->haveKey($item, $test1)) {
                            $actions[] = array(
                                'sql' => $this->getDropKey($table, $item),
                                'action' => 'drop_unique'
                            );
                        }
                    }

                }
            } else {
                //                if(!$value instanceof \stdClass) die_stack_trace();
                $actions[] = array('sql' => $this->getCreateTable($value), 'action' => 'create_table');
            }
        }
        if ($current) {
            foreach ($current as $table => $value) {
                if (!isset($excepted[$table]) && $drop) {
                    $actions[] = array('sql' => $this->getDropTable($value), 'action' => 'drop_table');
                }
            }
        }
        return $actions;
    }
534738
protected function compareStructures(): bool
    {
        if (empty($this->_appliedChanges)) {
            return true;
        }

        $different = false;

        if ($this->showOnly) {
            echo "SHOWING DIFFERENCES:\n";
        }

        foreach ($this->table->columns as $name => $column) {
            if (!isset($this->oldTable->columns[$name])) {
                if ($this->showOnly) {
                    echo "   - missing column '$name'\n";
                } else {
                    $this->plan->addColumn[$name] = $column;
                }

                $different = true;

                continue;
            }

            foreach (['type', 'isNotNull', 'length', 'isUnique', 'isUnsigned', 'default', 'append', 'comment'] as $property) {
                if ($this->generalSchema && $property === 'length') {
                    continue;
                }

                if (
                    !$this->generalSchema
                    && $property === 'append'
                    && $column->append === null
                    && !$this->table->primaryKey->isComposite()
                    && $column->isColumnInPK($this->table->primaryKey)
                ) {
                    $column->append = $column->prepareSchemaAppend(true, $column->autoIncrement);
                }

                if ($this->oldTable->columns[$name]->$property !== $column->$property) {
                    if ($this->showOnly) {
                        echo "   - different '$name' column property: $property (";
                        echo 'DB: ' . $this->displayValue($column->$property) . ' <> ';
                        echo 'MIG: ' . $this->displayValue($this->oldTable->columns[$name]->$property) . ")\n";

                        if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                            echo "   (!) ALTER COLUMN is not supported by SQLite: Migration must be created manually\n";
                        }
                    } elseif (!isset($this->plan->alterColumn[$name])) {
                        if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                            throw new NotSupportedException('ALTER COLUMN is not supported by SQLite.');
                        }

                        $this->plan->alterColumn[$name] = $column;
                    }

                    $different = true;
                }
            }
        }

        foreach ($this->oldTable->columns as $name => $column) {
            if (!isset($this->table->columns[$name])) {
                if ($this->showOnly) {
                    echo "   - excessive column '$name'\n";

                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        echo "   (!) DROP COLUMN is not supported by SQLite: Migration must be created manually\n";
                    }
                } else {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('DROP COLUMN is not supported by SQLite.');
                    }

                    $this->plan->dropColumn[] = $name;
                }

                $different = true;
            }
        }

        foreach ($this->table->foreignKeys as $name => $foreignKey) {
            if (!isset($this->oldTable->foreignKeys[$name])) {
                if ($this->showOnly) {
                    echo "   - missing foreign key '$name'\n";

                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        echo "   (!) ADD FOREIGN KEY is not supported by SQLite: Migration must be created manually\n";
                    }
                } else {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('ADD FOREIGN KEY is not supported by SQLite.');
                    }

                    $this->plan->addForeignKey[$name] = $foreignKey;
                }

                $different = true;

                continue;
            }

            $tableFKColumns = !empty($this->table->foreignKeys[$name]->columns) ? $this->table->foreignKeys[$name]->columns : [];
            $oldTableFKColumns = !empty($this->oldTable->foreignKeys[$name]->columns) ? $this->oldTable->foreignKeys[$name]->columns : [];

            if (
                count(
                    array_merge(
                        array_diff($tableFKColumns, array_intersect($tableFKColumns, $oldTableFKColumns)),
                        array_diff($oldTableFKColumns, array_intersect($tableFKColumns, $oldTableFKColumns))
                    )
                )
            ) {
                if ($this->showOnly) {
                    echo "   - different foreign key '$name' columns (";
                    echo 'DB: (' . implode(', ', $tableFKColumns) . ') <> ';
                    echo 'MIG: (' . implode(', ', $oldTableFKColumns) . "))\n";

                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        echo "   (!) DROP/ADD FOREIGN KEY is not supported by SQLite: Migration must be created manually\n";
                    }
                } else {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('DROP/ADD FOREIGN KEY is not supported by SQLite.');
                    }

                    $this->plan->dropForeignKey[] = $name;
                    $this->plan->addForeignKey[$name] = $foreignKey;
                }

                $different = true;

                continue;
            }

            $tableFKRefColumns = !empty($this->table->foreignKeys[$name]->refColumns) ? $this->table->foreignKeys[$name]->refColumns : [];
            $oldTableFKRefColumns = !empty($this->oldTable->foreignKeys[$name]->refColumns) ? $this->oldTable->foreignKeys[$name]->refColumns : [];

            if (
                count(
                    array_merge(
                        array_diff($tableFKRefColumns, array_intersect($tableFKRefColumns, $oldTableFKRefColumns)),
                        array_diff($oldTableFKRefColumns, array_intersect($tableFKRefColumns, $oldTableFKRefColumns))
                    )
                )
            ) {
                if ($this->showOnly) {
                    echo "   - different foreign key '$name' referral columns (";
                    echo 'DB: (' . implode(', ', $tableFKRefColumns) . ') <> ';
                    echo 'MIG: (' . implode(', ', $oldTableFKRefColumns) . "))\n";

                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        echo "   (!) DROP/ADD FOREIGN KEY is not supported by SQLite: Migration must be created manually\n";
                    }
                } else {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('DROP/ADD FOREIGN KEY is not supported by SQLite.');
                    }

                    $this->plan->dropForeignKey[] = $name;
                    $this->plan->addForeignKey[$name] = $foreignKey;
                }

                $different = true;
            }
        }

        foreach ($this->oldTable->foreignKeys as $name => $foreignKey) {
            if (!isset($this->table->foreignKeys[$name])) {
                if ($this->showOnly) {
                    echo "   - excessive foreign key '$name'\n";

                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        echo "   (!) DROP FOREIGN KEY is not supported by SQLite: Migration must be created manually\n";
                    }
                } else {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('DROP FOREIGN KEY is not supported by SQLite.');
                    }

                    $this->plan->dropForeignKey[] = $name;
                }

                $different = true;
            }
        }

        $tablePKColumns = !empty($this->table->primaryKey->columns) ? $this->table->primaryKey->columns : [];
        $oldTablePKColumns = !empty($this->oldTable->primaryKey->columns) ? $this->oldTable->primaryKey->columns : [];

        $newKeys = array_merge(
            array_diff($tablePKColumns, array_intersect($tablePKColumns, $oldTablePKColumns)),
            array_diff($oldTablePKColumns, array_intersect($tablePKColumns, $oldTablePKColumns))
        );

        if (count($newKeys)) {
            if ($this->showOnly) {
                echo "   - different primary key definition\n";

                if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                    echo "   (!) DROP/ADD PRIMARY KEY is not supported by SQLite: Migration must be created manually\n";
                }
            } else {
                if (!empty($this->oldTable->primaryKey->columns)) {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('DROP PRIMARY KEY is not supported by SQLite.');
                    }

                    $this->plan->dropPrimaryKey = $this->oldTable->primaryKey->name ?: TablePrimaryKey::GENERIC_PRIMARY_KEY;
                }

                if (!empty($this->table->primaryKey->columns) && $this->confirmCompositePrimaryKey($newKeys)) {
                    if ($this->table->getSchema() === TableStructure::SCHEMA_SQLITE) {
                        throw new NotSupportedException('ADD PRIMARY KEY is not supported by SQLite.');
                    }

                    $this->plan->addPrimaryKey = $this->table->primaryKey;
                }
            }

            $different = true;
        }

        foreach ($this->table->indexes as $name => $index) {
            if (!isset($this->oldTable->indexes[$name])) {
                if ($this->showOnly) {
                    echo "   - missing index '$name'\n";
                } else {
                    $this->plan->createIndex[$name] = $index;
                }

                $different = true;

                continue;
            }

            if ($this->oldTable->indexes[$name]->unique !== $this->table->indexes[$name]->unique) {
                if ($this->showOnly) {
                    echo "   - different index '$name' definition (";
                    echo 'DB: unique ' . $this->displayValue($this->table->indexes[$name]->unique) . ' <> ';
                    echo 'MIG: unique ' . $this->displayValue($this->oldTable->indexes[$name]->unique) . ")\n";
                } else {
                    $this->plan->dropIndex[] = $name;
                    $this->plan->createIndex[$name] = $index;
                }

                $different = true;

                continue;
            }

            $tableIndexColumns = !empty($this->table->indexes[$name]->columns) ? $this->table->indexes[$name]->columns : [];
            $oldTableIndexColumns = !empty($this->oldTable->indexes[$name]->columns) ? $this->oldTable->indexes[$name]->columns : [];

            if (
                count(
                    array_merge(
                        array_diff($tableIndexColumns, array_intersect($tableIndexColumns, $oldTableIndexColumns)),
                        array_diff($oldTableIndexColumns, array_intersect($tableIndexColumns, $oldTableIndexColumns))
                    )
                )
            ) {
                if ($this->showOnly) {
                    echo "   - different index '$name' columns (";
                    echo 'DB: (' . implode(', ', $tableIndexColumns) . ') <> ';
                    echo 'MIG: (' . implode(', ', $oldTableIndexColumns) . "))\n";
                } else {
                    $this->plan->dropIndex[] = $name;
                    $this->plan->createIndex[$name] = $index;
                }

                $different = true;
            }
        }

        foreach ($this->oldTable->indexes as $name => $index) {
            if (!isset($this->table->indexes[$name])) {
                if ($this->showOnly) {
                    echo "   - excessive index '$name'\n";
                } else {
                    $this->plan->dropIndex[] = $name;
                }

                $different = true;
            }
        }

        return $different;
    }
336444
public function getTables($dbType, $dbDescription)
    {
        $db = $this->_connect($dbType, $dbDescription);
        return $db->listTables();
    }
873445
public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
    {
        $table = $this->getTablePrefix().$blueprint->getTable();

        return tap(new TableDiff($table), function ($tableDiff) use ($schema, $table) {
            $tableDiff->fromTable = $schema->listTableDetails($table);
        });
    }
540679
protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql)
    {
        if ($this->_eventManager === null) {
            return false;
        }

        if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) {
            return false;
        }

        $eventArgs = new SchemaAlterTableAddColumnEventArgs($column, $diff, $this);
        $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableAddColumn, $eventArgs);

        $columnSql = array_merge($columnSql, $eventArgs->getSql());

        return $eventArgs->isDefaultPrevented();
    }
1015627
private function getAlterColumnClausesSQL(ColumnDiff $columnDiff)
    {
        $column = $columnDiff->column->toArray();

        $alterClause = 'ALTER COLUMN ' . $columnDiff->column->getQuotedName($this);

        if ($column['columnDefinition']) {
            return [$alterClause . ' ' . $column['columnDefinition']];
        }

        $clauses = [];

        if ($columnDiff->hasChanged('type') ||
            $columnDiff->hasChanged('length') ||
            $columnDiff->hasChanged('precision') ||
            $columnDiff->hasChanged('scale') ||
            $columnDiff->hasChanged('fixed')
        ) {
            $clauses[] = $alterClause . ' SET DATA TYPE ' . $column['type']->getSQLDeclaration($column, $this);
        }

        if ($columnDiff->hasChanged('notnull')) {
            $clauses[] = $column['notnull'] ? $alterClause . ' SET NOT NULL' : $alterClause . ' DROP NOT NULL';
        }

        if ($columnDiff->hasChanged('default')) {
            if (isset($column['default'])) {
                $defaultClause = $this->getDefaultValueDeclarationSQL($column);

                if ($defaultClause) {
                    $clauses[] = $alterClause . ' SET' . $defaultClause;
                }
            } else {
                $clauses[] = $alterClause . ' DROP DEFAULT';
            }
        }

        return $clauses;
    }