Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
commit
79affae9f9
@ -775,7 +775,7 @@ final class Import
|
||||
$size = 10;
|
||||
}
|
||||
|
||||
$tempSQLStr .= Util::backquote($column) . ' ' . match ($analyses[$i][$j]->type) {
|
||||
$colType = match ($analyses[$i][$j]->type) {
|
||||
ColumnType::None => 'NULL',
|
||||
ColumnType::Varchar => 'varchar',
|
||||
ColumnType::Int => 'int',
|
||||
@ -783,7 +783,17 @@ final class Import
|
||||
ColumnType::BigInt => 'bigint',
|
||||
ColumnType::Geometry => 'geometry',
|
||||
};
|
||||
if ($analyses[$i][$j]->type !== ColumnType::Geometry) {
|
||||
|
||||
// Use TEXT instead of VARCHAR when the length exceeds
|
||||
// the maximum allowed for VARCHAR. The limit depends on
|
||||
// the charset (e.g. 16383 for utf8mb4, 65535 for latin1).
|
||||
// We use the most restrictive limit (utf8mb4) to be safe.
|
||||
if ($colType === 'varchar' && $size > 16383) {
|
||||
$colType = 'text';
|
||||
}
|
||||
|
||||
$tempSQLStr .= Util::backquote($column) . ' ' . $colType;
|
||||
if ($colType !== 'text' && $analyses[$i][$j]->type !== ColumnType::Geometry) {
|
||||
$tempSQLStr .= '(' . $size . ')';
|
||||
}
|
||||
|
||||
|
||||
@ -853,6 +853,13 @@ class ExportSql extends ExportPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip CREATE DATABASE when only exporting data
|
||||
if (! $this->includeStructure()) {
|
||||
$this->exportUseStatement($dbAlias, $this->compatibility);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$createQuery = 'CREATE DATABASE IF NOT EXISTS '
|
||||
. Util::backquoteCompat($dbAlias, $this->compatibility, $this->useSqlBackquotes);
|
||||
$collation = $this->dbi->getDbCollation($db);
|
||||
|
||||
@ -230,7 +230,6 @@ class ExportTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
$expected = <<<'SQL'
|
||||
CREATE DATABASE IF NOT EXISTS test_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
USE test_db;
|
||||
|
||||
INSERT INTO test_table (id, name, datetimefield) VALUES
|
||||
|
||||
@ -512,6 +512,33 @@ final class ExportSqlTest extends AbstractTestCase
|
||||
self::assertStringContainsString('USE db;', $result);
|
||||
}
|
||||
|
||||
public function testExportDBCreateDataOnly(): void
|
||||
{
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
|
||||
->withParsedBody([
|
||||
'sql_backquotes' => 'true',
|
||||
'sql_compatibility' => 'NONE',
|
||||
'sql_structure_or_data' => 'data',
|
||||
]);
|
||||
|
||||
$dbi = $this->getMockBuilder(DatabaseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects(self::any())->method('quoteString')
|
||||
->willReturnCallback(static fn (string $string): string => "'" . $string . "'");
|
||||
|
||||
$exportSql = $this->getExportSql($dbi);
|
||||
$exportSql->setExportOptions($request, new Export());
|
||||
|
||||
ob_start();
|
||||
$exportSql->exportDBCreate('db');
|
||||
$result = ob_get_clean();
|
||||
|
||||
self::assertIsString($result);
|
||||
self::assertStringNotContainsString('CREATE DATABASE', $result);
|
||||
self::assertStringContainsString('USE `db`;', $result);
|
||||
}
|
||||
|
||||
public function testExportDBHeader(): void
|
||||
{
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user