-
-
Notifications
You must be signed in to change notification settings - Fork 12
Fix ColumnDefinitionParser
#299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58dfcbc
Fix `ColumnDefinitionParser`
Tigrov 7522482
rearrange methods
Tigrov 945363f
fix psalm
Tigrov a50f60f
Add line to CHANGELOG.md [skip ci]
Tigrov 0c1c2d9
Improve and add tests
Tigrov cf8bace
Apply fixes from StyleCI
StyleCIBot d23c5b4
Refactor, conversion to lower case db types
Tigrov 927b264
Add line to CHANGELOG.md [skip ci]
Tigrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Oracle\Column; | ||
|
||
use function preg_match; | ||
use function preg_replace; | ||
use function strlen; | ||
use function strtolower; | ||
use function substr; | ||
|
||
/** | ||
* Parses column definition string. For example, `string(255)` or `int unsigned`. | ||
*/ | ||
final class ColumnDefinitionParser extends \Yiisoft\Db\Syntax\ColumnDefinitionParser | ||
{ | ||
private const TYPE_PATTERN = '/^(' | ||
. 'timestamp\s*(?:\((\d+)\))? with(?: local)? time zone' | ||
. '|interval year\s*(?:\((\d+)\))? to month' | ||
. ')|(' | ||
. 'interval day\s*(?:\((\d+)\))? to second' | ||
. '|long raw' | ||
. '|\w*' | ||
. ')\s*(?:\(([^)]+)\))?\s*' | ||
. '/i'; | ||
|
||
public function parse(string $definition): array | ||
{ | ||
preg_match(self::TYPE_PATTERN, $definition, $matches); | ||
|
||
$type = strtolower(preg_replace('/\s*\(\d+\)/', '', $matches[4] ?? $matches[1])); | ||
$info = ['type' => $type]; | ||
|
||
$typeDetails = $matches[6] ?? $matches[2] ?? ''; | ||
|
||
if ($typeDetails !== '') { | ||
if ($type === 'enum') { | ||
$info += $this->enumInfo($typeDetails); | ||
} else { | ||
$info += $this->sizeInfo($typeDetails); | ||
} | ||
} | ||
|
||
$scale = $matches[5] ?? $matches[3] ?? ''; | ||
|
||
if ($scale !== '') { | ||
$info += ['scale' => (int) $scale]; | ||
} | ||
|
||
$extra = substr($definition, strlen($matches[0])); | ||
|
||
return $info + $this->extraInfo($extra); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Oracle\Tests; | ||
|
||
use Yiisoft\Db\Oracle\Column\ColumnDefinitionParser; | ||
use Yiisoft\Db\Tests\AbstractColumnDefinitionParserTest; | ||
|
||
/** | ||
* @group oracle | ||
*/ | ||
final class ColumnDefinitionParserTest extends AbstractColumnDefinitionParserTest | ||
{ | ||
protected function createColumnDefinitionParser(): ColumnDefinitionParser | ||
{ | ||
return new ColumnDefinitionParser(); | ||
} | ||
|
||
/** | ||
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnDefinitionParserProvider::parse | ||
*/ | ||
public function testParse(string $definition, array $expected): void | ||
{ | ||
parent::testParse($definition, $expected); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Oracle\Tests\Provider; | ||
|
||
class ColumnDefinitionParserProvider extends \Yiisoft\Db\Tests\Provider\ColumnDefinitionParserProvider | ||
{ | ||
public static function parse(): array | ||
{ | ||
return [ | ||
...parent::parse(), | ||
['long raw', ['type' => 'long raw']], | ||
['interval day to second', ['type' => 'interval day to second']], | ||
['interval day to second (2)', ['type' => 'interval day to second', 'size' => 2]], | ||
['interval day(0) to second(2)', ['type' => 'interval day to second', 'size' => 2, 'scale' => 0]], | ||
['timestamp with time zone', ['type' => 'timestamp with time zone']], | ||
['timestamp (3) with time zone', ['type' => 'timestamp with time zone', 'size' => 3]], | ||
['timestamp(3) with local time zone', ['type' => 'timestamp with local time zone', 'size' => 3]], | ||
['interval year to month', ['type' => 'interval year to month']], | ||
['interval year (3) to month', ['type' => 'interval year to month', 'scale' => 3]], | ||
]; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.