19declare(strict_types=1);
30 'STRICT_TRANS_TABLES',
35 'ERROR_FOR_DIVISION_BY_ZERO',
36 'NO_ENGINE_SUBSTITUTION',
54 $this->pdo->exec(
"SET SESSION sql_mode = '" . implode(
",", $this->modes) .
"';");
70 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY =>
true,
71 PDO::ATTR_TIMEOUT => 300 * 60,
78 $this->pdo->exec(
"ALTER TABLE {$table_name} ENGINE={$engine}");
80 $this->pdo->exec(
"ALTER TABLE {$table_name}_seq ENGINE={$engine}");
82 }
catch (PDOException
$e) {
93 $engines = $this->
queryCol(
'SHOW ENGINES');
94 if (!in_array($engine, $engines,
true)) {
99 array_walk($tables,
function (
string $table_name) use (&$errors, $engine):
void {
101 $this->pdo->exec(
"ALTER TABLE $table_name ENGINE=$engine");
103 $this->pdo->exec(
"ALTER TABLE {$table_name}_seq ENGINE=$engine");
105 }
catch (Exception
$e) {
106 $errors[$table_name] =
$e->getMessage();
117 $collation_split = explode(
"_", $collation);
118 $character = $collation_split[0] ??
'utf8mb4';
119 $collate = $collation;
120 $q =
"ALTER TABLE {$this->quoteIdentifier($table_name)} CONVERT TO CHARACTER SET {$character} COLLATE {$collate};";
122 $this->pdo->exec(
$q);
123 }
catch (PDOException) {
137 foreach ($manager->listTables() as $table_name) {
138 if (!$this->migrateTableCollation($table_name, $collation)) {
139 $errors[] = $table_name;
157 $sequence_name = $this->quoteIdentifier($this->getSequenceName($table_name),
true);
158 $seqcol_name = $this->quoteIdentifier(
'sequence');
159 $query =
"INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
161 $this->pdo->exec($query);
162 }
catch (PDOException) {
166 $result = $this->query(
'SELECT LAST_INSERT_ID() AS next');
167 $value = $result->fetchObject()->next;
169 if (is_numeric($value)) {
170 $query =
"DELETE FROM $sequence_name WHERE $seqcol_name < $value";
171 $this->pdo->exec($query);
const MYSQL_ENGINE_INNODB
const MYSQL_COLLATION_UTF8MB4
Class ilDBPdoMySQLFieldDefinition.
getAdditionalAttributes()
nextId(string $table_name)
supportsCollationMigration()
@inheritDoc
doesCollationSupportMB4Strings()
@inheritDoc
migrateTableCollation(string $table_name, string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
migrateTableToEngine(string $table_name, string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
migrateAllTablesToCollation(string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
@inheritDoc
supportsEngineMigration()
migrateAllTablesToEngine(string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
sequenceExists(string $sequence)
queryCol(string $query, int $type=PDO::FETCH_ASSOC, int $colnum=0)
Class ilDatabaseException.