| DBIx-Class documentation | Contained in the DBIx-Class distribution. |
DBIx::Class::Storage::DBI::ADO::MS_Jet - Support for MS Access over ADO
This driver is a subclass of DBIx::Class::Storage::DBI::ADO and DBIx::Class::Storage::DBI::ACCESS for connecting to MS Access via DBD::ADO.
See the documentation for DBIx::Class::Storage::DBI::ACCESS for information on the MS Access driver for DBIx::Class.
This driver implements workarounds for TEXT/IMAGE/MEMO columns, sets the
cursor_class to
DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor to normalize returned
GUID values and provides DBIx::Class::InflateColumn::DateTime support
for DATETIME columns.
# older Access versions: dbi:ADO:Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb # newer Access versions: dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb;Persist Security Info=False'
The ADO driver does not suffer from the problems the ODBC driver has with these types of columns. You can use them safely.
When you execute a CREATE TABLE statement over this driver with a TEXT
column, it will be converted to MEMO, while in the
ODBC driver it is converted to
VARCHAR(255).
However, the caveat about LongReadLen having to be twice the
max size of your largest MEMO/TEXT column +1 still applies. DBD::ADO
sets LongReadLen to a large value by default, so it should be
safe to just leave it unset. If you do pass a LongReadLen in
your connect_info, it will be
multiplied by two and 1 added, just as for the
ODBC driver.
You may distribute this code under the same terms as Perl itself.
| DBIx-Class documentation | Contained in the DBIx-Class distribution. |
package DBIx::Class::Storage::DBI::ADO::MS_Jet; use strict; use warnings; use base qw/ DBIx::Class::Storage::DBI::ADO DBIx::Class::Storage::DBI::ACCESS /; use mro 'c3'; use DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor (); __PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
# set LongReadLen = LongReadLen * 2 + 1 (see docs on MEMO) sub _run_connection_actions { my $self = shift; my $long_read_len = $self->_dbh->{LongReadLen}; # This is the DBD::ADO default. if ($long_read_len != 2147483647) { $self->_dbh->{LongReadLen} = $long_read_len * 2 + 1; } return $self->next::method(@_); } # AutoCommit does not get reset properly after transactions for some reason # (probably because of my nested transaction hacks in ACCESS.pm) fix it up # here. sub _exec_txn_commit { my $self = shift; $self->next::method(@_); $self->_dbh->{AutoCommit} = $self->_dbh_autocommit if $self->{transaction_depth} == 1; } sub _exec_txn_rollback { my $self = shift; $self->next::method(@_); $self->_dbh->{AutoCommit} = $self->_dbh_autocommit if $self->{transaction_depth} == 1; } # Fix up GUIDs for ->find, for cursors see the cursor_class above. sub select_single { my $self = shift; my ($ident, $select) = @_; my @row = $self->next::method(@_); return @row unless $self->cursor_class->isa('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor'); my $col_info = $self->_resolve_column_info($ident); for my $select_idx (0..$#$select) { my $selected = $select->[$select_idx]; next if ref $selected; my $data_type = $col_info->{$selected}{data_type}; if ($self->_is_guid_type($data_type)) { my $returned = $row[$select_idx]; $row[$select_idx] = substr($returned, 1, 36) if substr($returned, 0, 1) eq '{'; } } return @row; } sub datetime_parser_type { 'DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format' } package # hide from PAUSE DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format; my $datetime_format = '%m/%d/%Y %I:%M:%S %p'; my $datetime_parser; sub parse_datetime { shift; require DateTime::Format::Strptime; $datetime_parser ||= DateTime::Format::Strptime->new( pattern => $datetime_format, on_error => 'croak', ); return $datetime_parser->parse_datetime(shift); } sub format_datetime { shift; require DateTime::Format::Strptime; $datetime_parser ||= DateTime::Format::Strptime->new( pattern => $datetime_format, on_error => 'croak', ); return $datetime_parser->format_datetime(shift); } 1;
# vim:sts=2 sw=2: