1 package DBIx::Class::Storage::DBI::ODBC::ACCESS;
6 DBIx::Class::Storage::DBI::ODBC
7 DBIx::Class::Storage::DBI::ACCESS
11 __PACKAGE__->mk_group_accessors(inherited =>
12 'disable_sth_caching_for_image_insert_or_update'
15 __PACKAGE__->disable_sth_caching_for_image_insert_or_update(1);
19 DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC
23 This class implements support specific to Microsoft Access over ODBC.
25 It is a subclass of L<DBIx::Class::Storage::DBI::ODBC> and
26 L<DBIx::Class::Storage::DBI::ACCESS>, see those classes for more
29 It is loaded automatically by L<DBIx::Class::Storage::DBI::ODBC> when it
30 detects a MS Access back-end.
32 This driver implements workarounds for C<IMAGE> and C<MEMO> columns, and
33 L<DBIx::Class::InflateColumn::DateTime> support for C<DATETIME> columns.
37 dbi:ODBC:driver={Microsoft Access Driver (*.mdb, *.accdb)};dbq=C:\Users\rkitover\Documents\access_sample.accdb
39 =head1 TEXT/IMAGE/MEMO COLUMNS
41 Avoid using C<TEXT> columns as they will be truncated to 255 bytes. Some other
42 drivers (like L<ADO|DBIx::Class::Storage::DBI::ADO::MS_Jet>) will automatically
43 convert C<TEXT> columns to C<MEMO>, but the ODBC driver does not.
45 C<IMAGE> columns work correctly, but the statements for inserting or updating an
46 C<IMAGE> column will not be L<cached|DBI/prepare_cached>, due to a bug in the
49 C<MEMO> columns work correctly as well, but you must take care to set
50 L<LongReadLen|DBI/LongReadLen> to C<$max_memo_size * 2 + 1>. This is done for
51 you automatically if you pass L<LongReadLen|DBI/LongReadLen> in your
52 L<connect_info|DBIx::Class::Storage::DBI/connect_info>; but if you set this
53 attribute directly on the C<$dbh>, keep this limitation in mind.
57 # set LongReadLen = LongReadLen * 2 + 1 (see docs on MEMO)
58 sub _run_connection_actions {
61 my $long_read_len = $self->_dbh->{LongReadLen};
63 # 80 is another default (just like 0) on some drivers
64 if ($long_read_len != 0 && $long_read_len != 80) {
65 $self->_dbh->{LongReadLen} = $long_read_len * 2 + 1;
68 # batch operations do not work
69 $self->_disable_odbc_array_ops;
71 return $self->next::method(@_);
76 my ($source, $to_insert) = @_;
78 my $columns_info = $source->columns_info;
80 my $is_image_insert = 0;
82 for my $col (keys %$to_insert) {
83 if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
89 local $self->{disable_sth_caching} = 1 if $is_image_insert
90 && $self->disable_sth_caching_for_image_insert_or_update;
92 return $self->next::method(@_);
97 my ($source, $fields) = @_;
99 my $columns_info = $source->columns_info;
101 my $is_image_insert = 0;
103 for my $col (keys %$fields) {
104 if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
105 $is_image_insert = 1;
110 local $self->{disable_sth_caching} = 1 if $is_image_insert
111 && $self->disable_sth_caching_for_image_insert_or_update;
113 return $self->next::method(@_);
116 sub datetime_parser_type {
117 'DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format'
120 package # hide from PAUSE
121 DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format;
123 my $datetime_format = '%Y-%m-%d %H:%M:%S'; # %F %T, no fractional part
128 require DateTime::Format::Strptime;
129 $datetime_parser ||= DateTime::Format::Strptime->new(
130 pattern => $datetime_format,
133 return $datetime_parser->parse_datetime(shift);
136 sub format_datetime {
138 require DateTime::Format::Strptime;
139 $datetime_parser ||= DateTime::Format::Strptime->new(
140 pattern => $datetime_format,
143 return $datetime_parser->format_datetime(shift);
146 =head1 FURTHER QUESTIONS?
148 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
150 =head1 COPYRIGHT AND LICENSE
152 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
153 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
154 redistribute it and/or modify it under the same terms as the
155 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.