From: John Napiorkowski Date: Thu, 20 Oct 2011 18:55:44 +0000 (-0400) Subject: in the case where there is a multi field PK and a field is marked as autoinc, do... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fpeople%2Fjnap%2Fsqlite_multifieldpk_autoinc;p=dbsrgits%2FSQL-Translator.git in the case where there is a multi field PK and a field is marked as autoinc, do something that mostly works --- diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 1838e5f..2f93d28 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -297,21 +297,26 @@ sub create_field my $pk = $field->table->primary_key; my @pk_fields = $pk ? $pk->fields : (); - if ( - $field->is_primary_key && - scalar @pk_fields == 1 && - ( + if( + $field->is_primary_key && ( $data_type =~ /int(eger)?$/i || ( $data_type =~ /^number?$/i && $size !~ /,/ ) - ) - ) { - $data_type = 'INTEGER PRIMARY KEY'; - $size = undef; -# $pk_set = 1; + ) + ) { + if(scalar @pk_fields == 1) { + $data_type = 'INTEGER PRIMARY KEY'; + $size = undef; +# $pk_set = 1; + + } elsif(scalar(@pk_fields) > 1 && $field->is_auto_increment) { + $data_type = 'INTEGER DEFAULT (LAST_INSERT_ROWID())'; + $size = undef; + + } } - $field_def .= sprintf " %s%s", $data_type, + $field_def .= sprintf " %s%s", $data_type, ( !$field->is_auto_increment && $size ) ? "($size)" : ''; # Null?