1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
8use Test::SQL::Translator qw(maybe_plan);
9
10use Data::Dumper;
11use FindBin qw/$Bin/;
12
13# Testing 1,2,3,4...
14#=============================================================================
15
16BEGIN {
17    maybe_plan(4,
18        'SQL::Translator::Producer::DB2',
19        'Test::Differences',
20    )
21}
22use Test::Differences;
23use SQL::Translator;
24
25
26
27my $table = SQL::Translator::Schema::Table->new( name => 'mytable');
28
29my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield',
30                                                  table => $table,
31                                                  data_type => 'VARCHAR',
32                                                  size => 10,
33                                                  default_value => undef,
34                                                  is_auto_increment => 0,
35                                                  is_nullable => 1,
36                                                  is_foreign_key => 0,
37                                                  is_unique => 0 );
38
39my $field1_sql = SQL::Translator::Producer::DB2::create_field($field1);
40
41is($field1_sql, 'myfield VARCHAR(10)', 'Create field works');
42
43my $field2 = SQL::Translator::Schema::Field->new( name      => 'myfield',
44                                                  table => $table,
45                                                  data_type => 'VARCHAR',
46                                                  size      => 25,
47                                                  default_value => undef,
48                                                  is_auto_increment => 0,
49                                                  is_nullable => 0,
50                                                  is_foreign_key => 0,
51                                                  is_unique => 0 );
52
53my $alter_field = SQL::Translator::Producer::DB2::alter_field($field1,
54                                                                $field2);
55is($alter_field, 'ALTER TABLE mytable ALTER myfield SET DATATYPE VARCHAR(25)', 'Alter field works');
56
57my $add_field = SQL::Translator::Producer::DB2::add_field($field1);
58
59is($add_field, 'ALTER TABLE mytable ADD COLUMN myfield VARCHAR(10)', 'Add field works');
60
61my $drop_field = SQL::Translator::Producer::DB2::drop_field($field2);
62is($drop_field, '', 'Drop field works');
63