auto-disambiguate monikers from different schemas
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_11msaccess_common.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use DBIx::Class::Schema::Loader::DBI::ODBC::ACCESS ();
5 use lib qw(t/lib);
6 use dbixcsl_common_tests;
7
8 my $odbc_dsn      = $ENV{DBICTEST_MSACCESS_ODBC_DSN} || '';
9 my $odbc_user     = $ENV{DBICTEST_MSACCESS_ODBC_USER} || '';
10 my $odbc_password = $ENV{DBICTEST_MSACCESS_ODBC_PASS} || '';
11
12 my $ado_dsn       = $ENV{DBICTEST_MSACCESS_ADO_DSN} || '';
13 my $ado_user      = $ENV{DBICTEST_MSACCESS_ADO_USER} || '';
14 my $ado_password  = $ENV{DBICTEST_MSACCESS_ADO_PASS} || '';
15
16 my %ado_extra_types = (
17     'tinyint'     => { data_type => 'tinyint', original => { data_type => 'byte' } },
18     'smallmoney'  => { data_type => 'money', original => { data_type => 'currency' } },
19     'decimal'     => { data_type => 'decimal' },
20     'decimal(3)'  => { data_type => 'decimal', size => [3, 0] },
21     'decimal(3,3)'=> { data_type => 'decimal', size => [3, 3] },
22     'dec(5,5)'    => { data_type => 'decimal', size => [5, 5] },
23     'numeric(2,2)'=> { data_type => 'decimal', size => [2, 2] },
24     'character'   => { data_type => 'char', size => 255 },
25     'character varying(5)'  => { data_type => 'varchar', size => 5 },
26     'nchar(5)'    => { data_type => 'char', size => 5 },
27     'national character(5)' => { data_type => 'char', size => 5 },
28     'nvarchar(5)' => { data_type => 'varchar', size => 5 },
29     'national character varying(5)' => { data_type => 'varchar', size => 5 },
30     'national char varying(5)' => { data_type => 'varchar', size => 5 },
31     'smalldatetime' => { data_type => 'datetime' },
32     'uniqueidentifier' => { data_type => 'uniqueidentifier', original => { data_type => 'guid' } },
33     'text'        => { data_type => 'text', original => { data_type => 'longchar' } },
34     'ntext'       => { data_type => 'text', original => { data_type => 'longchar' } },
35 );
36
37 my $tester = dbixcsl_common_tests->new(
38     vendor      => 'Access',
39     auto_inc_pk => 'AUTOINCREMENT PRIMARY KEY',
40     quote_char  => [qw/[ ]/],
41     connect_info => [ ($odbc_dsn ? {
42             dsn         => $odbc_dsn,
43             user        => $odbc_user,
44             password    => $odbc_password,
45         } : ()),
46         ($ado_dsn ? {
47             dsn         => $ado_dsn,
48             user        => $ado_user,
49             password    => $ado_password,
50         } : ()),
51     ],
52     data_types  => {
53         # http://msdn.microsoft.com/en-us/library/bb208866(v=office.12).aspx
54         #
55         # Numeric types
56         'autoincrement'=>{ data_type => 'integer', is_auto_increment => 1 },
57         'int'         => { data_type => 'integer' },
58         'integer'     => { data_type => 'integer' },
59         'long'        => { data_type => 'integer' },
60         'integer4'    => { data_type => 'integer' },
61         'smallint'    => { data_type => 'smallint' },
62         'short'       => { data_type => 'smallint' },
63         'integer2'    => { data_type => 'smallint' },
64         'integer1'    => { data_type => 'tinyint', original => { data_type => 'byte' } },
65         'byte'        => { data_type => 'tinyint', original => { data_type => 'byte' } },
66         'bit'         => { data_type => 'bit' },
67         'logical'     => { data_type => 'bit' },
68         'logical1'    => { data_type => 'bit' },
69         'yesno'       => { data_type => 'bit' },
70         'money'       => { data_type => 'money', original => { data_type => 'currency' } },
71         'currency'    => { data_type => 'money', original => { data_type => 'currency' } },
72         'real'        => { data_type => 'real' },
73         'single'      => { data_type => 'real' },
74         'ieeesingle'  => { data_type => 'real' },
75         'float4'      => { data_type => 'real' },
76         'float'       => { data_type => 'double precision', original => { data_type => 'double' } },
77         'float'       => { data_type => 'double precision', original => { data_type => 'double' } },
78         'float8'      => { data_type => 'double precision', original => { data_type => 'double' } },
79         'double'      => { data_type => 'double precision', original => { data_type => 'double' } },
80         'ieeedouble'  => { data_type => 'double precision', original => { data_type => 'double' } },
81         'number'      => { data_type => 'double precision', original => { data_type => 'double' } },
82
83 #        # character types
84         'text(25)'    => { data_type => 'varchar', size => 25 },
85         'char'        => { data_type => 'char', size => 255 },
86         'char(5)'     => { data_type => 'char', size => 5 },
87         'string(5)'   => { data_type => 'varchar', size => 5 },
88         'varchar(5)'  => { data_type => 'varchar', size => 5 },
89
90         # binary types
91         'binary(10)'  => { data_type => 'binary', size => 10 },
92         'varbinary(11)' => { data_type => 'varbinary', size => 11 },
93
94         # datetime types
95         'datetime'    => { data_type => 'datetime' },
96         'time'        => { data_type => 'datetime' },
97         'timestamp'   => { data_type => 'datetime' },
98
99         # misc types
100         'guid'        => { data_type => 'uniqueidentifier', original => { data_type => 'guid' } },
101
102         # blob types
103         'longchar'    => { data_type => 'text', original => { data_type => 'longchar' } },
104         'longtext'    => { data_type => 'text', original => { data_type => 'longchar' } },
105         'memo'        => { data_type => 'text', original => { data_type => 'longchar' } },
106         'image'       => { data_type => 'image', original => { data_type => 'longbinary' } },
107         'longbinary'  => { data_type => 'image', original => { data_type => 'longbinary' } },
108
109         %ado_extra_types,
110     },
111     data_types_ddl_cb => sub {
112         my $ddl = shift;
113         {
114             package DBIXCSL_Test::DummySchema;
115             use base 'DBIx::Class::Schema';
116         }
117         my @connect_info = $odbc_dsn ? ($odbc_dsn, $odbc_user, $odbc_password)
118                                      : ($ado_dsn,  $ado_user,  $ado_password);
119
120         my $schema = DBIXCSL_Test::DummySchema->connect(@connect_info);
121
122         my $loader = DBIx::Class::Schema::Loader::DBI::ODBC::ACCESS->new(
123             schema => $schema,
124             naming => 'current',
125         );
126
127         my $conn = $loader->_ado_connection;
128
129         require Win32::OLE;
130         my $comm = Win32::OLE->new('ADODB.Command');
131
132         $comm->{ActiveConnection} = $conn;
133         $comm->{CommandText}      = $ddl;
134         $comm->Execute;
135     },
136 );
137
138 if (not ($odbc_dsn || $ado_dsn)) {
139     $tester->skip_tests('You need to set the DBICTEST_MSACCESS_ODBC_DSN, and optionally _USER and _PASS and/or the DBICTEST_MSACCESS_ADO_DSN, and optionally _USER and _PASS environment variables');
140 }
141 else {
142     $tester->run_tests();
143 }
144
145 # vim:et sts=4 sw=4 tw=0: