Skip to content

Commit

Permalink
Included support for double unsigned column type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Cima committed Apr 29, 2016
1 parent 5ec8a7c commit 98aa4ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/RegExpPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RegExpPattern
'binary',
'real',
'decimal\((?<decimalLength>\d+),(?<decimalPrecision>\d+)\)',
'double(?:\((?<doubleLength>\d+),(?<doublePrecision>\d+)\))?',
'double(?:\((?<doubleLength>\d+),(?<doublePrecision>\d+)\))?(?:\s+unsigned)?',
'datetime',
'date',
'time',
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function column()
*/
public static function dataType()
{
return '/(?<dataType>[^\(]+)\s*(?:\([^\)]+\))?\s*(?<unsigned>unsigned)?/';
return '/(?<dataType>[^\(\s]+)\s*(?:\([^\)]+\))?\s*(?<unsigned>unsigned)?/';
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,17 @@ public function testIsParsingTableWithPartitionDefinitions()
$this->assertCount(1, $database->getTables());
$this->assertCount(9, $database->getTableByName('export')->getColumns());
}

public function testIsParsingDoubleUnsignedType()
{
$parser = new Parser();

$database = $parser->parseDatabase($this->getDatabaseFixture('jos_finder_links.sql'));

$this->assertInstanceOf(Database::class, $database);
$this->assertCount(1, $database->getTables());
$this->assertCount(19, $database->getTableByName('jos_finder_links')->getColumns());
$this->assertEquals('double unsigned', $database->getTableByName('jos_finder_links')->getColumnByName('list_price')->getColumnType());
$this->assertEquals('double', $database->getTableByName('jos_finder_links')->getColumnByName('list_price')->getDataType());
}
}
28 changes: 28 additions & 0 deletions tests/fixtures/jos_finder_links.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE `jos_finder_links` (
`link_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`url` varchar(255) NOT NULL,
`route` varchar(255) NOT NULL,
`title` varchar(400) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`indexdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`md5sum` varchar(32) DEFAULT NULL,
`published` tinyint(1) NOT NULL DEFAULT '1',
`state` int(5) DEFAULT '1',
`access` int(5) DEFAULT '0',
`language` varchar(8) NOT NULL,
`publish_start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`publish_end_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`end_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`list_price` double unsigned NOT NULL DEFAULT '0',
`sale_price` double unsigned NOT NULL DEFAULT '0',
`type_id` int(11) NOT NULL,
`object` mediumblob NOT NULL,
PRIMARY KEY (`link_id`),
KEY `idx_type` (`type_id`),
KEY `idx_md5` (`md5sum`),
KEY `idx_url` (`url`(75)),
KEY `idx_published_list` (`published`,`state`,`access`,`publish_start_date`,`publish_end_date`,`list_price`),
KEY `idx_published_sale` (`published`,`state`,`access`,`publish_start_date`,`publish_end_date`,`sale_price`),
KEY `idx_title` (`title`(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

0 comments on commit 98aa4ed

Please sign in to comment.