Skip to content

Commit

Permalink
Merge pull request #19 from kojirock5260/feature/edit_extractTokens_f…
Browse files Browse the repository at this point in the history
…or_default_0

create table default data for integer
  • Loading branch information
muglug authored Apr 14, 2021
2 parents 28e0a93 + 17102a6 commit 6078af6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Parser/CreateTableParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ private function extractTokens(string $sql, array $source_map): array
$i = 0;
$len = \count($source_map);
while ($i < $len) {
$token = \substr($sql, $source_map[$i][0], $source_map[$i][1]) ?: '';
$token = \substr($sql, $source_map[$i][0], $source_map[$i][1]);
$token = $token !== false ? $token : '';
$tokenUpper = \strtoupper($token);
if (\array_key_exists($tokenUpper, $maps)) {
$found = false;
Expand Down
2 changes: 1 addition & 1 deletion tests/CreateTableParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testSimpleParse()

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

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

foreach ($create_queries as $create_query) {
$table = \Vimeo\MysqlEngine\Processor\CreateProcessor::makeTableDefinition(
Expand Down
12 changes: 11 additions & 1 deletion tests/fixtures/create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ CREATE TABLE `transactions` (
`other_tax` DECIMAL(12, 2) DEFAULT NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `orders`
(
`id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INTEGER(11) UNSIGNED,
`price` INTEGER(11) UNSIGNED NOT NULL DEFAULT 0,
`created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

0 comments on commit 6078af6

Please sign in to comment.