From: Arthur Axel 'fREW' Schmidt Date: Thu, 31 Oct 2013 13:27:12 +0000 (-0500) Subject: Revert "Fixed autoincrement in primary keys for SQLite" X-Git-Tag: v0.011018~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7313cecbe6f1660e72486d0d6cf41437632d6223;p=dbsrgits%2FSQL-Translator.git Revert "Fixed autoincrement in primary keys for SQLite" This reverts commit 03b0fa258c8580135c282b0282b5c7dcb0865c14. This turns out to break far more than I expected it would. See discussion here: https://github.com/dbsrgits/sql-translator/pull/26 --- diff --git a/AUTHORS b/AUTHORS index 3e94545..1096342 100644 --- a/AUTHORS +++ b/AUTHORS @@ -45,7 +45,6 @@ The following people have contributed to the SQLFairy project: - Paul Harrington - Peter Rabbitson - Robert Bohne -- Rafael Porres Molina - Ross Smith II - Ryan D Johnson - Salvatore Bonaccorso diff --git a/Changes b/Changes index 1769f36..8ed52c6 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Changes for SQL::Translator + * Revert "Fix AUTOINCREMENT in SQLite" + 0.11017 2013-10-30 * Apply quotes to fix tables that are reserved words, DBI::SQLServer (Jonathan C. Otsuka) diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm index 5a60d51..0f55fd9 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLite.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLite.pm @@ -78,13 +78,12 @@ sub _ipk { sub field { my ($self, $field) = @_; + return join ' ', $self->field_comments($field), $self->field_name($field), ( $self->_ipk($field) - ? $field->is_auto_increment - ? ( 'INTEGER PRIMARY KEY AUTOINCREMENT' ) - : ( 'INTEGER PRIMARY KEY' ) + ? ( 'INTEGER PRIMARY KEY' ) : ( $self->field_type($field) ) ), $self->field_nullable($field), diff --git a/t/30sqlt-new-diff-sqlite.t b/t/30sqlt-new-diff-sqlite.t index 00272ca..ef7fee7 100644 --- a/t/30sqlt-new-diff-sqlite.t +++ b/t/30sqlt-new-diff-sqlite.t @@ -122,7 +122,7 @@ ALTER TABLE old_name RENAME TO new_name; ALTER TABLE new_name ADD COLUMN new_field int; CREATE TEMPORARY TABLE person_temp_alter ( - person_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + person_id INTEGER PRIMARY KEY NOT NULL, name varchar(20) NOT NULL, age int(11) DEFAULT 18, weight double(11,2), @@ -136,7 +136,7 @@ INSERT INTO person_temp_alter( person_id, name, age, weight, iq, is_rock_star, p DROP TABLE person; CREATE TABLE person ( - person_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + person_id INTEGER PRIMARY KEY NOT NULL, name varchar(20) NOT NULL, age int(11) DEFAULT 18, weight double(11,2), diff --git a/t/48xml-to-sqlite.t b/t/48xml-to-sqlite.t index b7b6e32..21e8ad3 100644 --- a/t/48xml-to-sqlite.t +++ b/t/48xml-to-sqlite.t @@ -40,7 +40,7 @@ BEGIN TRANSACTION; DROP TABLE "Basic"; CREATE TABLE "Basic" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "id" INTEGER PRIMARY KEY NOT NULL, "title" varchar(100) NOT NULL DEFAULT 'hello', "description" text DEFAULT '', "email" varchar(500), @@ -62,7 +62,7 @@ CREATE UNIQUE INDEX "very_long_index_name_on_title_field_which_should_be_truncat DROP TABLE "Another"; CREATE TABLE "Another" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "id" INTEGER PRIMARY KEY NOT NULL, "num" numeric(10,2) ); @@ -98,7 +98,7 @@ eq_or_diff(\@sql, 'BEGIN TRANSACTION', q, q, q, q, q, @@ -130,3 +130,5 @@ eq_or_diff(\@sql, 'COMMIT', ], 'SQLite translate in list context matches'); + + diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index 2129c29..5d56adf 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -164,40 +164,4 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0; is_deeply($result, $expected, 'correctly unquoted excempted DEFAULTs'); } -{ - my $table = SQL::Translator::Schema::Table->new( - name => 'foo_auto_increment', - ); - $table->add_field( - name => 'id', - data_type => 'integer', - is_nullable => 0, - is_auto_increment => 1, - ); - $table->primary_key('id'); - my $expected = [ qq]; - my $result = [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })]; - is_deeply($result, $expected, 'correctly built table with autoincrement on primary key'); -} - -{ - my $table = SQL::Translator::Schema::Table->new( - name => 'foo_no_auto_increment', - ); - $table->add_field( - name => 'id', - data_type => 'integer', - is_nullable => 0, - is_auto_increment => 0, - ); - $table->primary_key('id'); - my $expected = [ qq]; - my $result = [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })]; - is_deeply($result, $expected, 'correctly built table without autoincrement on primary key'); -} - done_testing;