-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Oracle\Column; | ||
|
||
use function preg_match; | ||
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' | ||
. '|\w*' | ||
. ')\s*(?:\(([^)]+)\))?\s*' | ||
. '/i'; | ||
|
||
public function parse(string $definition): array | ||
{ | ||
preg_match(self::TYPE_PATTERN, $definition, $matches); | ||
|
||
$type = strtolower($matches[3] ?? $matches[1]); | ||
$info = ['type' => $type]; | ||
|
||
$typeDetails = $matches[4] ?? $matches[2] ?? ''; | ||
|
||
if ($typeDetails !== '') { | ||
if ($type === 'enum') { | ||
$info += $this->enumInfo($typeDetails); | ||
} else { | ||
$info += $this->sizeInfo($typeDetails); | ||
} | ||
} | ||
|
||
$extra = substr($definition, strlen($matches[0])); | ||
|
||
return $info + $this->extraInfo($extra); | ||
} | ||
} |
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,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 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,22 @@ | ||
<?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(), | ||
['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(0) to second', 'size' => 2]], | ||
['timestamp with time zone', ['type' => 'timestamp with time zone']], | ||
['timestamp (3) with time zone', ['type' => 'timestamp (3) with time zone', 'size' => 3]], | ||
['timestamp(3) with local time zone', ['type' => 'timestamp(3) with local time zone', 'size' => 3]], | ||
['interval year to month', ['type' => 'interval year to month']], | ||
]; | ||
} | ||
} |