From: Darren Chamberlain Date: Tue, 11 Jan 2011 16:56:22 +0000 (+0000) Subject: Merging patch from ddascalescu+perl@gmail.com, for https://rt.cpan.org/Ticket/Display... X-Git-Tag: v0.11008~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=431151a91858558a31eff837eee3bcb3ae6a8a5f;p=dbsrgits%2FSQL-Translator.git Merging patch from ddascalescu+perl@gmail.com, for https://rt.cpan.org/Ticket/Display.html?id=44769. I've not tested it. --- diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 2e7aa6a..d7d3816 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -234,6 +234,9 @@ sub create_table # my $c_name_default = 'A'; for my $c ( $table->get_constraints ) { + if ($c->type eq "FOREIGN KEY") { + push @field_defs, create_foreignkey($c); + } next unless $c->type eq UNIQUE; push @constraint_defs, create_constraint($c); } @@ -243,6 +246,15 @@ sub create_table return (@create, $create_table, @index_defs, @constraint_defs ); } +sub create_foreignkey { + my $c = shift; + + my $fk_sql = "FOREIGN KEY(".$c->{fields}[0].") REFERENCES "; + $fk_sql .= $c->{reference_table}."(".$c->{reference_fields}[0].")"; + + return $fk_sql; +} + sub create_field { my ($field, $options) = @_;