With time couple DBIHacks methods became single-callsite only
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO / MS_Jet.pm
CommitLineData
726c8f65 1package DBIx::Class::Storage::DBI::ADO::MS_Jet;
2
3use strict;
4use warnings;
5use base qw/
6 DBIx::Class::Storage::DBI::ADO
7 DBIx::Class::Storage::DBI::ACCESS
8/;
9use mro 'c3';
2edf3352 10use DBIx::Class::Storage::DBI::ADO::CursorUtils '_normalize_guids';
11use namespace::clean;
726c8f65 12
13__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
14
15=head1 NAME
16
17DBIx::Class::Storage::DBI::ADO::MS_Jet - Support for MS Access over ADO
18
19=head1 DESCRIPTION
20
21This driver is a subclass of L<DBIx::Class::Storage::DBI::ADO> and
22L<DBIx::Class::Storage::DBI::ACCESS> for connecting to MS Access via
23L<DBD::ADO>.
24
25See the documentation for L<DBIx::Class::Storage::DBI::ACCESS> for
26information on the MS Access driver for L<DBIx::Class>.
27
28This driver implements workarounds for C<TEXT/IMAGE/MEMO> columns, sets the
29L<cursor_class|DBIx::Class::Storage::DBI/cursor_class> to
30L<DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor> to normalize returned
31C<GUID> values and provides L<DBIx::Class::InflateColumn::DateTime> support
32for C<DATETIME> columns.
33
34=head1 EXAMPLE DSNs
35
36 # older Access versions:
37 dbi:ADO:Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb
38
39 # newer Access versions:
40 dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb;Persist Security Info=False'
41
42=head1 TEXT/IMAGE/MEMO COLUMNS
43
44The ADO driver does not suffer from the
45L<problems|DBIx::Class::Storage::DBI::ODBC::ACCESS/"TEXT/IMAGE/MEMO COLUMNS">
46the L<ODBC|DBIx::Class::Storage::DBI::ODBC::ACCESS> driver has with these types
47of columns. You can use them safely.
48
49When you execute a C<CREATE TABLE> statement over this driver with a C<TEXT>
50column, it will be converted to C<MEMO>, while in the
51L<ODBC|DBIx::Class::Storage::DBI::ODBC::ACCESS> driver it is converted to
52C<VARCHAR(255)>.
53
54However, the caveat about L<LongReadLen|DBI/LongReadLen> having to be twice the
55max size of your largest C<MEMO/TEXT> column C<+1> still applies. L<DBD::ADO>
56sets L<LongReadLen|DBI/LongReadLen> to a large value by default, so it should be
57safe to just leave it unset. If you do pass a L<LongReadLen|DBI/LongReadLen> in
58your L<connect_info|DBIx::Class::Storage::DBI/connect_info>, it will be
59multiplied by two and C<1> added, just as for the
60L<ODBC|DBIx::Class::Storage::DBI::ODBC::ACCESS> driver.
61
62=cut
63
64# set LongReadLen = LongReadLen * 2 + 1 (see docs on MEMO)
65sub _run_connection_actions {
66 my $self = shift;
67
68 my $long_read_len = $self->_dbh->{LongReadLen};
69
70# This is the DBD::ADO default.
71 if ($long_read_len != 2147483647) {
72 $self->_dbh->{LongReadLen} = $long_read_len * 2 + 1;
73 }
74
75 return $self->next::method(@_);
76}
77
78# AutoCommit does not get reset properly after transactions for some reason
79# (probably because of my nested transaction hacks in ACCESS.pm) fix it up
80# here.
81
90d7422f 82sub _exec_txn_commit {
726c8f65 83 my $self = shift;
84 $self->next::method(@_);
85 $self->_dbh->{AutoCommit} = $self->_dbh_autocommit
86 if $self->{transaction_depth} == 1;
87}
88
90d7422f 89sub _exec_txn_rollback {
726c8f65 90 my $self = shift;
91 $self->next::method(@_);
92 $self->_dbh->{AutoCommit} = $self->_dbh_autocommit
93 if $self->{transaction_depth} == 1;
94}
95
96# Fix up GUIDs for ->find, for cursors see the cursor_class above.
97
98sub select_single {
99 my $self = shift;
100 my ($ident, $select) = @_;
101
102 my @row = $self->next::method(@_);
103
104 return @row unless
105 $self->cursor_class->isa('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
106
2edf3352 107 my $col_infos = $self->_resolve_column_info($ident);
726c8f65 108
2edf3352 109 _normalize_guids($select, $col_infos, \@row, $self);
726c8f65 110
111 return @row;
112}
113
114sub datetime_parser_type {
115 'DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format'
116}
117
118package # hide from PAUSE
119 DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format;
120
121my $datetime_format = '%m/%d/%Y %I:%M:%S %p';
122my $datetime_parser;
123
124sub parse_datetime {
125 shift;
126 require DateTime::Format::Strptime;
127 $datetime_parser ||= DateTime::Format::Strptime->new(
128 pattern => $datetime_format,
129 on_error => 'croak',
130 );
131 return $datetime_parser->parse_datetime(shift);
132}
133
134sub format_datetime {
135 shift;
136 require DateTime::Format::Strptime;
137 $datetime_parser ||= DateTime::Format::Strptime->new(
138 pattern => $datetime_format,
139 on_error => 'croak',
140 );
141 return $datetime_parser->format_datetime(shift);
142}
143
a2bd3796 144=head1 FURTHER QUESTIONS?
726c8f65 145
a2bd3796 146Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
726c8f65 147
a2bd3796 148=head1 COPYRIGHT AND LICENSE
726c8f65 149
a2bd3796 150This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
151by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
152redistribute it and/or modify it under the same terms as the
153L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
726c8f65 154
155=cut
a2bd3796 156
1571;
158
726c8f65 159# vim:sts=2 sw=2: