DBIx/Class/Storage/DBI/ODBC/ACCESS.pm

filter: Statementstmt 32.6% 17 / 52 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 4 / 10 Podpod 100% 3 / 3 totaltotal 24.0% 24 / 100 CC 13 SCAR 28.1
CC
13
Cov
22%
insert
30.0
update
30.0
_run_connection_actions
12.0
CRAP 16.6
« DBIx/Class/CDBICompat/DestroyWarning.pm ↑ Summary DBIx/Class/InflateColumn/DateTime.pm »
1 package DBIx::Class::Storage::DBI::ODBC::ACCESS;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
6 DBIx::Class::Storage::DBI::ODBC
7 DBIx::Class::Storage::DBI::ACCESS
8 3 /;
9 3 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 __PACKAGE__->mk_group_accessors(inherited =>
12 'disable_sth_caching_for_image_insert_or_update'
13 );
14  
15 3 __PACKAGE__->disable_sth_caching_for_image_insert_or_update(1);
16  
17 =head1 NAME
18  
19 DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC
20  
21 =head1 DESCRIPTION
22  
23 This class implements support specific to Microsoft Access over ODBC.
24  
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
27 information.
28  
29 It is loaded automatically by L<DBIx::Class::Storage::DBI::ODBC> when it
30 detects a MS Access back-end.
31  
32 This driver implements workarounds for C<IMAGE> and C<MEMO> columns, and
33 L<DBIx::Class::InflateColumn::DateTime> support for C<DATETIME> columns.
34  
35 =head1 EXAMPLE DSN
36  
37 dbi:ODBC:driver={Microsoft Access Driver (*.mdb, *.accdb)};dbq=C:\Users\rkitover\Documents\access_sample.accdb
38  
39 =head1 TEXT/IMAGE/MEMO COLUMNS
40  
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.
44  
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
47 Access ODBC driver.
48  
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.
54  
55 =cut
56  
57 # set LongReadLen = LongReadLen * 2 + 1 (see docs on MEMO)
58 0 ▶sub _run_connection_actions {
Subroutine _run_connection_actions: not called CC=3 SCAR=24.8
59 0 my $self = shift;
60  
61 0 my $long_read_len = $self->_dbh->{LongReadLen};
62  
63 # 80 is another default (just like 0) on some drivers
64 0 ▶ if ($long_read_len != 0 && $long_read_len != 80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long_read_len != 0 and $long_read_len != 80) 0 0 0
Condition0%0/3
$long_read_len != 0 and $long_read_len != 80
!ll&&!rl&&r
000
MC/DC0%0/2
$long_read_len != 0 and $long_read_len != 80
$long_read_len != 0 $long_read_len != 80
Truth table0%0/3
A and B
A= $long_read_len != 0B= $long_read_len != 80
ABresult
0X0
100
111
65 0 $self->_dbh->{LongReadLen} = $long_read_len * 2 + 1;
66 }
67  
68 # batch operations do not work
69 0 $self->_disable_odbc_array_ops;
70  
71 0 return $self->next::method(@_);
72 }
73  
74 0 ▶sub insert {
Subroutine insert: not called CC=5 SCAR=34.0
Pod documented
75 0 my $self = shift;
76 0 my ($source, $to_insert) = @_;
77  
78 0 my $columns_info = $source->columns_info;
79  
80 0 my $is_image_insert = 0;
81  
82 0 for my $col (keys %$to_insert) {
83 0 ▶ if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_binary_lob_type($columns_info->{$col}{"data_type"})) 0 0 0
84 0 $is_image_insert = 1;
85 0 last;
86 }
87 }
88  
89 0 ▶ local $self->{disable_sth_caching} = 1 if $is_image_insert
Branch: 1 branch
BranchTrueFalseTotal
if $is_image_insert and $self->disable_sth_caching_for_image_insert_or_update 0 0 0
Condition0%0/3
$is_image_insert and $self->disable_sth_caching_for_image_insert_or_update
!ll&&!rl&&r
000
MC/DC0%0/2
$is_image_insert and $self->disable_sth_caching_for_image_insert_or_update
$is_image_insert $self->disable_sth_caching_for_image_insert_or_update
Truth table0%0/3
A and B
A= $is_image_insertB= $self->disable_sth_caching_for_image_insert_or_update
ABresult
0X0
100
111
90 && $self->disable_sth_caching_for_image_insert_or_update;
91  
92 0 return $self->next::method(@_);
93 }
94  
95 0 ▶sub update {
Subroutine update: not called CC=5 SCAR=34.0
Pod documented
96 0 my $self = shift;
97 0 my ($source, $fields) = @_;
98  
99 0 my $columns_info = $source->columns_info;
100  
101 0 my $is_image_insert = 0;
102  
103 0 for my $col (keys %$fields) {
104 0 ▶ if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_binary_lob_type($columns_info->{$col}{"data_type"})) 0 0 0
105 0 $is_image_insert = 1;
106 0 last;
107 }
108 }
109  
110 0 ▶ local $self->{disable_sth_caching} = 1 if $is_image_insert
Branch: 1 branch
BranchTrueFalseTotal
if $is_image_insert and $self->disable_sth_caching_for_image_insert_or_update 0 0 0
Condition0%0/3
$is_image_insert and $self->disable_sth_caching_for_image_insert_or_update
!ll&&!rl&&r
000
MC/DC0%0/2
$is_image_insert and $self->disable_sth_caching_for_image_insert_or_update
$is_image_insert $self->disable_sth_caching_for_image_insert_or_update
Truth table0%0/3
A and B
A= $is_image_insertB= $self->disable_sth_caching_for_image_insert_or_update
ABresult
0X0
100
111
111 && $self->disable_sth_caching_for_image_insert_or_update;
112  
113 0 return $self->next::method(@_);
114 }
115  
116 0 ▶sub datetime_parser_type {
Subroutine datetime_parser_type: not called CC=1 SCAR=6.9
Pod documented
117 0 'DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format'
118 }
119  
120 package # hide from PAUSE
121 DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format;
122  
123 3 my $datetime_format = '%Y-%m-%d %H:%M:%S'; # %F %T, no fractional part
124 3 my $datetime_parser;
125  
126 0 ▶sub parse_datetime {
Subroutine parse_datetime: not called CC=2 SCAR=17.9
127 0 shift;
128 0 require DateTime::Format::Strptime;
129 0 ▶ $datetime_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
$datetime_parser "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $datetime_parserB= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
ABresult
1X1
011
000
130 pattern => $datetime_format,
131 on_error => 'croak',
132 );
133 0 return $datetime_parser->parse_datetime(shift);
134 }
135  
136 0 ▶sub format_datetime {
Subroutine format_datetime: not called CC=2 SCAR=17.9
137 0 shift;
138 0 require DateTime::Format::Strptime;
139 0 ▶ $datetime_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
$datetime_parser "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $datetime_parserB= "DateTime::Format::Strptime"->new("pattern", $datetime_format, "on_error", "croak")
ABresult
1X1
011
000
140 pattern => $datetime_format,
141 on_error => 'croak',
142 );
143 0 return $datetime_parser->format_datetime(shift);
144 }
145  
146 =head1 FURTHER QUESTIONS?
147  
148 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
149  
150 =head1 COPYRIGHT AND LICENSE
151  
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>.
156  
157 =cut
158  
159 3 1;
160  
161 # vim:sts=2 sw=2:
« DBIx/Class/CDBICompat/DestroyWarning.pm ↑ Summary DBIx/Class/InflateColumn/DateTime.pm »