Skip to content

Commit

Permalink
Removed PMA_RTN_parseAllParameters().
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ungureanu <udan1107@gmail.com>
  • Loading branch information
Dan Ungureanu committed Jul 10, 2015
1 parent bb1c380 commit 1499963
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 192 deletions.
79 changes: 2 additions & 77 deletions libraries/rte/rte_routines.lib.php
Expand Up @@ -80,9 +80,8 @@ function PMA_RTN_main($type)
} // end PMA_RTN_main()

/**
* This function parses a string containing one parameter of a routine,
* as returned by PMA_RTN_parseAllParameters() and returns an array containing
* the information about this parameter.
* This function parses a string containing one parameter of a routine
* and returns an array containing the information about this parameter.
*
* @param string $value A string containing one parameter of a routine
*
Expand Down Expand Up @@ -156,80 +155,6 @@ function PMA_RTN_parseOneParameter($value)
return $retval;
} // end PMA_RTN_parseOneParameter()

/**
* This function looks through the contents of a parsed
* SHOW CREATE [PROCEDURE | FUNCTION] query and extracts
* information about the routine's parameters.
*
* @param array $parsed_query Parsed query, returned by by PMA_SQP_parse()
* @param string $routine_type Routine type: 'PROCEDURE' or 'FUNCTION'
*
* @return array Information about the parameters of a routine.
*/
function PMA_RTN_parseAllParameters($parsed_query, $routine_type)
{
$retval = array();
$retval['num'] = 0;

if ($parsed_query) {
// First get the list of parameters from the query
$buffer = '';
$params = array();
$fetching = false;
$depth = 0;
for ($i = 0; $i < $parsed_query['len']; $i++) {
if ($parsed_query[$i]['type'] == 'alpha_reservedWord'
&& $parsed_query[$i]['data'] == $routine_type
) {
$fetching = true;
} else if ($fetching == true
&& $parsed_query[$i]['type'] == 'punct_bracket_open_round'
) {
$depth++;
if ($depth > 1) {
$buffer .= $parsed_query[$i]['data'] . ' ';
}
} else if ($fetching == true
&& $parsed_query[$i]['type'] == 'punct_bracket_close_round'
) {
$depth--;
if ($depth > 0) {
$buffer .= $parsed_query[$i]['data'] . ' ';
} else {
break;
}
} else if ($parsed_query[$i]['type'] == 'punct_listsep' && $depth == 1) {
$params[] = $buffer;
$retval['num']++;
$buffer = '';
} else if ($fetching == true && $depth > 0) {
$buffer .= $parsed_query[$i]['data'] . ' ';
}
}
if (! empty($buffer)) {
$params[] = $buffer;
$retval['num']++;
}
// Now parse each parameter individually
foreach ($params as $key => $value) {
list($retval['dir'][],
$retval['name'][],
$retval['type'][],
$retval['length'][],
$retval['opts'][]) = PMA_RTN_parseOneParameter($value);
}
}
// Since some indices of $retval may be still undefined, we fill
// them each with an empty array to avoid E_ALL errors in PHP.
foreach (array('dir', 'name', 'type', 'length', 'opts') as $key => $index) {
if (! isset($retval[$index])) {
$retval[$index] = array();
}
}

return $retval;
} // end PMA_RTN_parseAllParameters()

/**
* This function looks through the contents of a parsed
* SHOW CREATE [PROCEDURE | FUNCTION] query and extracts
Expand Down
115 changes: 0 additions & 115 deletions test/libraries/rte/PMA_RTN_ParameterParser_test.php
Expand Up @@ -114,120 +114,5 @@ public function paramProvider()
)
);
}

/**
* Test for PMA_RTN_parseAllParameters
*
* @param string $query Query
* @param string $type Type
* @param array $target Expected output
*
* @return void
*
* @depends testParseOneParameter
* @dataProvider queryProvider
*/
public function testParseAllParameters($query, $type, $target)
{
PMA_RTN_setGlobals();
$this->assertEquals(
$target,
PMA_RTN_parseAllParameters(PMA_SQP_parse($query), $type)
);
}

/**
* Data provider for testParseAllParameters
*
* @return array
*/
public function queryProvider()
{
return array(
array(
'CREATE PROCEDURE `foo`() SET @A=0',
'PROCEDURE',
array(
'num' => 0,
'dir' => array(),
'name' => array(),
'type' => array(),
'length' => array(),
'opts' => array()
)
),
array(
'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
'FUNCTION',
array(
'num' => 1,
'dir' => array(
0 => ''
),
'name' => array(
0 => 'baz'
),
'type' => array(
0 => 'INT'
),
'length' => array(
0 => ''
),
'opts' => array(
0 => ''
)
)
),
array(
'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
'PROCEDURE',
array(
'num' => 1,
'dir' => array(
0 => 'IN'
),
'name' => array(
0 => 'baz\\)'
),
'type' => array(
0 => 'INT'
),
'length' => array(
0 => '25'
),
'opts' => array(
0 => 'UNSIGNED ZEROFILL'
)
)
),
array(
'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset UTF8) BEGIN SELECT NULL; END',
'PROCEDURE',
array(
'num' => 2,
'dir' => array(
0 => 'IN',
1 => 'OUT'
),
'name' => array(
0 => 'baz\\',
1 => 'bazz'
),
'type' => array(
0 => 'INT',
1 => 'VARCHAR'
),
'length' => array(
0 => '1',
1 => '15'
),
'opts' => array(
0 => 'ZEROFILL',
1 => 'utf8'
)
)
),
);
}
}
?>

0 comments on commit 1499963

Please sign in to comment.