forked from greenlion/PHP-SQL-Parser
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix confusion between CHARACTER data type and CHARACTER SET issue (gr…
…eenlion#376) * Confusion between CHARACTER type and CHARACTER SET In an attempt to fix the character set issue introduced by me in greenlion#355 This change separates out the CHARACTER check to do a look ahead to see if the next keyword is SET and splits the logic appropriately. An alternative would be to look back at the constructed expression array ($expr) to see if a ExpressionType::DATA_TYPE has already been defined. This is an alternative fix to the fix proposed by greenlion#366 * Updated removed PHPUnit expect function. * Added additional tests for explicit conditions.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* issue265.php | ||
* | ||
* Test case for PHPSQLCreator. | ||
*/ | ||
|
||
namespace PHPSQLParser\Test\Creator; | ||
|
||
use PHPSQLParser\PHPSQLParser; | ||
use PHPSQLParser\PHPSQLCreator; | ||
|
||
class Issue365Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
/* | ||
* https://github.com/greenlion/PHP-SQL-Parser/issues/365 | ||
* Data type alias of character broken the CHARACTER SET parsing | ||
*/ | ||
public function testIssue365() | ||
{ | ||
$sql = "CREATE TABLE IF NOT EXISTS example (`type` CHARACTER (255) CHARACTER SET utf8)"; | ||
|
||
$parser = new PHPSQLParser($sql); | ||
$parsed = $parser->parsed; | ||
$create_def = $parsed['TABLE']['create-def']; | ||
$sub_tree = $create_def['sub_tree'][0]['sub_tree'][1]; | ||
|
||
$this->assertEquals('utf8', $sub_tree['charset'], 'CHARACTER SET utf8'); | ||
$expected_type = [ | ||
'expr_type' => 'data-type', | ||
'base_expr' => 'CHARACTER', | ||
'length' => 255 | ||
]; | ||
$this->assertEquals($expected_type, $sub_tree['sub_tree'][0], 'CHARACTER data type definition'); | ||
} | ||
|
||
public function testIssue365BonusCharset() | ||
{ | ||
$sql = "CREATE TABLE IF NOT EXISTS example (`type` CHARACTER (255) CHARSET utf8)"; | ||
|
||
$parser = new PHPSQLParser($sql); | ||
$parsed = $parser->parsed; | ||
$create_def = $parsed['TABLE']['create-def']; | ||
$sub_tree = $create_def['sub_tree'][0]['sub_tree'][1]; | ||
|
||
$this->assertEquals('utf8', $sub_tree['charset'], 'CHARACTER SET utf8'); | ||
} | ||
} |