Skip to content

create table default data for integer #19

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;