Add a custom function to the parser. no return value
public addCustomFunction ( String $token ) : null | ||
$token | String | The name of the function to add |
return | null |
public function testIssueGit183() { $query = "SELECT *\nFROM SC_CATALOG_DETAIL_REG CD\nINNER JOIN MASTER_ITEM_LOOKUP IL\nON to_number( CD.STYLE ) = to_number( IL.SKU_NUM )\n\t\t\t\t"; $parser = new PHPSQLParser(); $parser->addCustomFunction("to_number"); $p = $parser->parse($query, true); $expected = getExpectedValue(dirname(__FILE__), 'issue_git183.serialized'); $this->assertEquals($expected, $p, "Oracle\\'s to_number"); }
public function testCustomfunction() { try { $sql = "SELECT PERCENTILE(xyz, 90) as percentile from some_table"; $parser = new PHPSQLParser(); $parser->addCustomFunction("percentile"); $p = $parser->parse($sql, true); } catch (\Exception $e) { $p = array(); } $this->assertSame(ExpressionType::CUSTOM_FUNCTION, $p['SELECT'][0]['expr_type'], 'custom function within SELECT clause'); $parser = new PHPSQLParser(); $parser->addCustomFunction("percentile"); $parser->addCustomFunction("foo_bar"); $p = $parser->getCustomFunctions(); $this->assertEquals(array("PERCENTILE", "FOO_BAR"), $p, 'custom function list'); $parser = new PHPSQLParser(); $parser->addCustomFunction("percentile"); $parser->addCustomFunction("foo_bar"); $parser->removeCustomFunction('percentile'); $p = $parser->getCustomFunctions(); $this->assertEquals(array("FOO_BAR"), $p, 'remove custom function from list'); }