'
@@ -954,6 +954,7 @@ class Generator
// Has as sql_query without a signature, to be accepted it needs to be sent using POST
str_contains($url, 'sql_query=') && ! str_contains($url, 'sql_signature=')
)
+ || $config->config->URLQueryEncryption
|| str_contains($url, 'view[as]=');
if ($respectUrlLengthLimit && $isDataPostFormatSupported) {
$parts = explode('?', $url, 2);
diff --git a/src/Import/Import.php b/src/Import/Import.php
index b35f52df3d..b9ae466545 100644
--- a/src/Import/Import.php
+++ b/src/Import/Import.php
@@ -847,7 +847,8 @@ final class Import
if ($analyses !== null) {
$isVarchar = $analyses[$tableIndex][$columnIndex]->type === ColumnType::Varchar;
} else {
- $isVarchar = ! is_numeric($row[$columnIndex]);
+ $isVarchar = ! is_numeric($row[$columnIndex])
+ && ! preg_match('/^0x[0-9a-f]+$/', (string) $row[$columnIndex]);
}
/* Don't put quotes around NULL fields */
diff --git a/src/Plugins/Export/ExportCsv.php b/src/Plugins/Export/ExportCsv.php
index 3d8144f6cb..2547706360 100644
--- a/src/Plugins/Export/ExportCsv.php
+++ b/src/Plugins/Export/ExportCsv.php
@@ -21,6 +21,7 @@ use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use function __;
+use function bin2hex;
use function implode;
use function is_string;
use function str_replace;
@@ -139,6 +140,7 @@ class ExportCsv extends ExportPlugin
array $aliases = [],
): void {
$result = $this->dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
$charsNeedingEnclosure = $this->separator . $this->enclosed . $this->terminated;
@@ -165,7 +167,7 @@ class ExportCsv extends ExportPlugin
// Format the data
while ($row = $result->fetchRow()) {
$insertValues = [];
- foreach ($row as $field) {
+ foreach ($row as $j => $field) {
if ($field === null) {
$insertValues[] = $this->null;
continue;
@@ -176,6 +178,11 @@ class ExportCsv extends ExportPlugin
continue;
}
+ if ($fieldsMeta[$j]->isMappedTypeGeometry || $fieldsMeta[$j]->isBinary) {
+ $insertValues[] = '0x' . bin2hex($row[$j] ?? '');
+ continue;
+ }
+
// remove CRLF characters within field
if ($this->removeCrLf) {
$field = str_replace(["\r", "\n"], '', $field);
diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php
index 7f42a6a94e..19f8ec591e 100644
--- a/src/Plugins/Export/ExportLatex.php
+++ b/src/Plugins/Export/ExportLatex.php
@@ -28,6 +28,8 @@ use function __;
use function addcslashes;
use function array_keys;
use function array_values;
+use function assert;
+use function bin2hex;
use function in_array;
use function is_string;
use function mb_strpos;
@@ -272,8 +274,10 @@ class ExportLatex extends ExportPlugin
$tableAlias = $this->getTableAlias($aliases, $db, $table);
$result = $this->dbi->tryQuery($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
+ assert($result !== false);
$columnsCnt = $result->numFields();
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
$columns = [];
$columnsAlias = [];
foreach ($result->getFieldNames() as $i => $colAs) {
@@ -350,7 +354,13 @@ class ExportLatex extends ExportPlugin
/** @infection-ignore-all */
for ($i = 0; $i < $columnsCnt; $i++) {
if ($record[$columns[$i]] !== null) {
- $columnValue = self::texEscape($record[$columns[$i]]);
+ if ($fieldsMeta[$i]->isMappedTypeGeometry || $fieldsMeta[$i]->isBinary) {
+ $columnValue = self::texEscape(
+ '0x' . bin2hex($record[$columns[$i]]),
+ );
+ } else {
+ $columnValue = self::texEscape($record[$columns[$i]]);
+ }
} else {
$columnValue = $this->null;
}
diff --git a/src/Plugins/Export/ExportMediawiki.php b/src/Plugins/Export/ExportMediawiki.php
index 955ec0a97e..334c123f52 100644
--- a/src/Plugins/Export/ExportMediawiki.php
+++ b/src/Plugins/Export/ExportMediawiki.php
@@ -23,6 +23,7 @@ use PhpMyAdmin\Util;
use function __;
use function array_values;
+use function bin2hex;
use function htmlspecialchars;
use function str_repeat;
@@ -226,6 +227,7 @@ class ExportMediawiki extends ExportPlugin
// Get the table data from the database
$result = $this->dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
$fieldsCnt = $result->numFields();
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
while ($row = $result->fetchRow()) {
$output .= '|-' . $this->exportCRLF();
@@ -233,6 +235,12 @@ class ExportMediawiki extends ExportPlugin
// Use '|' for separating table columns
/** @infection-ignore-all */
for ($i = 0; $i < $fieldsCnt; ++$i) {
+ if (! isset($row[$i])) {
+ $row[$i] = 'NULL';
+ } elseif ($fieldsMeta[$i]->isMappedTypeGeometry || $fieldsMeta[$i]->isBinary) {
+ $row[$i] = '0x' . bin2hex($row[$i]);
+ }
+
$output .= ' | ' . $row[$i] . $this->exportCRLF();
}
}
diff --git a/src/Plugins/Export/ExportPhparray.php b/src/Plugins/Export/ExportPhparray.php
index 5bbe10a93e..15e3a9b411 100644
--- a/src/Plugins/Export/ExportPhparray.php
+++ b/src/Plugins/Export/ExportPhparray.php
@@ -21,6 +21,7 @@ use PhpMyAdmin\Util;
use PhpMyAdmin\Version;
use function __;
+use function bin2hex;
use function preg_match;
use function preg_replace;
use function strtr;
@@ -127,6 +128,7 @@ class ExportPhparray extends ExportPlugin
$result = $this->dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
$columnsCnt = $result->numFields();
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
$columns = [];
foreach ($result->getFieldNames() as $i => $colAs) {
$colAs = $this->getColumnAlias($aliases, $db, $table, $colAs);
@@ -171,6 +173,10 @@ class ExportPhparray extends ExportPlugin
/** @infection-ignore-all */
for ($i = 0; $i < $columnsCnt; $i++) {
+ if ($record[$i] !== null && ($fieldsMeta[$i]->isMappedTypeGeometry || $fieldsMeta[$i]->isBinary)) {
+ $record[$i] = '0x' . bin2hex($record[$i]);
+ }
+
$buffer .= var_export($columns[$i], true)
. ' => ' . var_export($record[$i], true)
. ($i + 1 >= $columnsCnt ? '' : ',');
diff --git a/src/Plugins/Export/ExportTexytext.php b/src/Plugins/Export/ExportTexytext.php
index ef908a5ef7..2665e8511b 100644
--- a/src/Plugins/Export/ExportTexytext.php
+++ b/src/Plugins/Export/ExportTexytext.php
@@ -25,6 +25,7 @@ use PhpMyAdmin\Triggers\Triggers;
use PhpMyAdmin\Util;
use function __;
+use function bin2hex;
use function htmlspecialchars;
use function in_array;
use function is_string;
@@ -143,6 +144,7 @@ class ExportTexytext extends ExportPlugin
* Gets the data from the database
*/
$result = $this->dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
// If required, get fields name at the first line
if ($this->columns) {
@@ -160,11 +162,15 @@ class ExportTexytext extends ExportPlugin
// Format the data
while ($row = $result->fetchRow()) {
$textOutput = '';
- foreach ($row as $field) {
+ foreach ($row as $j => $field) {
if ($field === null) {
$value = $this->null;
} elseif ($field !== '') {
$value = $field;
+
+ if ($fieldsMeta[$j]->isMappedTypeGeometry || $fieldsMeta[$j]->isBinary) {
+ $value = '0x' . bin2hex($value);
+ }
} else {
$value = ' ';
}
diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php
index ae43e648ba..70af2a6191 100644
--- a/src/Plugins/Export/ExportXml.php
+++ b/src/Plugins/Export/ExportXml.php
@@ -25,6 +25,7 @@ use PhpMyAdmin\Util;
use PhpMyAdmin\Version;
use function __;
+use function bin2hex;
use function htmlspecialchars;
use function mb_substr;
use function rtrim;
@@ -402,6 +403,7 @@ class ExportXml extends ExportPlugin
$result = $this->dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
$columnsCnt = $result->numFields();
+ $fieldsMeta = $this->dbi->getFieldsMeta($result);
$columns = $result->getFieldNames();
$buffer = '
+
+
+
+
+
+
+ CREATE TABLE `test` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `binary` binary(16) NOT NULL,
+ `name` varchar(20) NOT NULL,
+ `shape` geometry DEFAULT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
+
+
+
+
+
+
+
+
+ 1
+ 0x10000000000000000000000000000000
+ POLYGON
+ 0x00000000010300000001000000040000000000000000405f40000000000000000000000000008063400000000000006940000000000040664000000000004057400000000000405f400000000000000000
+
+
+ 2
+ 0x20000000000000000000000000000000
+ MULTIPOLYGON
+ 0x00000000010600000002000000010300000001000000040000000000000000006140000000000000444000000000006062400000000000c0544000000000004064400000000000c0524000000000000061400000000000004440010300000001000000040000000000000000405a4000000000000000000000000000004c400000000000006940000000000080534000000000004057400000000000405a400000000000000000
+
+
+ 3
+ 0x30000000000000000000000000000000
+ MULTIPOINT
+ 0x0000000001040000000400000001010000000000000000405f400000000000004940010100000000000000008063400000000000406f40010100000000000000004066400000000000e0614001010000000000000000e065400000000000005440
+
+
+ 4
+ 0x40000000000000000000000000000000
+ MULTILINESTRING
+ 0x000000000105000000020000000102000000030000000000000000004240000000000080614000000000008047400000000000206d400000000000004f400000000000c052400102000000030000000000000000004240000000000000594000000000000031400000000000206d4000000000004066400000000000405740
+
+
+ 5
+ 0x50000000000000000000000000000000
+ POINT
+ 0x00000000010100000000000000000059400000000000406f40
+
+
+ 6
+ 0x60000000000000000000000000000000
+ LINESTRING
+ 0x0000000001020000000400000000000000008063400000000000003840000000000040664000000000000058400000000000606d4000000000000069400000000000a063400000000000c06140
+
+
+ 7
+ 0x70000000000000000000000000000000
+ GEOMETRYCOLLECTION
+ 0x000000000107000000030000000101000000000000000000594000000000000059400102000000050000000000000000000000000000000000000000000000000059400000000000005940000000000000694000000000000069400000000000c072400000000000c07240000000000000794000000000000079400103000000020000000500000000000000008041400000000000002440000000000000244000000000000034400000000000002e40000000000000444000000000008046400000000000804640000000000080414000000000000024400400000000000000000034400000000000003e40000000000080414000000000008041400000000000003e40000000000000344000000000000034400000000000003e40
+
+
+ 8
+ 0x80000000000000000000000000000000
+ TEST
+ NULL
+
+
+
diff --git a/tests/unit/Plugins/Import/ImportXmlTest.php b/tests/unit/Plugins/Import/ImportXmlTest.php
index 6bd2c5b8f5..10d03897fc 100644
--- a/tests/unit/Plugins/Import/ImportXmlTest.php
+++ b/tests/unit/Plugins/Import/ImportXmlTest.php
@@ -108,6 +108,24 @@ final class ImportXmlTest extends AbstractTestCase
pma_bookmarktest (Structure) (Options)
*/
+ //assert that all sql are executed
+ self::assertSame(
+ 'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
+ . 'USE `phpmyadmintest`;' . "\n"
+ . 'CREATE TABLE IF NOT EXISTS `pma_bookmarktest` (' . "\n"
+ . ' `id` int(11) NOT NULL AUTO_INCREMENT,' . "\n"
+ . ' `dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT \'\',' . "\n"
+ . ' `user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT \'\',' . "\n"
+ . ' `label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT \'\',' . "\n"
+ . ' `query` text COLLATE utf8_bin NOT NULL,' . "\n"
+ . ' PRIMARY KEY (`id`)' . "\n"
+ . ') ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=\'Bookmarks\';' . "\n"
+ . ' ;'
+ . 'INSERT INTO `phpmyadmintest`.`pma_bookmarktest` (`id`, `dbase`, `user`, `label`, `query`) '
+ . 'VALUES (, \'\', \'\', \'\', \'\');;',
+ Current::$sqlQuery,
+ );
+
self::assertStringContainsString(
'The following structures have either been created or altered.',
ImportSettings::$importNotice,
@@ -126,4 +144,50 @@ final class ImportXmlTest extends AbstractTestCase
return new ImportXml(new Import($dbiObject, new ResponseRenderer(), $config), $dbiObject, $config);
}
+
+ /**
+ * Test for doImport using second dataset
+ */
+ #[RequiresPhpExtension('simplexml')]
+ public function testDoImportDataset2(): void
+ {
+ $dbi = $this->getMockBuilder(DatabaseInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $importHandle = new File(ImportSettings::$importFile);
+ $importHandle->open();
+
+ ImportSettings::$importFile = 'test/test_data/test.xml';
+
+ $importXml = $this->getImportXml($dbi);
+ $importXml->doImport($importHandle);
+
+ self::assertSame(
+ 'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
+ . 'USE `phpmyadmintest`;' . "\n"
+ . 'CREATE TABLE IF NOT EXISTS `pma_bookmarktest` (' . "\n"
+ . ' `id` int(11) NOT NULL AUTO_INCREMENT,' . "\n"
+ . ' `dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT \'\',' . "\n"
+ . ' `user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT \'\',' . "\n"
+ . ' `label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT \'\',' . "\n"
+ . ' `query` text COLLATE utf8_bin NOT NULL,' . "\n"
+ . ' PRIMARY KEY (`id`)' . "\n"
+ . ') ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=\'Bookmarks\';' . "\n"
+ . ' ;'
+ . 'INSERT INTO `phpmyadmintest`.`pma_bookmarktest` (`id`, `dbase`, `user`, `label`, `query`) '
+ . 'VALUES (, \'\', \'\', \'\', \'\');;',
+ Current::$sqlQuery,
+ );
+
+ self::assertStringContainsString(
+ 'The following structures have either been created or altered.',
+ ImportSettings::$importNotice,
+ );
+ self::assertStringContainsString('Go to database: `test`', ImportSettings::$importNotice);
+ self::assertStringContainsString('Edit settings for `test`', ImportSettings::$importNotice);
+ self::assertStringContainsString('Go to table: `test`', ImportSettings::$importNotice);
+ self::assertStringContainsString('Edit settings for `test`', ImportSettings::$importNotice);
+ self::assertTrue(ImportSettings::$finished);
+ }
}