Skip to content

Commit

Permalink
Merge pull request #5055 from Deltik/fix/5054
Browse files Browse the repository at this point in the history
Fixes #5054 db_verify::getIndex(): Support index_col_name optional parts
  • Loading branch information
CaMer0n authored Aug 17, 2023
2 parents 1f06bb3 + b623868 commit 068bf05
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
5 changes: 2 additions & 3 deletions e107_handlers/db_verify_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,8 @@ function getFields($data, $print = false)
*/
function getIndex($data, $print = false)
{
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?(INDEX|KEY) (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
$regex = "/(PRIMARY|UNIQUE|FULLTEXT|FOREIGN)?[\s]*?(INDEX|KEY)[\s]*(?:`?([\w]*)`?)?[\s]*?\(`?([\w]+)`?(?:\s*\(\d+\))?(?:\s*(ASC|DESC))?\)[\s]*,?/i";
preg_match_all($regex,$data,$m);
if (count($m) > 0)
Expand Down
47 changes: 47 additions & 0 deletions e107_tests/tests/unit/db_verifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,53 @@ public function testGetIndex()
$this->assertEquals($expected,$result);
}

/**
* @see https://github.com/e107inc/e107/issues/5054
*/
public function testGetIndexOptionalLengthAndSortOrder()
{
$data = <<<EOF
`field1` int(10) unsigned NOT NULL AUTO_INCREMENT,
`field2` varchar(100) NOT NULL DEFAULT '',
`field3` varchar(100) NOT NULL DEFAULT '',
`field4` varchar(100) NOT NULL DEFAULT '',
KEY (`field1`),
INDEX `field2` (`field2` DESC),
KEY `field3` (`field3` (100) ASC),
INDEX `field4` (`field4` (100)),
EOF;

$expected = array(
'field1' =>
array(
'type' => '',
'keyname' => 'field1',
'field' => 'field1',
),
'field2' =>
array(
'type' => '',
'keyname' => 'field2',
'field' => 'field2',
),
'field3' =>
array(
'type' => '',
'keyname' => 'field3',
'field' => 'field3',
),
'field4' =>
array(
'type' => '',
'keyname' => 'field4',
'field' => 'field4',
),
);

$result = $this->dbv->getIndex($data);
$this->assertEquals($expected,$result);
}

/**
* FIXME: This test has no assertions!
*/
Expand Down

0 comments on commit 068bf05

Please sign in to comment.