Merge #17775 - Fix #17248 - search UUID data type error

Pull-request: #17775
Fixes: #17428

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2022-10-13 20:57:41 +02:00
commit 09259eb1a1
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 102 additions and 1 deletions

View File

@ -164,7 +164,7 @@ final class Search
// strings to numbers and numbers to strings as necessary
// during the comparison
if (
preg_match('@char|binary|blob|text|set|date|time|year@i', $types)
preg_match('@char|binary|blob|text|set|date|time|year|uuid@i', $types)
|| mb_strpos(' ' . $func_type, 'LIKE')
) {
$quot = '\'';

View File

@ -139,6 +139,25 @@ class Types
];
}
/**
* UUID search operators
*
* @return string[]
*/
public function getUUIDOperators()
{
return [
'=',
'!=',
'LIKE',
'LIKE %...%',
'NOT LIKE',
'NOT LIKE %...%',
'IN (...)',
'NOT IN (...)',
];
}
/**
* Returns operators for given type
*
@ -156,6 +175,8 @@ class Types
$ret = array_merge($ret, $this->getEnumOperators());
} elseif ($class === 'CHAR') {
$ret = array_merge($ret, $this->getTextOperators());
} elseif ($class === 'UUID') {
$ret = array_merge($ret, $this->getUUIDOperators());
} else {
$ret = array_merge($ret, $this->getNumberOperators());
}

View File

@ -208,4 +208,34 @@ class SearchTest extends AbstractTestCase
$this->search->buildSqlQuery()
);
}
public function testBuildSqlQueryWithWhereClauseUUID(): void
{
$_POST['zoom_submit'] = true;
$_POST['table'] = 'PMA';
$this->assertEquals(
'SELECT * FROM `PMA`',
$this->search->buildSqlQuery()
);
$_POST['customWhereClause'] = '';
$this->assertEquals(
'SELECT * FROM `PMA`',
$this->search->buildSqlQuery()
);
unset($_POST['customWhereClause']);
$_POST['criteriaColumnNames'] = ['id'];
$_POST['criteriaColumnOperators'] = ['='];
$_POST['criteriaValues'] = ['07ca1fdd-4805-11ed-a4dc-0242ac110002'];
$_POST['criteriaColumnTypes'] = ['uuid'];
$this->assertEquals(
"SELECT * FROM `PMA` WHERE `id` = '07ca1fdd-4805-11ed-a4dc-0242ac110002'",
$this->search->buildSqlQuery()
);
}
}

View File

@ -130,6 +130,26 @@ class TypesTest extends AbstractTestCase
);
}
/**
* Test for getUUIDOperators
*/
public function testGetUUIDOperators(): void
{
$this->assertEquals(
[
'=',
'!=',
'LIKE',
'LIKE %...%',
'NOT LIKE',
'NOT LIKE %...%',
'IN (...)',
'NOT IN (...)',
],
$this->object->getUUIDOperators()
);
}
/**
* Test for getting type operators
*
@ -194,6 +214,36 @@ class TypesTest extends AbstractTestCase
],
],
],
[
'UUID',
false,
[
'=',
'!=',
'LIKE',
'LIKE %...%',
'NOT LIKE',
'NOT LIKE %...%',
'IN (...)',
'NOT IN (...)',
],
],
[
'UUID',
true,
[
'=',
'!=',
'LIKE',
'LIKE %...%',
'NOT LIKE',
'NOT LIKE %...%',
'IN (...)',
'NOT IN (...)',
'IS NULL',
'IS NOT NULL',
],
],
];
}