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