From: Arthur Axel 'fREW' Schmidt Date: Mon, 30 Apr 2012 14:45:04 +0000 (-0500) Subject: fix list of numeric types for SQLite X-Git-Tag: v0.11011~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27f0e868b86375ba0b46a0577a190b76f2887bf3;p=dbsrgits%2FSQL-Translator.git fix list of numeric types for SQLite See http://www.sqlite.org/datatype3.html --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm index 681c116..c195ea2 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLite.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLite.pm @@ -21,7 +21,26 @@ sub _build_type_map { } sub _build_sizeless_types { +{ text => 1 } } -sub _build_numeric_types { +{ int => 1, tinyint => 1 } } +sub _build_numeric_types { + +{ + int => 1, + integer => 1, + tinyint => 1, + smallint => 1, + mediumint => 1, + bigint => 1, + 'unsigned big int' => 1, + int2 => 1, + int8 => 1, + numeric => 1, + decimal => 1, + boolean => 1, + real => 1, + double => 1, + 'double precision' => 1, + float => 1, + } +} sub _build_unquoted_defaults { +{ diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index a83cbe6..3151ddb 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -2,9 +2,8 @@ # vim: set ft=perl: use strict; -use Test::More tests => 3; +use Test::More; use Test::SQL::Translator qw(maybe_plan); -use FindBin qw/$Bin/; use SQL::Translator::Schema::View; use SQL::Translator::Schema::Table; @@ -45,6 +44,7 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0; $table->add_field( name => 'foreign_key', data_type => 'integer', + default_value => 1, ); my $constraint = SQL::Translator::Schema::Constraint->new( table => $table, @@ -56,8 +56,22 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0; on_delete => 'RESTRICT', on_update => 'CASCADE', ); - my $expected = [ 'FOREIGN KEY ("foreign_key") REFERENCES "foo"("id") ON DELETE RESTRICT ON UPDATE CASCADE']; my $result = [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)]; is_deeply($result, $expected, 'correct "FOREIGN KEY"'); } +{ + my $table = SQL::Translator::Schema::Table->new( + name => 'foo_table', + ); + $table->add_field( + name => 'id', + data_type => 'integer', + default_value => 1, + ); + my $expected = [ qq]; + my $result = [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })]; + is_deeply($result, $expected, 'correctly unquoted DEFAULT'); +} + +done_testing;