Skip to content

Commit afa9e1a

Browse files
Merge pull request #18260 from kamil-tekiela/useSqlBackquotes
Fix useSqlBackquotes in ExportSql
2 parents b489506 + 34ad6b7 commit afa9e1a

6 files changed

Lines changed: 25 additions & 104 deletions

File tree

libraries/classes/Controllers/Export/ExportController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PhpMyAdmin\Http\ServerRequest;
1515
use PhpMyAdmin\Message;
1616
use PhpMyAdmin\Plugins;
17+
use PhpMyAdmin\Plugins\Export\ExportSql;
1718
use PhpMyAdmin\ResponseRenderer;
1819
use PhpMyAdmin\Sanitize;
1920
use PhpMyAdmin\SqlParser\Parser;
@@ -113,6 +114,10 @@ public function __invoke(ServerRequest $request): void
113114
return;
114115
}
115116

117+
if ($request->hasBodyParam('sql_backquotes') && $exportPlugin instanceof ExportSql) {
118+
$exportPlugin->useSqlBackquotes(true);
119+
}
120+
116121
/**
117122
* valid compression methods
118123
*/
@@ -827,10 +832,6 @@ private function setGlobalsFromRequest(array $postParams): void
827832
$GLOBALS['sql_auto_increment'] = $postParams['sql_auto_increment'];
828833
}
829834

830-
if (isset($postParams['sql_backquotes'])) {
831-
$GLOBALS['sql_backquotes'] = $postParams['sql_backquotes'];
832-
}
833-
834835
if (isset($postParams['sql_truncate'])) {
835836
$GLOBALS['sql_truncate'] = $postParams['sql_truncate'];
836837
}

libraries/classes/Plugins/Export/ExportSql.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ class ExportSql extends ExportPlugin
6969
*/
7070
private bool $sentCharset = false;
7171

72-
private bool $useSqlBackquotes = true;
73-
74-
protected function init(): void
75-
{
76-
$this->useSqlBackquotes = isset($GLOBALS['sql_backquotes']);
77-
}
72+
private bool $useSqlBackquotes = false;
7873

7974
/** @psalm-return non-empty-lowercase-string */
8075
public function getName(): string
8176
{
8277
return 'sql';
8378
}
8479

80+
public function useSqlBackquotes(bool $useSqlBackquotes): void
81+
{
82+
$this->useSqlBackquotes = $useSqlBackquotes;
83+
}
84+
8585
protected function setProperties(): ExportPluginProperties
8686
{
8787
$GLOBALS['plugin_param'] ??= null;

libraries/classes/Table.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,6 @@ public static function moveCopy(
937937
}
938938

939939
// Setting required export settings.
940-
$GLOBALS['sql_backquotes'] = 1;
941940
$GLOBALS['asfile'] = 1;
942941

943942
// Ensuring the target database is valid.

libraries/classes/Tracker.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public static function createVersion(
184184
$trackingSet = '',
185185
bool $isView = false,
186186
): bool {
187-
$GLOBALS['sql_backquotes'] ??= null;
188187
$GLOBALS['export_type'] ??= null;
189188
$relation = new Relation($GLOBALS['dbi']);
190189

@@ -200,7 +199,7 @@ public static function createVersion(
200199
return false;
201200
}
202201

203-
$GLOBALS['sql_backquotes'] = true;
202+
$exportSqlPlugin->useSqlBackquotes(true);
204203

205204
$date = Util::date('Y-m-d H:i:s');
206205

@@ -223,8 +222,6 @@ public static function createVersion(
223222
$snapshot = serialize($snapshot);
224223

225224
// Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
226-
$GLOBALS['sql_backquotes'] = true;
227-
228225
$createSql = '';
229226

230227
if ($GLOBALS['cfg']['Server']['tracking_add_drop_table'] == true && $isView === false) {

psalm-baseline.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,6 @@
19731973
<code><![CDATA[$GLOBALS['single_table']]]></code>
19741974
<code><![CDATA[$GLOBALS['single_table']]]></code>
19751975
<code><![CDATA[$GLOBALS['sql_auto_increment']]]></code>
1976-
<code><![CDATA[$GLOBALS['sql_backquotes']]]></code>
19771976
<code><![CDATA[$GLOBALS['sql_compatibility']]]></code>
19781977
<code><![CDATA[$GLOBALS['sql_create_database']]]></code>
19791978
<code><![CDATA[$GLOBALS['sql_create_table']]]></code>
@@ -9999,7 +9998,6 @@
99999998
<code><![CDATA[$GLOBALS['sql_auto_increment']]]></code>
100009999
<code><![CDATA[$GLOBALS['sql_auto_increments']]]></code>
1000110000
<code><![CDATA[$GLOBALS['sql_auto_increments']]]></code>
10002-
<code><![CDATA[$GLOBALS['sql_backquotes']]]></code>
1000310001
<code><![CDATA[$GLOBALS['sql_create_database']]]></code>
1000410002
<code><![CDATA[$GLOBALS['sql_delayed']]]></code>
1000510003
<code><![CDATA[$GLOBALS['sql_disable_fk']]]></code>
@@ -13964,7 +13962,6 @@
1396413962
</InvalidArgument>
1396513963
<InvalidArrayOffset>
1396613964
<code><![CDATA[$GLOBALS['export_type']]]></code>
13967-
<code><![CDATA[$GLOBALS['sql_backquotes']]]></code>
1396813965
</InvalidArrayOffset>
1396913966
<MixedArgument>
1397013967
<code><![CDATA[$data['statement']]]></code>
@@ -13986,7 +13983,6 @@
1398613983
<MixedAssignment>
1398713984
<code><![CDATA[$GLOBALS['db']]]></code>
1398813985
<code><![CDATA[$GLOBALS['export_type']]]></code>
13989-
<code><![CDATA[$GLOBALS['sql_backquotes']]]></code>
1399013986
<code>$data</code>
1399113987
<code><![CDATA[$result['tablename']]]></code>
1399213988
<code>$trackingEnabled</code>

test/classes/Plugins/Export/ExportSqlTest.php

Lines changed: 13 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ protected function setUp(): void
6969
$GLOBALS['plugin_param']['export_type'] = 'table';
7070
$GLOBALS['plugin_param']['single_table'] = false;
7171
$GLOBALS['sql_constraints'] = null;
72-
$GLOBALS['sql_backquotes'] = null;
7372
$GLOBALS['sql_indexes'] = null;
7473
$GLOBALS['sql_auto_increments'] = null;
7574

@@ -78,6 +77,7 @@ protected function setUp(): void
7877
new Export($GLOBALS['dbi']),
7978
new Transformations(),
8079
);
80+
$this->object->useSqlBackquotes(false);
8181
}
8282

8383
/**
@@ -473,7 +473,6 @@ public function testExportDBCreate(): void
473473
{
474474
$GLOBALS['sql_compatibility'] = 'NONE';
475475
$GLOBALS['sql_drop_database'] = true;
476-
$GLOBALS['sql_backquotes'] = true;
477476
$GLOBALS['sql_create_database'] = true;
478477
$GLOBALS['sql_create_table'] = true;
479478
$GLOBALS['sql_create_view'] = true;
@@ -491,12 +490,7 @@ public function testExportDBCreate(): void
491490

492491
$GLOBALS['dbi'] = $dbi;
493492

494-
// Reset the object
495-
$this->object = new ExportSql(
496-
new Relation($GLOBALS['dbi']),
497-
new Export($GLOBALS['dbi']),
498-
new Transformations(),
499-
);
493+
$this->object->useSqlBackquotes(true);
500494

501495
ob_start();
502496
$this->assertTrue(
@@ -518,7 +512,6 @@ public function testExportDBCreate(): void
518512
// case2: no backquotes
519513
unset($GLOBALS['sql_compatibility']);
520514
$GLOBALS['cfg']['Server']['DisableIS'] = true;
521-
unset($GLOBALS['sql_backquotes']);
522515

523516
$dbi = $this->getMockBuilder(DatabaseInterface::class)
524517
->disableOriginalConstructor()
@@ -533,12 +526,7 @@ public function testExportDBCreate(): void
533526

534527
$GLOBALS['dbi'] = $dbi;
535528

536-
// Reset the object
537-
$this->object = new ExportSql(
538-
new Relation($GLOBALS['dbi']),
539-
new Export($GLOBALS['dbi']),
540-
new Transformations(),
541-
);
529+
$this->object->useSqlBackquotes(false);
542530

543531
ob_start();
544532
$this->assertTrue(
@@ -561,15 +549,9 @@ public function testExportDBCreate(): void
561549
public function testExportDBHeader(): void
562550
{
563551
$GLOBALS['sql_compatibility'] = 'MSSQL';
564-
$GLOBALS['sql_backquotes'] = true;
565552
$GLOBALS['sql_include_comments'] = true;
566553

567-
// Reset the object
568-
$this->object = new ExportSql(
569-
new Relation($GLOBALS['dbi']),
570-
new Export($GLOBALS['dbi']),
571-
new Transformations(),
572-
);
554+
$this->object->useSqlBackquotes(true);
573555

574556
ob_start();
575557
$this->assertTrue(
@@ -583,14 +565,8 @@ public function testExportDBHeader(): void
583565

584566
// case 2
585567
unset($GLOBALS['sql_compatibility']);
586-
unset($GLOBALS['sql_backquotes']);
587568

588-
// Reset the object
589-
$this->object = new ExportSql(
590-
new Relation($GLOBALS['dbi']),
591-
new Export($GLOBALS['dbi']),
592-
new Transformations(),
593-
);
569+
$this->object->useSqlBackquotes(false);
594570

595571
ob_start();
596572
$this->assertTrue(
@@ -791,7 +767,6 @@ public function testGetTableDef(): void
791767
$GLOBALS['sql_compatibility'] = 'MSSQL';
792768
$GLOBALS['sql_auto_increment'] = true;
793769
$GLOBALS['sql_drop_table'] = true;
794-
$GLOBALS['sql_backquotes'] = true;
795770
$GLOBALS['sql_if_not_exists'] = true;
796771
$GLOBALS['sql_include_comments'] = true;
797772
if (isset($GLOBALS['sql_constraints'])) {
@@ -845,12 +820,7 @@ public function testGetTableDef(): void
845820
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
846821
$GLOBALS['cfg']['Server']['DisableIS'] = false;
847822

848-
// Reset the object
849-
$this->object = new ExportSql(
850-
new Relation($GLOBALS['dbi']),
851-
new Export($GLOBALS['dbi']),
852-
new Transformations(),
853-
);
823+
$this->object->useSqlBackquotes(true);
854824

855825
$result = $this->object->getTableDef('db', 'table', true, true, false);
856826

@@ -875,7 +845,6 @@ public function testGetTableDefWithError(): void
875845
$GLOBALS['sql_compatibility'] = '';
876846
$GLOBALS['sql_auto_increment'] = true;
877847
$GLOBALS['sql_drop_table'] = true;
878-
$GLOBALS['sql_backquotes'] = false;
879848
$GLOBALS['sql_if_not_exists'] = true;
880849
$GLOBALS['sql_include_comments'] = true;
881850

@@ -900,12 +869,7 @@ public function testGetTableDefWithError(): void
900869
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
901870
$GLOBALS['cfg']['Server']['DisableIS'] = false;
902871

903-
// Reset the object
904-
$this->object = new ExportSql(
905-
new Relation($GLOBALS['dbi']),
906-
new Export($GLOBALS['dbi']),
907-
new Transformations(),
908-
);
872+
$this->object->useSqlBackquotes(false);
909873

910874
$result = $this->object->getTableDef('db', 'table', true, true, false);
911875

@@ -977,15 +941,9 @@ public function testGetTableComments(): void
977941
public function testExportStructure(): void
978942
{
979943
$GLOBALS['sql_compatibility'] = 'MSSQL';
980-
$GLOBALS['sql_backquotes'] = true;
981944
$GLOBALS['sql_include_comments'] = true;
982945

983-
// Reset the object
984-
$this->object = new ExportSql(
985-
new Relation($GLOBALS['dbi']),
986-
new Export($GLOBALS['dbi']),
987-
new Transformations(),
988-
);
946+
$this->object->useSqlBackquotes(true);
989947

990948
// case 1
991949
ob_start();
@@ -1006,17 +964,11 @@ public function testExportStructure(): void
1006964

1007965
// case 2
1008966
unset($GLOBALS['sql_compatibility']);
1009-
unset($GLOBALS['sql_backquotes']);
1010967

1011968
$GLOBALS['sql_create_trigger'] = true;
1012969
$GLOBALS['sql_drop_table'] = true;
1013970

1014-
// Reset the object
1015-
$this->object = new ExportSql(
1016-
new Relation($GLOBALS['dbi']),
1017-
new Export($GLOBALS['dbi']),
1018-
new Transformations(),
1019-
);
971+
$this->object->useSqlBackquotes(false);
1020972

1021973
ob_start();
1022974
$this->assertTrue(
@@ -1042,14 +994,8 @@ public function testExportStructure(): void
1042994

1043995
// case 3
1044996
$GLOBALS['sql_views_as_tables'] = false;
1045-
$GLOBALS['sql_backquotes'] = null;
1046997

1047-
// Reset the object
1048-
$this->object = new ExportSql(
1049-
new Relation($GLOBALS['dbi']),
1050-
new Export($GLOBALS['dbi']),
1051-
new Transformations(),
1052-
);
998+
$this->object->useSqlBackquotes(false);
1053999

10541000
ob_start();
10551001
$this->assertTrue(
@@ -1192,7 +1138,6 @@ public function testExportData(): void
11921138

11931139
$GLOBALS['dbi'] = $dbi;
11941140
$GLOBALS['sql_compatibility'] = 'MSSQL';
1195-
$GLOBALS['sql_backquotes'] = true;
11961141
$GLOBALS['sql_max_query_size'] = 50000;
11971142
$GLOBALS['sql_views_as_tables'] = true;
11981143
$GLOBALS['sql_type'] = 'INSERT';
@@ -1203,12 +1148,7 @@ public function testExportData(): void
12031148
$GLOBALS['sql_hex_for_binary'] = true;
12041149
$GLOBALS['cfg']['Server']['DisableIS'] = false;
12051150

1206-
// Reset the object
1207-
$this->object = new ExportSql(
1208-
new Relation($GLOBALS['dbi']),
1209-
new Export($GLOBALS['dbi']),
1210-
new Transformations(),
1211-
);
1151+
$this->object->useSqlBackquotes(true);
12121152

12131153
ob_start();
12141154
$this->object->exportData('db', 'table', 'example.com/err', 'SELECT a FROM b WHERE 1');
@@ -1300,7 +1240,6 @@ public function testExportDataWithUpdate(): void
13001240

13011241
$GLOBALS['dbi'] = $dbi;
13021242
$GLOBALS['sql_compatibility'] = 'MSSQL';
1303-
$GLOBALS['sql_backquotes'] = true;
13041243
$GLOBALS['sql_views_as_tables'] = true;
13051244
$GLOBALS['sql_type'] = 'UPDATE';
13061245
$GLOBALS['sql_delayed'] = ' DELAYED';
@@ -1310,12 +1249,7 @@ public function testExportDataWithUpdate(): void
13101249
$GLOBALS['sql_hex_for_binary'] = true;
13111250
$GLOBALS['cfg']['Server']['DisableIS'] = false;
13121251

1313-
// Reset the object
1314-
$this->object = new ExportSql(
1315-
new Relation($GLOBALS['dbi']),
1316-
new Export($GLOBALS['dbi']),
1317-
new Transformations(),
1318-
);
1252+
$this->object->useSqlBackquotes(true);
13191253

13201254
ob_start();
13211255
$this->object->exportData('db', 'table', 'example.com/err', 'SELECT a FROM b WHERE 1');
@@ -1358,14 +1292,8 @@ public function testExportDataWithIsView(): void
13581292
$GLOBALS['sql_include_comments'] = true;
13591293
$oldVal = $GLOBALS['sql_compatibility'] ?? '';
13601294
$GLOBALS['sql_compatibility'] = 'NONE';
1361-
$GLOBALS['sql_backquotes'] = true;
13621295

1363-
// Reset the object
1364-
$this->object = new ExportSql(
1365-
new Relation($GLOBALS['dbi']),
1366-
new Export($GLOBALS['dbi']),
1367-
new Transformations(),
1368-
);
1296+
$this->object->useSqlBackquotes(true);
13691297

13701298
ob_start();
13711299
$this->assertTrue(

0 commit comments

Comments
 (0)