Remove sql_* global variables

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2024-12-20 12:20:00 -03:00
parent 038c59b1bf
commit 75d11f910b
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
9 changed files with 178 additions and 240 deletions

View File

@ -12564,7 +12564,7 @@ parameters:
-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 34
count: 27
path: src/Plugins/Export/ExportSql.php
-
@ -12579,6 +12579,12 @@ parameters:
count: 1
path: src/Plugins/Export/ExportSql.php
-
message: '#^Method PhpMyAdmin\\Plugins\\Export\\ExportSql\:\:setMaxQuerySize\(\) should return int\<0, max\> but returns int\.$#'
identifier: return.type
count: 2
path: src/Plugins/Export/ExportSql.php
-
message: '#^Only booleans are allowed in &&, bool\|null given on the left side\.$#'
identifier: booleanAnd.leftNotBoolean
@ -12591,12 +12597,6 @@ parameters:
count: 1
path: src/Plugins/Export/ExportSql.php
-
message: '#^Only booleans are allowed in &&, mixed given on the right side\.$#'
identifier: booleanAnd.rightNotBoolean
count: 4
path: src/Plugins/Export/ExportSql.php
-
message: '#^Only booleans are allowed in an if condition, bool\|null given\.$#'
identifier: if.condNotBoolean
@ -21699,7 +21699,7 @@ parameters:
-
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 4
count: 2
path: tests/unit/Plugins/Export/ExportSqlTest.php
-

View File

@ -1458,22 +1458,6 @@
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['single_table']]]></code>
<code><![CDATA[$GLOBALS['single_table']]]></code>
<code><![CDATA[$GLOBALS['sql_auto_increment']]]></code>
<code><![CDATA[$GLOBALS['sql_create_trigger']]]></code>
<code><![CDATA[$GLOBALS['sql_delayed']]]></code>
<code><![CDATA[$GLOBALS['sql_drop_database']]]></code>
<code><![CDATA[$GLOBALS['sql_hex_for_binary']]]></code>
<code><![CDATA[$GLOBALS['sql_if_not_exists']]]></code>
<code><![CDATA[$GLOBALS['sql_ignore']]]></code>
<code><![CDATA[$GLOBALS['sql_insert_syntax']]]></code>
<code><![CDATA[$GLOBALS['sql_max_query_size']]]></code>
<code><![CDATA[$GLOBALS['sql_metadata']]]></code>
<code><![CDATA[$GLOBALS['sql_or_replace_view']]]></code>
<code><![CDATA[$GLOBALS['sql_simple_view_export']]]></code>
<code><![CDATA[$GLOBALS['sql_truncate']]]></code>
<code><![CDATA[$GLOBALS['sql_utc_time']]]></code>
<code><![CDATA[$GLOBALS['sql_view_current_user']]]></code>
<code><![CDATA[$GLOBALS['sql_views_as_tables']]]></code>
<code><![CDATA[$GLOBALS['table_data']]]></code>
<code><![CDATA[$GLOBALS['table_data']]]></code>
<code><![CDATA[$GLOBALS['table_select']]]></code>
@ -4866,10 +4850,6 @@
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['sql_create_trigger']]]></code>
<code><![CDATA[$GLOBALS['sql_create_trigger']]]></code>
<code><![CDATA[$GLOBALS['sql_metadata']]]></code>
<code><![CDATA[$GLOBALS['sql_metadata']]]></code>
<code><![CDATA[$GLOBALS['time_start']]]></code>
<code><![CDATA[$GLOBALS['xkana']]]></code>
</InvalidArrayOffset>
@ -7172,31 +7152,15 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['exporting_metadata']]]></code>
<code><![CDATA[$GLOBALS['no_constraints_comments']]]></code>
<code><![CDATA[$GLOBALS['no_constraints_comments']]]></code>
<code><![CDATA[$GLOBALS['sql_auto_increment']]]></code>
<code><![CDATA[$GLOBALS['sql_delayed']]]></code>
<code><![CDATA[$GLOBALS['sql_drop_database']]]></code>
<code><![CDATA[$GLOBALS['sql_drop_foreign_keys']]]></code>
<code><![CDATA[$GLOBALS['sql_if_not_exists']]]></code>
<code><![CDATA[$GLOBALS['sql_if_not_exists']]]></code>
<code><![CDATA[$GLOBALS['sql_if_not_exists']]]></code>
<code><![CDATA[$GLOBALS['sql_ignore']]]></code>
<code><![CDATA[$GLOBALS['sql_ignore']]]></code>
<code><![CDATA[$GLOBALS['sql_indexes_query']]]></code>
<code><![CDATA[$GLOBALS['sql_insert_syntax']]]></code>
<code><![CDATA[$GLOBALS['sql_insert_syntax']]]></code>
<code><![CDATA[$GLOBALS['sql_max_query_size']]]></code>
<code><![CDATA[$GLOBALS['sql_or_replace_view']]]></code>
<code><![CDATA[$GLOBALS['sql_simple_view_export']]]></code>
<code><![CDATA[$GLOBALS['sql_truncate']]]></code>
<code><![CDATA[$GLOBALS['sql_utc_time']]]></code>
<code><![CDATA[$GLOBALS['sql_utc_time']]]></code>
<code><![CDATA[$GLOBALS['sql_view_current_user']]]></code>
<code><![CDATA[$GLOBALS['sql_views_as_tables']]]></code>
<code><![CDATA[$GLOBALS['sql_views_as_tables']]]></code>
<code><![CDATA[$GLOBALS['table_data']]]></code>
</InvalidArrayOffset>
<LessSpecificReturnStatement>
<code><![CDATA[(int) $fromConfig]]></code>
<code><![CDATA[(int) $fromRequest]]></code>
</LessSpecificReturnStatement>
<MixedArgument>
<code><![CDATA[$GLOBALS['table_data']]]></code>
<code><![CDATA[$colAlias]]></code>
@ -7220,8 +7184,6 @@
<code><![CDATA[$row[$j]]]></code>
</MixedArrayTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['sql_drop_foreign_keys']]]></code>
<code><![CDATA[$GLOBALS['sql_indexes_query']]]></code>
<code><![CDATA[$colAlias]]></code>
<code><![CDATA[$colAlias]]></code>
<code><![CDATA[$colAs]]></code>
@ -7234,7 +7196,6 @@
<code><![CDATA[$newTable]]></code>
<code><![CDATA[$relFieldAlias]]></code>
<code><![CDATA[$relFieldAlias]]></code>
<code><![CDATA[$sqlMaxSize]]></code>
<code><![CDATA[$statement->name->database]]></code>
<code><![CDATA[$statement->name->table]]></code>
<code><![CDATA[$statement->table->table]]></code>
@ -7246,6 +7207,9 @@
<code><![CDATA[$field->key->columns]]></code>
<code><![CDATA[$field->references->columns]]></code>
</MixedPropertyTypeCoercion>
<MoreSpecificReturnType>
<code><![CDATA[int<0, max>]]></code>
</MoreSpecificReturnType>
<PossiblyNullArgument>
<code><![CDATA[$createQuery]]></code>
<code><![CDATA[$definition]]></code>
@ -7282,20 +7246,11 @@
<code><![CDATA[remove]]></code>
<code><![CDATA[remove]]></code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$GLOBALS['sql_insert_syntax']]]></code>
</PossiblyUndefinedArrayOffset>
<PossiblyUnusedReturnValue>
<code><![CDATA[bool]]></code>
<code><![CDATA[bool]]></code>
</PossiblyUnusedReturnValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['exporting_metadata'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_auto_increment'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_if_not_exists'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_if_not_exists'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_if_not_exists'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_views_as_tables'])]]></code>
<code><![CDATA[empty($column->collation)]]></code>
<code><![CDATA[empty($config->selectedServer['port'])]]></code>
<code><![CDATA[empty($delimiter)]]></code>
@ -13118,15 +13073,11 @@
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['no_constraints_comments']]]></code>
<code><![CDATA[$GLOBALS['no_constraints_comments']]]></code>
<code><![CDATA[$GLOBALS['sql_drop_foreign_keys']]]></code>
<code><![CDATA[$GLOBALS['sql_if_not_exists']]]></code>
</InvalidArrayOffset>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$config->selectedServer]]></code>
</InvalidPropertyAssignmentValue>
<MixedArgument>
<code><![CDATA[$GLOBALS['sql_drop_foreign_keys']]]></code>
<code><![CDATA[$GLOBALS['sql_drop_foreign_keys']]]></code>
<code><![CDATA[$result]]></code>
</MixedArgument>
<MixedAssignment>

View File

@ -510,70 +510,6 @@ final class ExportController implements InvocableController
$GLOBALS['excel_edition'] = $postParams['excel_edition'];
}
if (isset($postParams['sql_create_trigger'])) {
$GLOBALS['sql_create_trigger'] = $postParams['sql_create_trigger'];
}
if (isset($postParams['sql_view_current_user'])) {
$GLOBALS['sql_view_current_user'] = $postParams['sql_view_current_user'];
}
if (isset($postParams['sql_simple_view_export'])) {
$GLOBALS['sql_simple_view_export'] = $postParams['sql_simple_view_export'];
}
if (isset($postParams['sql_if_not_exists'])) {
$GLOBALS['sql_if_not_exists'] = $postParams['sql_if_not_exists'];
}
if (isset($postParams['sql_or_replace_view'])) {
$GLOBALS['sql_or_replace_view'] = $postParams['sql_or_replace_view'];
}
if (isset($postParams['sql_auto_increment'])) {
$GLOBALS['sql_auto_increment'] = $postParams['sql_auto_increment'];
}
if (isset($postParams['sql_truncate'])) {
$GLOBALS['sql_truncate'] = $postParams['sql_truncate'];
}
if (isset($postParams['sql_delayed'])) {
$GLOBALS['sql_delayed'] = $postParams['sql_delayed'];
}
if (isset($postParams['sql_ignore'])) {
$GLOBALS['sql_ignore'] = $postParams['sql_ignore'];
}
if (isset($postParams['sql_insert_syntax'])) {
$GLOBALS['sql_insert_syntax'] = $postParams['sql_insert_syntax'];
}
if (isset($postParams['sql_max_query_size'])) {
$GLOBALS['sql_max_query_size'] = $postParams['sql_max_query_size'];
}
if (isset($postParams['sql_hex_for_binary'])) {
$GLOBALS['sql_hex_for_binary'] = $postParams['sql_hex_for_binary'];
}
if (isset($postParams['sql_utc_time'])) {
$GLOBALS['sql_utc_time'] = $postParams['sql_utc_time'];
}
if (isset($postParams['sql_drop_database'])) {
$GLOBALS['sql_drop_database'] = $postParams['sql_drop_database'];
}
if (isset($postParams['sql_views_as_tables'])) {
$GLOBALS['sql_views_as_tables'] = $postParams['sql_views_as_tables'];
}
if (isset($postParams['sql_metadata'])) {
$GLOBALS['sql_metadata'] = $postParams['sql_metadata'];
}
if (isset($postParams['csv_separator'])) {
$GLOBALS['csv_separator'] = $postParams['csv_separator'];
}

View File

@ -659,7 +659,7 @@ class Export
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if (
! isset($GLOBALS['sql_create_trigger'])
! ($exportPlugin instanceof ExportSql && $exportPlugin->hasCreateTrigger())
|| $structureOrData === StructureOrData::Data
|| ! in_array($table, $tableStructure, true)
) {
@ -701,7 +701,7 @@ class Export
}
// export metadata related to this db
if (isset($GLOBALS['sql_metadata'])) {
if ($exportPlugin instanceof ExportSql && $exportPlugin->hasMetadata()) {
// Types of metadata to export.
// In the future these can be allowed to be selected by the user
$metadataTypes = $this->getMetadataTypes();
@ -840,7 +840,10 @@ class Export
// now export the triggers (needs to be done after the data because
// triggers can modify already imported tables)
if (isset($GLOBALS['sql_create_trigger']) && $structureOrData !== StructureOrData::Data) {
if (
$exportPlugin instanceof ExportSql && $exportPlugin->hasCreateTrigger()
&& $structureOrData !== StructureOrData::Data
) {
if (! $exportPlugin->exportStructure($db, $table, 'triggers', $aliases)) {
return;
}
@ -850,7 +853,7 @@ class Export
return;
}
if (! isset($GLOBALS['sql_metadata'])) {
if (! ($exportPlugin instanceof ExportSql && $exportPlugin->hasMetadata())) {
return;
}

View File

@ -48,6 +48,7 @@ use function explode;
use function implode;
use function in_array;
use function is_array;
use function is_numeric;
use function is_string;
use function mb_strlen;
use function mb_strpos;
@ -101,6 +102,27 @@ class ExportSql extends ExportPlugin
private string $type = 'INSERT';
private bool $createView = false;
private bool $createTrigger = false;
private bool $viewCurrentUser = false;
private bool $simpleViewExport = false;
private bool $ifNotExists = false;
private bool $orReplaceView = false;
private bool $autoIncrement = false;
private bool $truncate = false;
private bool $delayed = false;
private bool $ignore = false;
/** @var 'complete'|'extended'|'both'|'none' */
private string $insertSyntax = 'both';
/** @var int<0, max> */
private int $maxQuerySize = 50000;
private bool $hexForBinary = false;
private bool $utcTime = false;
private bool $dropDatabase = false;
private bool $viewsAsTables = false;
private bool $metadata = false;
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
@ -703,7 +725,7 @@ class ExportSql extends ExportPlugin
}
/* Restore timezone */
if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) {
if ($this->utcTime) {
DatabaseInterface::getInstance()->query('SET time_zone = "' . $GLOBALS['old_tz'] . '"');
}
@ -768,7 +790,7 @@ class ExportSql extends ExportPlugin
}
/* Change timezone if we should export timestamps in UTC */
if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) {
if ($this->utcTime) {
$head .= 'SET time_zone = "+00:00";' . "\n";
$GLOBALS['old_tz'] = $dbi
->fetchValue('SELECT @@session.time_zone');
@ -819,7 +841,7 @@ class ExportSql extends ExportPlugin
$dbAlias = $db;
}
if ($this->structureOrData !== StructureOrData::Data && isset($GLOBALS['sql_drop_database'])) {
if ($this->structureOrData !== StructureOrData::Data && $this->dropDatabase) {
if (
! $this->export->outputHandler(
'DROP DATABASE IF EXISTS '
@ -1232,7 +1254,7 @@ class ExportSql extends ExportPlugin
$createQuery .= 'CREATE TABLE ';
if (isset($GLOBALS['sql_if_not_exists']) && $GLOBALS['sql_if_not_exists']) {
if ($this->ifNotExists) {
$createQuery .= 'IF NOT EXISTS ';
}
@ -1269,7 +1291,7 @@ class ExportSql extends ExportPlugin
$viewAlias = $view;
$this->initAlias($aliases, $dbAlias, $viewAlias);
$createQuery = 'CREATE TABLE';
if (isset($GLOBALS['sql_if_not_exists'])) {
if ($this->ifNotExists) {
$createQuery .= ' IF NOT EXISTS ';
}
@ -1345,9 +1367,6 @@ class ExportSql extends ExportPlugin
bool $updateIndexesIncrements = true,
array $aliases = [],
): string {
$GLOBALS['sql_indexes_query'] ??= null;
$GLOBALS['sql_drop_foreign_keys'] ??= null;
$dbAlias = $db;
$tableAlias = $table;
$this->initAlias($aliases, $dbAlias, $tableAlias);
@ -1452,12 +1471,12 @@ class ExportSql extends ExportPlugin
// exclude definition of current user
if (
Config::getInstance()->settings['Export']['remove_definer_from_definitions']
|| isset($GLOBALS['sql_view_current_user'])
|| $this->viewCurrentUser
) {
$statement->options->remove('DEFINER');
}
if (isset($GLOBALS['sql_simple_view_export'])) {
if ($this->simpleViewExport) {
$statement->options->remove('SQL SECURITY');
$statement->options->remove('INVOKER');
$statement->options->remove('ALGORITHM');
@ -1467,7 +1486,7 @@ class ExportSql extends ExportPlugin
$createQuery = $statement->build();
// whether to replace existing view or not
if (isset($GLOBALS['sql_or_replace_view'])) {
if ($this->orReplaceView) {
$createQuery = preg_replace('/^CREATE/', 'CREATE OR REPLACE', $createQuery);
}
}
@ -1488,7 +1507,7 @@ class ExportSql extends ExportPlugin
}
// Adding IF NOT EXISTS, if required.
if (isset($GLOBALS['sql_if_not_exists'])) {
if ($this->ifNotExists) {
$createQuery = (string) preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $createQuery);
}
@ -1551,11 +1570,6 @@ class ExportSql extends ExportPlugin
*/
$indexesFulltext = [];
/**
* Fragments containing definition of each foreign key that will be dropped.
*/
$dropped = [];
/**
* Fragment containing definition of the `AUTO_INCREMENT`.
*/
@ -1578,7 +1592,7 @@ class ExportSql extends ExportPlugin
if ($field->key->type === 'FULLTEXT KEY') {
$indexesFulltext[] = $field->build();
unset($statement->fields[$key]);
} elseif (empty($GLOBALS['sql_if_not_exists'])) {
} elseif (! $this->ifNotExists) {
$indexes[] = str_replace(
'COMMENT=\'',
'COMMENT \'',
@ -1590,7 +1604,6 @@ class ExportSql extends ExportPlugin
// Creating the parts that drop foreign keys.
if ($field->key !== null && $field->key->type === 'FOREIGN KEY' && $field->name !== null) {
$dropped[] = 'FOREIGN KEY ' . Context::escape($field->name);
unset($statement->fields[$key]);
}
@ -1599,7 +1612,7 @@ class ExportSql extends ExportPlugin
continue;
}
if (! $field->options->has('AUTO_INCREMENT') || ! empty($GLOBALS['sql_if_not_exists'])) {
if (! $field->options->has('AUTO_INCREMENT') || $this->ifNotExists) {
continue;
}
@ -1637,10 +1650,9 @@ class ExportSql extends ExportPlugin
}
// Generating indexes-related query.
$GLOBALS['sql_indexes_query'] = '';
$indexesQuery = '';
if ($indexes !== []) {
$GLOBALS['sql_indexes_query'] .= $alterHeader . "\n" . ' ADD '
$indexesQuery .= $alterHeader . "\n" . ' ADD '
. implode(',' . "\n" . ' ADD ', $indexes)
. $alterFooter;
}
@ -1649,7 +1661,7 @@ class ExportSql extends ExportPlugin
// InnoDB supports one FULLTEXT index creation at a time.
// So FULLTEXT indexes are created one-by-one after other
// indexes where created.
$GLOBALS['sql_indexes_query'] .= $alterHeader
$indexesQuery .= $alterHeader
. ' ADD ' . implode($alterFooter . $alterHeader . ' ADD ', $indexesFulltext)
. $alterFooter;
}
@ -1661,14 +1673,7 @@ class ExportSql extends ExportPlugin
__('Indexes for table'),
$tableAlias,
$this->compatibility,
) . $GLOBALS['sql_indexes_query'];
}
// Generating drop foreign keys-related query.
if ($dropped !== []) {
$GLOBALS['sql_drop_foreign_keys'] = $alterHeader . "\n" . ' DROP '
. implode(',' . "\n" . ' DROP ', $dropped)
. $alterFooter;
) . $indexesQuery;
}
// Generating auto-increment-related query.
@ -1676,7 +1681,7 @@ class ExportSql extends ExportPlugin
$sqlAutoIncrementsQuery = $alterHeader . "\n" . ' MODIFY '
. implode(',' . "\n" . ' MODIFY ', $autoIncrement);
if (
isset($GLOBALS['sql_auto_increment'])
$this->autoIncrement
&& $statement->entityOptions->has('AUTO_INCREMENT')
&& (! isset($GLOBALS['table_data']) || in_array($table, $GLOBALS['table_data']))
) {
@ -1699,8 +1704,7 @@ class ExportSql extends ExportPlugin
// too.
if (
$statement->entityOptions !== null
&& (empty($GLOBALS['sql_if_not_exists'])
|| empty($GLOBALS['sql_auto_increment']))
&& (! $this->ifNotExists || ! $this->autoIncrement)
) {
$statement->entityOptions->remove('AUTO_INCREMENT');
}
@ -1939,7 +1943,7 @@ class ExportSql extends ExportPlugin
break;
case 'create_view':
if (empty($GLOBALS['sql_views_as_tables'])) {
if (! $this->viewsAsTables) {
$dump .= $this->exportComment(
__('Structure for view')
. ' '
@ -1970,7 +1974,7 @@ class ExportSql extends ExportPlugin
$dump .= $this->getTableDefForView($db, $table, $aliases);
}
if (empty($GLOBALS['sql_views_as_tables'])) {
if (! $this->viewsAsTables) {
// Save views, to be inserted after indexes
// in case the view uses USE INDEX syntax
$this->sqlViews .= $dump;
@ -2025,7 +2029,7 @@ class ExportSql extends ExportPlugin
// Do not export data for a VIEW, unless asked to export the view as a table
// (For a VIEW, this is called only when exporting a single VIEW)
if ($dbi->getTable($db, $table)->isView() && empty($GLOBALS['sql_views_as_tables'])) {
if ($dbi->getTable($db, $table)->isView() && ! $this->viewsAsTables) {
$head = $this->possibleCRLF()
. $this->exportComment()
. $this->exportComment('VIEW ' . $formattedTableName)
@ -2074,7 +2078,7 @@ class ExportSql extends ExportPlugin
if ($this->type === 'UPDATE') {
// update
$schemaInsert = 'UPDATE ';
if (isset($GLOBALS['sql_ignore'])) {
if ($this->ignore) {
$schemaInsert .= 'IGNORE ';
}
@ -2089,19 +2093,19 @@ class ExportSql extends ExportPlugin
}
// delayed inserts?
if (isset($GLOBALS['sql_delayed'])) {
if ($this->delayed) {
$insertDelayed = ' DELAYED';
} else {
$insertDelayed = '';
}
// insert ignore?
if (isset($GLOBALS['sql_ignore']) && $this->type === 'INSERT') {
if ($this->ignore && $this->type === 'INSERT') {
$insertDelayed .= ' IGNORE';
}
//truncate table before insert
if (isset($GLOBALS['sql_truncate']) && $GLOBALS['sql_truncate'] && $sqlCommand === 'INSERT') {
if ($this->truncate && $sqlCommand === 'INSERT') {
$truncate = 'TRUNCATE TABLE '
. Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes) . ';';
$truncatehead = $this->possibleCRLF()
@ -2117,7 +2121,7 @@ class ExportSql extends ExportPlugin
}
// scheme for inserting fields
if ($GLOBALS['sql_insert_syntax'] === 'complete' || $GLOBALS['sql_insert_syntax'] === 'both') {
if ($this->insertSyntax === 'complete' || $this->insertSyntax === 'both') {
$fields = implode(', ', $fieldSet);
$schemaInsert = $sqlCommand . $insertDelayed . ' INTO '
. Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes)
@ -2132,11 +2136,7 @@ class ExportSql extends ExportPlugin
//\x08\\x09, not required
$currentRow = 0;
$querySize = 0;
if (
($GLOBALS['sql_insert_syntax'] === 'extended'
|| $GLOBALS['sql_insert_syntax'] === 'both')
&& $this->type !== 'UPDATE'
) {
if (($this->insertSyntax === 'extended' || $this->insertSyntax === 'both') && $this->type !== 'UPDATE') {
$separator = ',';
$schemaInsert .= "\n";
} else {
@ -2186,7 +2186,7 @@ class ExportSql extends ExportPlugin
) {
// a number
$values[] = $row[$j];
} elseif ($metaInfo->isBinary && isset($GLOBALS['sql_hex_for_binary'])) {
} elseif ($metaInfo->isBinary && $this->hexForBinary) {
// a true BLOB
// - mysqldump only generates hex data when the --hex-blob
// option is used, for fields having the binary attribute
@ -2235,7 +2235,7 @@ class ExportSql extends ExportPlugin
}
$insertLine .= ' WHERE ' . (new UniqueCondition($fieldsMeta, $row))->getWhereClause();
} elseif ($GLOBALS['sql_insert_syntax'] === 'extended' || $GLOBALS['sql_insert_syntax'] === 'both') {
} elseif ($this->insertSyntax === 'extended' || $this->insertSyntax === 'both') {
// Extended inserts case
if ($currentRow === 1) {
$insertLine = $schemaInsert . '('
@ -2243,8 +2243,7 @@ class ExportSql extends ExportPlugin
} else {
$insertLine = '(' . implode(', ', $values) . ')';
$insertLineSize = mb_strlen($insertLine);
$sqlMaxSize = $GLOBALS['sql_max_query_size'];
if ($sqlMaxSize > 0 && $querySize + $insertLineSize > $sqlMaxSize) {
if ($this->maxQuerySize > 0 && $querySize + $insertLineSize > $this->maxQuerySize) {
if (! $this->export->outputHandler(';' . "\n")) {
return false;
}
@ -2714,6 +2713,42 @@ class ExportSql extends ExportPlugin
));
$this->createView = (bool) ($request->getParsedBodyParam('sql_create_view')
?? $exportConfig['sql_create_view'] ?? false);
$this->createTrigger = (bool) ($request->getParsedBodyParam('sql_create_trigger')
?? $exportConfig['sql_create_trigger'] ?? false);
$this->viewCurrentUser = (bool) ($request->getParsedBodyParam('sql_view_current_user')
?? $exportConfig['sql_view_current_user'] ?? false);
$this->simpleViewExport = (bool) ($request->getParsedBodyParam('sql_simple_view_export')
?? $exportConfig['sql_simple_view_export'] ?? false);
$this->ifNotExists = (bool) ($request->getParsedBodyParam('sql_if_not_exists')
?? $exportConfig['sql_if_not_exists'] ?? false);
$this->orReplaceView = (bool) ($request->getParsedBodyParam('sql_or_replace_view')
?? $exportConfig['sql_or_replace_view'] ?? false);
$this->autoIncrement = (bool) ($request->getParsedBodyParam('sql_auto_increment')
?? $exportConfig['sql_auto_increment'] ?? false);
$this->truncate = (bool) ($request->getParsedBodyParam('sql_truncate')
?? $exportConfig['sql_truncate'] ?? false);
$this->delayed = (bool) ($request->getParsedBodyParam('sql_delayed')
?? $exportConfig['sql_delayed'] ?? false);
$this->ignore = (bool) ($request->getParsedBodyParam('sql_ignore')
?? $exportConfig['sql_ignore'] ?? false);
$this->insertSyntax = $this->setInsertSyntax($this->setStringValue(
$request->getParsedBodyParam('sql_insert_syntax'),
$exportConfig['sql_insert_syntax'] ?? null,
));
$this->maxQuerySize = $this->setMaxQuerySize(
$request->getParsedBodyParam('sql_max_query_size'),
$exportConfig['sql_max_query_size'] ?? null,
);
$this->hexForBinary = (bool) ($request->getParsedBodyParam('sql_hex_for_binary')
?? $exportConfig['sql_hex_for_binary'] ?? false);
$this->utcTime = (bool) ($request->getParsedBodyParam('sql_utc_time')
?? $exportConfig['sql_utc_time'] ?? false);
$this->dropDatabase = (bool) ($request->getParsedBodyParam('sql_drop_database')
?? $exportConfig['sql_drop_database'] ?? false);
$this->viewsAsTables = (bool) ($request->getParsedBodyParam('sql_views_as_tables')
?? $exportConfig['sql_views_as_tables'] ?? false);
$this->metadata = (bool) ($request->getParsedBodyParam('sql_metadata')
?? $exportConfig['sql_metadata'] ?? false);
}
private function setStringValue(mixed $fromRequest, mixed $fromConfig): string
@ -2763,4 +2798,43 @@ class ExportSql extends ExportPlugin
{
return $this->createView;
}
public function hasCreateTrigger(): bool
{
return $this->createTrigger;
}
public function setAutoIncrement(bool $autoIncrement): void
{
$this->autoIncrement = $autoIncrement;
}
/** @return 'complete'|'extended'|'both'|'none' */
private function setInsertSyntax(string $syntax): string
{
if (in_array($syntax, ['complete', 'extended', 'none'], true)) {
return $syntax;
}
return 'both';
}
/** @return int<0, max> */
private function setMaxQuerySize(mixed $fromRequest, mixed $fromConfig): int
{
if (is_numeric($fromRequest) && $fromRequest >= 0) {
return (int) $fromRequest;
}
if (is_numeric($fromConfig) && $fromConfig >= 0) {
return (int) $fromConfig;
}
return 50000;
}
public function hasMetadata(): bool
{
return $this->metadata;
}
}

View File

@ -468,10 +468,7 @@ class TableMover
$exportSqlPlugin->useSqlBackquotes(true);
$GLOBALS['no_constraints_comments'] = true;
// set the value of global sql_auto_increment variable
if (isset($_POST['sql_auto_increment'])) {
$GLOBALS['sql_auto_increment'] = $_POST['sql_auto_increment'];
}
$exportSqlPlugin->setAutoIncrement(isset($_POST['sql_auto_increment']) && (bool) $_POST['sql_auto_increment']);
$isView = (new Table($sourceTable, $sourceDb, $this->dbi))->isView();
/**

View File

@ -102,8 +102,6 @@ class ExportTest extends AbstractTestCase
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = false;
Config::getInstance()->selectedServer['DisableIS'] = false;
$GLOBALS['sql_insert_syntax'] = 'both';
$GLOBALS['sql_max_query_size'] = '50000';
// phpcs:disable Generic.Files.LineLength.TooLong
$dbiDummy = $this->createDbiDummy();
@ -163,8 +161,6 @@ SQL;
$config = Config::getInstance();
$config->selectedServer['DisableIS'] = false;
$config->selectedServer['only_db'] = '';
$GLOBALS['sql_insert_syntax'] = 'both';
$GLOBALS['sql_max_query_size'] = '50000';
ExportPlugin::$exportType = ExportType::Server;
// phpcs:disable Generic.Files.LineLength.TooLong

View File

@ -386,7 +386,6 @@ class ExportSqlTest extends AbstractTestCase
public function testExportFooter(): void
{
$GLOBALS['charset'] = 'utf-8';
$GLOBALS['sql_utc_time'] = true;
$GLOBALS['old_tz'] = 'GMT';
$GLOBALS['asfile'] = 'yes';
$GLOBALS['output_charset_conversion'] = 'utf-8';
@ -402,7 +401,7 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_use_transaction' => 'On', 'sql_disable_fk' => 'On']);
->withParsedBody(['sql_use_transaction' => 'On', 'sql_disable_fk' => 'On', 'sql_utc_time' => 'On']);
$this->object->setExportOptions($request, []);
@ -418,7 +417,6 @@ class ExportSqlTest extends AbstractTestCase
$config = Config::getInstance();
$config->selectedServer['host'] = 'localhost';
$config->selectedServer['port'] = 80;
$GLOBALS['sql_utc_time'] = true;
$GLOBALS['old_tz'] = 'GMT';
$GLOBALS['asfile'] = 'yes';
$GLOBALS['output_charset_conversion'] = 'utf-8';
@ -449,6 +447,7 @@ class ExportSqlTest extends AbstractTestCase
'sql_header_comment' => "h1C\nh2C",
'sql_use_transaction' => 'On',
'sql_disable_fk' => 'On',
'sql_utc_time' => 'On',
]);
$this->object->setExportOptions($request, []);
@ -480,8 +479,6 @@ class ExportSqlTest extends AbstractTestCase
public function testExportDBCreate(): void
{
$GLOBALS['sql_drop_database'] = true;
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -494,7 +491,11 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_structure_or_data' => 'structure_and_data', 'sql_backquotes' => 'true']);
->withParsedBody([
'sql_structure_or_data' => 'structure_and_data',
'sql_backquotes' => 'true',
'sql_drop_database' => 'On',
]);
$this->object->setExportOptions($request, []);
@ -644,8 +645,6 @@ class ExportSqlTest extends AbstractTestCase
public function testGetTableDefStandIn(): void
{
$GLOBALS['sql_if_not_exists'] = true;
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -658,7 +657,7 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_drop_table' => 'On']);
->withParsedBody(['sql_drop_table' => 'On', 'sql_if_not_exists' => 'On']);
$this->object->setExportOptions($request, []);
@ -674,8 +673,6 @@ class ExportSqlTest extends AbstractTestCase
public function testGetTableDefForView(): void
{
$GLOBALS['sql_if_not_exists'] = true;
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -702,7 +699,7 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_compatibility' => 'MSSQL']);
->withParsedBody(['sql_compatibility' => 'MSSQL', 'sql_if_not_exists' => 'On']);
$this->object->setExportOptions($request, []);
@ -742,7 +739,7 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody([]);
->withParsedBody(['sql_if_not_exists' => 'On']);
$this->object->setExportOptions($request, []);
@ -758,8 +755,6 @@ class ExportSqlTest extends AbstractTestCase
public function testGetTableDef(): void
{
$GLOBALS['sql_auto_increment'] = true;
$GLOBALS['sql_if_not_exists'] = true;
$this->object->sqlConstraints = null;
if (isset($GLOBALS['no_constraints_comments'])) {
@ -836,15 +831,10 @@ SQL;
self::assertStringContainsString('ADD CONSTRAINT', $this->object->sqlConstraints);
self::assertStringContainsString('ALTER TABLE "table"', $this->object->sqlConstraintsQuery);
self::assertStringContainsString('ADD CONSTRAINT', $this->object->sqlConstraintsQuery);
self::assertStringContainsString('ALTER TABLE "table"', $GLOBALS['sql_drop_foreign_keys']);
self::assertStringContainsString('DROP FOREIGN KEY', $GLOBALS['sql_drop_foreign_keys']);
}
public function testGetTableDefWithError(): void
{
$GLOBALS['sql_auto_increment'] = true;
$GLOBALS['sql_if_not_exists'] = true;
$this->object->sqlConstraints = null;
if (isset($GLOBALS['no_constraints_comments'])) {
@ -946,8 +936,6 @@ SQL;
self::assertStringContainsString('CREATE TABLE `test_table`', $result);
// case 2
$GLOBALS['sql_create_trigger'] = true;
$this->object->useSqlBackquotes(false);
ob_start();
@ -961,11 +949,7 @@ SQL;
$result,
);
unset($GLOBALS['sql_create_trigger']);
// case 3
$GLOBALS['sql_views_as_tables'] = false;
$this->object->useSqlBackquotes(false);
ExportPlugin::$exportType = ExportType::Raw;
@ -982,8 +966,10 @@ SQL;
self::assertStringContainsString('CREATE TABLE `test_table`', $sqlViews);
// case 4
$GLOBALS['sql_views_as_tables'] = true;
unset($GLOBALS['sql_if_not_exists']);
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_include_comments' => 'On', 'sql_views_as_tables' => 'On']);
$this->object->setExportOptions($request, []);
ob_start();
self::assertTrue($this->object->exportStructure('test_db', 'test_table', 'create_view'));
@ -1079,17 +1065,17 @@ SQL;
->willReturn($tableObj);
DatabaseInterface::$instance = $dbi;
$GLOBALS['sql_max_query_size'] = 50000;
$GLOBALS['sql_views_as_tables'] = true;
$GLOBALS['sql_delayed'] = ' DELAYED';
$GLOBALS['sql_ignore'] = true;
$GLOBALS['sql_truncate'] = true;
$GLOBALS['sql_insert_syntax'] = 'both';
$GLOBALS['sql_hex_for_binary'] = true;
Config::getInstance()->selectedServer['DisableIS'] = false;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_backquotes' => 'true', 'sql_compatibility' => 'MSSQL']);
->withParsedBody([
'sql_backquotes' => 'true',
'sql_compatibility' => 'MSSQL',
'sql_truncate' => 'On',
'sql_delayed' => 'On',
'sql_ignore' => 'On',
'sql_hex_for_binary' => 'On',
]);
$this->object->setExportOptions($request, []);
@ -1177,16 +1163,15 @@ SQL;
->willReturn($tableObj);
DatabaseInterface::$instance = $dbi;
$GLOBALS['sql_views_as_tables'] = true;
$GLOBALS['sql_delayed'] = ' DELAYED';
$GLOBALS['sql_ignore'] = true;
$GLOBALS['sql_truncate'] = true;
$GLOBALS['sql_insert_syntax'] = 'both';
$GLOBALS['sql_hex_for_binary'] = true;
Config::getInstance()->selectedServer['DisableIS'] = false;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_backquotes' => 'true', 'sql_compatibility' => 'MSSQL', 'sql_type' => 'UPDATE']);
->withParsedBody([
'sql_backquotes' => 'true',
'sql_compatibility' => 'MSSQL',
'sql_type' => 'UPDATE',
'sql_ignore' => 'On',
]);
$this->object->setExportOptions($request, []);
@ -1225,7 +1210,6 @@ SQL;
DatabaseInterface::$instance = $dbi;
Config::getInstance()->selectedServer['DisableIS'] = false;
$GLOBALS['sql_views_as_tables'] = false;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_backquotes' => 'true', 'sql_include_comments' => 'On']);
@ -1271,7 +1255,6 @@ SQL;
DatabaseInterface::$instance = $dbi;
Config::getInstance()->selectedServer['DisableIS'] = false;
$GLOBALS['sql_views_as_tables'] = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['sql_include_comments' => 'On']);

View File

@ -49,8 +49,6 @@ class TableTest extends AbstractTestCase
$config->settings['MaxExactCount'] = 100;
$config->settings['MaxExactCountViews'] = 100;
$config->selectedServer['pmadb'] = 'pmadb';
$GLOBALS['sql_auto_increment'] = true;
$GLOBALS['sql_if_not_exists'] = true;
$config->selectedServer['table_uiprefs'] = 'pma__table_uiprefs';
$sqlIsViewTrue = 'SELECT 1'