diff --git a/src/Sql/SqlBase.php b/src/Sql/SqlBase.php index 98b7b05620..cd69d2fc59 100644 --- a/src/Sql/SqlBase.php +++ b/src/Sql/SqlBase.php @@ -121,7 +121,7 @@ public static function getInstance($db_spec, $options): ?self $driver = $db_spec['driver']; $class_name = 'Drush\Sql\Sql' . ucfirst($driver); if (class_exists($class_name)) { - $instance = new $class_name($db_spec, $options); + $instance = method_exists($class_name, 'make') ? $class_name::make($db_spec, $options) : new $class_name($db_spec, $options); // Inject config $instance->setConfig(Drush::config()); return $instance; diff --git a/src/Sql/SqlMariaDB.php b/src/Sql/SqlMariaDB.php new file mode 100644 index 0000000000..ed66a3b66a --- /dev/null +++ b/src/Sql/SqlMariaDB.php @@ -0,0 +1,20 @@ +alwaysQuery($sql); + $out = trim($instance->getProcess()->getOutput()); + if (str_contains($out, 'MariaDB')) { + // Replace with a MariaDB driver. + $instance = new SqlMariaDB($dbSpec, $options); + } + $instance->setVersion($out); + return $instance; + } + public function command(): string { return 'mysql'; } + public function dumpProgram(): string + { + return 'mysqldump'; + } + + /** + * The server version. + */ + public function getVersion(): string + { + return $this->version; + } + + public function setVersion(string $version): void + { + $this->version = $version; + } + public function creds($hide_password = true): string { $dbSpec = $this->getDbSpec(); @@ -160,7 +198,7 @@ public function dumpCmd($table_selection): string // The ordered-dump option is only supported by MySQL for now. $ordered_dump = $this->getOption('ordered-dump'); - $exec = 'mysqldump '; + $exec = $this->dumpProgram() . ' '; // mysqldump wants 'databasename' instead of 'database=databasename' for no good reason. $only_db_name = str_replace('--database=', ' ', $this->creds()); $exec .= $only_db_name;