Skip to content

Commit 6078af6

Browse files
authored
Merge pull request #19 from kojirock5260/feature/edit_extractTokens_for_default_0
create table default data for integer
2 parents 28e0a93 + 17102a6 commit 6078af6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Parser/CreateTableParser.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ private function extractTokens(string $sql, array $source_map): array
669669
$i = 0;
670670
$len = \count($source_map);
671671
while ($i < $len) {
672-
$token = \substr($sql, $source_map[$i][0], $source_map[$i][1]) ?: '';
672+
$token = \substr($sql, $source_map[$i][0], $source_map[$i][1]);
673+
$token = $token !== false ? $token : '';
673674
$tokenUpper = \strtoupper($token);
674675
if (\array_key_exists($tokenUpper, $maps)) {
675676
$found = false;

tests/CreateTableParseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testSimpleParse()
1414

1515
$create_queries = (new \Vimeo\MysqlEngine\Parser\CreateTableParser)->parse($query);
1616

17-
$this->assertCount(4, $create_queries);
17+
$this->assertCount(5, $create_queries);
1818

1919
foreach ($create_queries as $create_query) {
2020
$table = \Vimeo\MysqlEngine\Processor\CreateProcessor::makeTableDefinition(

tests/fixtures/create_table.sql

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ CREATE TABLE `transactions` (
5050
`other_tax` DECIMAL(12, 2) DEFAULT NULL,
5151
PRIMARY KEY (`id`)
5252
)
53-
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
53+
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
54+
55+
CREATE TABLE `orders`
56+
(
57+
`id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT,
58+
`user_id` INTEGER(11) UNSIGNED,
59+
`price` INTEGER(11) UNSIGNED NOT NULL DEFAULT 0,
60+
`created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
61+
`modified_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
62+
PRIMARY KEY (`id`)
63+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

0 commit comments

Comments
 (0)