Convert the tests with multiple DBDs to new optdeps system
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_11msaccess_common.t
CommitLineData
3b17d988 1use strict;
2use warnings;
3use Test::More;
4fb2971c 4use DBIx::Class::Optional::Dependencies;
3568bda9 5use DBIx::Class::Schema::Loader::DBI::ODBC::ACCESS ();
3b17d988 6use lib qw(t/lib);
7use dbixcsl_common_tests;
8
ffd4ce36 9my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(MSACCESS_ODBC MSACCESS_ADO);
10
11plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map
12 { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
13 values %env2optdep
14) unless scalar grep
15 { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) }
16 values %env2optdep
17;
18
4fb2971c 19my %dsns;
ffd4ce36 20for my $type (keys %env2optdep) {
21 my %conninfo;
22 @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS);
23 next unless $conninfo{dsn};
3b17d988 24
ffd4ce36 25 my $dep_group = $env2optdep{$type};
26 if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) {
27 diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group);
4fb2971c 28 next;
29 }
30
ffd4ce36 31 $dsns{$type} = \%conninfo;
32}
3b17d988 33
34my %ado_extra_types = (
35 'tinyint' => { data_type => 'tinyint', original => { data_type => 'byte' } },
36 'smallmoney' => { data_type => 'money', original => { data_type => 'currency' } },
37 'decimal' => { data_type => 'decimal' },
38 'decimal(3)' => { data_type => 'decimal', size => [3, 0] },
39 'decimal(3,3)'=> { data_type => 'decimal', size => [3, 3] },
40 'dec(5,5)' => { data_type => 'decimal', size => [5, 5] },
41 'numeric(2,2)'=> { data_type => 'decimal', size => [2, 2] },
42 'character' => { data_type => 'char', size => 255 },
43 'character varying(5)' => { data_type => 'varchar', size => 5 },
44 'nchar(5)' => { data_type => 'char', size => 5 },
45 'national character(5)' => { data_type => 'char', size => 5 },
46 'nvarchar(5)' => { data_type => 'varchar', size => 5 },
47 'national character varying(5)' => { data_type => 'varchar', size => 5 },
48 'national char varying(5)' => { data_type => 'varchar', size => 5 },
49 'smalldatetime' => { data_type => 'datetime' },
50 'uniqueidentifier' => { data_type => 'uniqueidentifier', original => { data_type => 'guid' } },
51 'text' => { data_type => 'text', original => { data_type => 'longchar' } },
52 'ntext' => { data_type => 'text', original => { data_type => 'longchar' } },
53);
54
55my $tester = dbixcsl_common_tests->new(
56 vendor => 'Access',
57 auto_inc_pk => 'AUTOINCREMENT PRIMARY KEY',
58 quote_char => [qw/[ ]/],
7336f5dc 59 connect_info => [ map { $dsns{$_} } sort keys %dsns ],
3b17d988 60 data_types => {
61 # http://msdn.microsoft.com/en-us/library/bb208866(v=office.12).aspx
62 #
63 # Numeric types
64 'autoincrement'=>{ data_type => 'integer', is_auto_increment => 1 },
65 'int' => { data_type => 'integer' },
66 'integer' => { data_type => 'integer' },
67 'long' => { data_type => 'integer' },
68 'integer4' => { data_type => 'integer' },
69 'smallint' => { data_type => 'smallint' },
70 'short' => { data_type => 'smallint' },
71 'integer2' => { data_type => 'smallint' },
72 'integer1' => { data_type => 'tinyint', original => { data_type => 'byte' } },
73 'byte' => { data_type => 'tinyint', original => { data_type => 'byte' } },
74 'bit' => { data_type => 'bit' },
75 'logical' => { data_type => 'bit' },
76 'logical1' => { data_type => 'bit' },
77 'yesno' => { data_type => 'bit' },
78 'money' => { data_type => 'money', original => { data_type => 'currency' } },
79 'currency' => { data_type => 'money', original => { data_type => 'currency' } },
80 'real' => { data_type => 'real' },
81 'single' => { data_type => 'real' },
82 'ieeesingle' => { data_type => 'real' },
83 'float4' => { data_type => 'real' },
84 'float' => { data_type => 'double precision', original => { data_type => 'double' } },
85 'float' => { data_type => 'double precision', original => { data_type => 'double' } },
86 'float8' => { data_type => 'double precision', original => { data_type => 'double' } },
87 'double' => { data_type => 'double precision', original => { data_type => 'double' } },
88 'ieeedouble' => { data_type => 'double precision', original => { data_type => 'double' } },
89 'number' => { data_type => 'double precision', original => { data_type => 'double' } },
90
91# # character types
92 'text(25)' => { data_type => 'varchar', size => 25 },
93 'char' => { data_type => 'char', size => 255 },
94 'char(5)' => { data_type => 'char', size => 5 },
95 'string(5)' => { data_type => 'varchar', size => 5 },
96 'varchar(5)' => { data_type => 'varchar', size => 5 },
97
98 # binary types
99 'binary(10)' => { data_type => 'binary', size => 10 },
100 'varbinary(11)' => { data_type => 'varbinary', size => 11 },
101
102 # datetime types
103 'datetime' => { data_type => 'datetime' },
104 'time' => { data_type => 'datetime' },
105 'timestamp' => { data_type => 'datetime' },
106
107 # misc types
108 'guid' => { data_type => 'uniqueidentifier', original => { data_type => 'guid' } },
109
110 # blob types
111 'longchar' => { data_type => 'text', original => { data_type => 'longchar' } },
112 'longtext' => { data_type => 'text', original => { data_type => 'longchar' } },
113 'memo' => { data_type => 'text', original => { data_type => 'longchar' } },
114 'image' => { data_type => 'image', original => { data_type => 'longbinary' } },
115 'longbinary' => { data_type => 'image', original => { data_type => 'longbinary' } },
116
3568bda9 117 %ado_extra_types,
118 },
119 data_types_ddl_cb => sub {
120 my $ddl = shift;
121 {
122 package DBIXCSL_Test::DummySchema;
123 use base 'DBIx::Class::Schema';
124 }
4fb2971c 125 my @connect_info = @{$dsns{MSACCESS_ODBC} || $dsns{MSACCESS_ADO}};
3568bda9 126
127 my $schema = DBIXCSL_Test::DummySchema->connect(@connect_info);
128
129 my $loader = DBIx::Class::Schema::Loader::DBI::ODBC::ACCESS->new(
130 schema => $schema,
131 naming => 'current',
132 );
133
134 my $conn = $loader->_ado_connection;
135
9ef345a5 136 require Win32::OLE;
3568bda9 137 my $comm = Win32::OLE->new('ADODB.Command');
138
139 $comm->{ActiveConnection} = $conn;
140 $comm->{CommandText} = $ddl;
141 $comm->Execute;
3b17d988 142 },
143);
144
4fb2971c 145$tester->run_tests();
3b17d988 146
147# vim:et sts=4 sw=4 tw=0: