Drop several tables at once

@param array $tables
@param boolean $fkChecks Whether to enabled Foreign Key checks
@return boolean
433
final public function dropTables(array $tables, $fkChecks = false)
    {
        // Whether FK checks are enabled
        if ($fkChecks == false) {
            $this->db->raw('SET FOREIGN_KEY_CHECKS=0')
                     ->execute();
        }

        foreach ($tables as $table) {
            if (!$this->dropTable($table)) {
                return false;
            }
        }

        // Whether FK checks are enabled
        if ($fkChecks == false) {
            $this->db->raw('SET FOREIGN_KEY_CHECKS=1')
                     ->execute();
        }

        return true;
    }
427345
private function sort(array $tables, $sort, $reverseSort)
    {
        switch ($sort) {
            case 'name':
                ksort($tables);
                break;

            case 'size':
                uasort(
                    $tables,
                    function ($a, $b) {
                        return $a['size'] > $b['size'];
                    }
                );
                break;

            default:
                throw new Exception\DomainException("Invalid sort option \"$sort\".");
        }

        if ($reverseSort) {
            $tables = array_reverse($tables, true);
        }

        return $tables;
    }
124978
public function actionDrop()
    {
        $stdout = '';
        foreach ($this->db->schema->getTableSchemas() as $table) {
            if ($table->name === $this->migrationTable) {
                continue;
            }
            $stdout .= static::generateDropTable($table->name);
            if (!empty($table->foreignKeys)) {
                $stdout .= ' // fk: ';

                foreach ($table->foreignKeys as $fk) {
                    foreach ($fk as $k => $v) {
                        if (0 === $k) {
                            continue;
                        }
                        $stdout .= "$k, ";
                    }
                }
                $stdout = rtrim($stdout, ', ');
            }
            $stdout .= "\n";
        }
        $this->stdout($stdout);
    }
827192
private function throwTableExceptions($tables, $requestedTables)
    {
        $foundTables = [];
        foreach ($tables as $table) {
            $foundTables[] = $table['name'];
        }

        foreach ($requestedTables as $requestedTable) {
            if (array_search($requestedTable, $foundTables) === false) {
                throw new exceptions\TableNotFoundException($requestedTable
                    ? "$requestedTable not found on target database."
                    : 'Please specify a table name.'
                );
            }
        }
    }
1324934
public function truncate(array $tables = null)
    {
        if (null === $this->db) {
            return;
        }

        if (null === $tables) {
            $tables = $this->tables;
        }

        foreach ($tables as $table) {
            $this->db->query("DELETE FROM $table");
        }

        $this->tables = array_diff($this->tables, $tables);
    }
228104
protected function isRelationTable($table)
	{
		$pk=$table->primaryKey;
        $count=is_array($pk) ? count($pk) : 1;
        return ($count === 2 // we want 2 columns
			&& isset($table->foreignKeys[$pk[0]]) // pk column 1 is also a foreign key
			&& isset($table->foreignKeys[$pk[1]]) // pk column 2 is also a foriegn key
			&& $table->foreignKeys[$pk[0]][0] !== $table->foreignKeys[$pk[1]][0]); // and the foreign keys point different tables
	}
877011
private function getTableChecksum($tables)
    {
        $tables = is_array($tables) ? $tables : array($tables);
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
        $query = 'CHECKSUM TABLE ' . implode(", ", $tables);
        $results = $database->getAll($query);

        $databaseName = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dbName');
        $checksum = array();
        foreach ($results as $result) {
            $table = str_replace($databaseName . '.', '', $result['Table']);
            $checksum[$table] = $result['Checksum'];
        }

        return $checksum;
    }
1038833
static function remove_bindings(\fenrir\system\MysqlDatabaseSignature $db, $table, array $bindings) {
		foreach ($bindings as $key) {
			$db->prepare
				(
					"
						ALTER TABLE `$table`
						 DROP FOREIGN KEY `$key`
					"
				)
				->execute();
		}
	}
268419
protected function createTableRelations(array $tables)
    {
        /** @var TableMigration $tableObject */
        foreach ($tables as $tableObject) {
            $tableObject->relateToOtherTables($tables);
        } // foreach

        return $this->sortTablesWithFKsToEnd($tables);
    }
847546
public function dropSchema(array $classes)
    {
        $dropSchemaSql = $this->getDropSchemaSQL($classes);
        $conn          = $this->em->getConnection();

        foreach ($dropSchemaSql as $sql) {
            try {
                $conn->executeQuery($sql);
            } catch (Throwable $e) {
                // ignored
            }
        }
    }
493798
public function delete_many(array $keys) {
        $count = 0;
        foreach ($keys as $key) {
            if (!is_array($key)) {
                $key = array('key' => $key);
            }
            $key = $key['key'];
            if (isset($this->store[$key])) {
                $count++;
            }
            unset($this->store[$key]);
        }
        if ($this->maxsize !== false) {
            $this->storecount -= $count;
        }
        return $count;
    }
253742
public function lockTables($tables)
    {
        /**
         * Unlock any previously locked tables
         * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
         * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
         */
        $this->unlockTables();

        $tables = Helper::toArray($tables);

        if ($this->mode == "odbc") {
            foreach ($tables as $table) {
                $table = $this->getTableName($table);
                $query = "LOCK TABLE " . $table . " IN EXCLUSIVE MODE ALLOW READ";
                $this->query($query);
            }

            # If none of the locks failed then report success
            return true;
        }

        foreach ($tables as &$table) {
            $table = $this->getTableName($table);
        }
        unset($table);

        if ($this->mode == "mysql") {
            $query = "LOCK TABLES " . implode(",", $tables) . " WRITE";
            return $this->query($query);
        }

        if (in_array($this->mode, ["postgres", "redshift"], true)) {
            $query = "LOCK TABLE " . implode(",", $tables) . " IN EXCLUSIVE MODE";
            return $this->query($query);
        }

        throw new \Exception("lockTables() not supported in this mode (" . $this->mode . ")");
    }
953713
public function foreignKeyCheck ($check = true)
		{
			$check = intval(boolval($check));
			$this->db->createCommand("SET FOREIGN_KEY_CHECKS=$check")->execute();
		}
223113
protected function reorderTables($tables, $relations)
    {
        $depencies = $orders = $result = [];
        foreach ($relations as $table => $relation) {
            if (isset($relation[$table])) {
                unset($relation[$table]);
            }
            $depencies[$table] = array_keys($relation);
        }
        $tableNames = array_keys($tables);
        sort($tableNames);
        $this->reorderRecrusive($tableNames, $depencies, $orders);
        foreach (array_keys($orders) as $value) {
            if (isset($tables[$value])) {
                $result[] = $tables[$value];
            }
        }
        return $result;
    }
712608
private function getTableChecksum($tables)
    {
        $tables = is_array($tables) ? $tables : array($tables);
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
        $select = 'CHECKSUM TABLE ' . implode(", ", $tables);
        $results = $database->getAll($select);

        $sDbName = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\ConfigFile::class)->getVar('dbName');
        $checksum = array();
        foreach ($results as $result) {
            $table = str_replace($sDbName . '.', '', $result['Table']);
            $checksum[$table] = $result['Checksum'];
        }

        return $checksum;
    }
869333
protected function filterAndSeparateForeignKeys($foreignKeys, $table)
    {
        $results = ['local' => [], 'remote' => []];
        foreach ($foreignKeys as $foreignKey) {
            if ($foreignKey->TABLE_NAME == $table) {
                $results['local'][] = $foreignKey;
            }
            if ($foreignKey->REFERENCED_TABLE_NAME == $table) {
                $results['remote'][] = $foreignKey;
            }
        }

        return $results;
    }
200731
public function checkTables(array $tables)
    {
        $check = implode(',', $tables);

        $result = $this->getConnection()->pdo()->query("CHECK TABLE $check");

        return $result ? $result->fetchAll(PDO::FETCH_ASSOC) : $result;
    }