5 use_ok( "SQL::Translator" );
6 use_ok( "SQL::Translator::Parser::MySQL" );
7 use_ok( "SQL::Translator::Producer::SQLite" );
9 # This test reproduces a bug in SQL::Translator::Producer::SQLite.
11 # When tables are created their names are not added to %global_names, and
14 # SQL::Translator::Producer::SQLite version 1.59.
15 # compliments of SymKat <symkat@symkat.com>
19 my $output = SQL::Translator
20 ->new( data => do { local $/; <DATA> })
21 ->translate( from => 'MySQL', to => 'SQLite' );
23 sub find_table_names {
27 for my $line ( split /\n/, $content ) {
28 if ($content =~ /CREATE (?:INDEX|UNIQUE|TABLE| ){0,6} ([^\s]+)/gc) {
39 for my $elem ( @list ) {
40 return 0 if exists $hist{$elem};
46 ok ( has_dupes( find_table_names( $output ) ) );
51 CREATE TABLE `ip_address` (
52 `id` int(11) NOT NULL auto_increment,
53 `ip_address` varchar(255) NOT NULL,
54 `machine_id` int(11) default NULL,
55 `primary_machine_id` int(11) default NULL,
56 `secondary_machine_id` int(11) default NULL,
57 `tertiary_machine_id` int(11) default NULL,
58 `protocol` enum('ipv4','ipv6') NOT NULL default 'ipv4',
59 `shared` tinyint(1) NOT NULL default '1',
61 UNIQUE KEY `ip_address` (`ip_address`),
62 KEY `machine_id` (`machine_id`),
63 KEY `primary_machine_id` (`primary_machine_id`),
64 KEY `secondary_machine_id` (`secondary_machine_id`),
65 KEY `tertiary_machine_id` (`tertiary_machine_id`),
66 CONSTRAINT `ip_address_ibfk_1` FOREIGN KEY (`machine_id`) REFERENCES `machine` (`id`),
67 CONSTRAINT `ip_address_ibfk_2` FOREIGN KEY (`primary_machine_id`) REFERENCES `machine` (`id`),
68 CONSTRAINT `ip_address_ibfk_3` FOREIGN KEY (`secondary_machine_id`) REFERENCES `machine` (`id`),
69 CONSTRAINT `ip_address_ibfk_4` FOREIGN KEY (`tertiary_machine_id`) REFERENCES `machine` (`id`)