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 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 return $self->next::method(@_);
73 my ($source, $to_insert) = @_;
75 my $columns_info = $source->columns_info;
77 my $is_image_insert = 0;
79 for my $col (keys %$to_insert) {
80 if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
86 local $self->{disable_sth_caching} = 1 if $is_image_insert
87 && $self->disable_sth_caching_for_image_insert_or_update;
89 return $self->next::method(@_);
94 my ($source, $fields) = @_;
96 my $columns_info = $source->columns_info;
98 my $is_image_insert = 0;
100 for my $col (keys %$fields) {
101 if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
102 $is_image_insert = 1;
107 local $self->{disable_sth_caching} = 1 if $is_image_insert
108 && $self->disable_sth_caching_for_image_insert_or_update;
110 return $self->next::method(@_);
113 sub datetime_parser_type {
114 'DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format'
117 package # hide from PAUSE
118 DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format;
120 my $datetime_format = '%Y-%m-%d %H:%M:%S'; # %F %T, no fractional part
125 require DateTime::Format::Strptime;
126 $datetime_parser ||= DateTime::Format::Strptime->new(
127 pattern => $datetime_format,
130 return $datetime_parser->parse_datetime(shift);
133 sub format_datetime {
135 require DateTime::Format::Strptime;
136 $datetime_parser ||= DateTime::Format::Strptime->new(
137 pattern => $datetime_format,
140 return $datetime_parser->format_datetime(shift);
147 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
151 You may distribute this code under the same terms as Perl itself.