- Allen Day <allenday@users.sourceforge.net>
- Anders Nor Berle <berle@cpan.org>
- Andrew Moore <amoore@cpan.org>
+- Arthur Axel "fREW" Schmidt <frioux@gmail.com>
- Ben Faga <faga@cshl.edu>
- Chris Hilton <chilton@alterpoint.com>
- Chris Mungall <cjm@fruitfly.org>
+* Correctly create and parse FK constraints in SQLite
* Correct postgis geography type insertion and linebreak fix for multiple geometry/geography columns
* made PostgreSQL producer consistent with other producers in terms of
quoting and allowing functions in constraints and indices
on_conflict => $item[5][0],
}
}
+ |
+ FOREIGN_KEY parens_field_list REFERENCES ref_def
+ {
+ $return = {
+ supertype => 'constraint',
+ type => 'foreign_key',
+ fields => $item[2],
+ reference_table => $item[4]{'reference_table'},
+ reference_fields => $item[4]{'reference_fields'},
+ }
+ }
ref_def : /(\w+)\s*\((\w+)\)/
{ $return = { reference_table => $1, reference_fields => $2 } }
PRIMARY_KEY : /primary key/i
+FOREIGN_KEY : /foreign key/i
+
CHECK_C : /check/i
DEFAULT : /default/i
#
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);
}
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) = @_;
CREATE TEMPORARY TABLE employee_temp_alter (
position varchar(50) NOT NULL,
employee_id int(11) NOT NULL,
- PRIMARY KEY (position, employee_id)
+ PRIMARY KEY (position, employee_id),
+ FOREIGN KEY(employee_id) REFERENCES person(person_id)
);
INSERT INTO employee_temp_alter SELECT position, employee_id FROM employee;
CREATE TABLE employee (
position varchar(50) NOT NULL,
employee_id int(11) NOT NULL,
- PRIMARY KEY (position, employee_id)
+ PRIMARY KEY (position, employee_id),
+ FOREIGN KEY(employee_id) REFERENCES person(person_id)
);
INSERT INTO employee SELECT position, employee_id FROM employee_temp_alter;
-- Hello emptytagdef
emptytagdef varchar DEFAULT '',
another_id int(10) DEFAULT 2,
- timest timestamp
+ timest timestamp,
+ FOREIGN KEY(another_id) REFERENCES Another()
);
CREATE INDEX titleindex ON Basic (title);
-- Hello emptytagdef
emptytagdef varchar DEFAULT \'\',
another_id int(10) DEFAULT 2,
- timest timestamp
+ timest timestamp,
+ FOREIGN KEY(another_id) REFERENCES Another()
)',
'CREATE INDEX titleindex ON Basic (title)',
'CREATE UNIQUE INDEX emailuniqueindex ON Basic (email)',