eol adjustments
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ODBC / ACCESS.pm
CommitLineData
65c2b042 1package DBIx::Class::Storage::DBI::ODBC::ACCESS;
2use strict;
3use warnings;
4
5use DBI;
6use base qw/DBIx::Class::Storage::DBI/;
7
8my $ERR_MSG_START = __PACKAGE__ . ' failed: ';
9
10sub insert {
11 my $self = shift;
12 my ( $source, $to_insert ) = @_;
13
14 my $bind_attributes = $self->source_bind_attributes( $source );
15 my ( undef, $sth ) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert );
16
17 #store the identity here since @@IDENTITY is connection global and this prevents
18 #possibility that another insert to a different table overwrites it for this resultsource
19 my $identity = 'SELECT @@IDENTITY';
20 my $max_sth = $self->{ _dbh }->prepare( $identity )
21 or $self->throw_exception( $ERR_MSG_START . $self->{ _dbh }->errstr() );
22 $max_sth->execute() or $self->throw_exception( $ERR_MSG_START . $max_sth->errstr );
23
24 my $row = $max_sth->fetchrow_arrayref()
25 or $self->throw_exception( $ERR_MSG_START . "$identity did not return any result." );
26
27 $self->{ last_pk }->{ $source->name() } = $row;
28
29 return $to_insert;
30}
31
32sub last_insert_id {
33 my $self = shift;
34 my ( $result_source ) = @_;
35
36 return @{ $self->{ last_pk }->{ $result_source->name() } };
37}
38
39sub bind_attribute_by_data_type {
40 my $self = shift;
41
42 my ( $data_type ) = @_;
43
44 return { TYPE => $data_type } if $data_type == DBI::SQL_LONGVARCHAR;
45
46 return;
47}
48
49sub sqlt_type { 'ACCESS' }
50
511;
52
53=head1 NAME
54
55DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC
56
57=head1 WARNING
58
59I am not a DBI, DBIx::Class or MS Access guru. Use this module with that in
60mind.
61
62This module is currently considered alpha software and can change without notice.
63
64=head1 DESCRIPTION
65
66This class implements support specific to Microsoft Access over ODBC.
67
68It is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it
69detects a MS Access back-end.
70
71=head1 SUPPORTED VERSIONS
72
73This module have currently only been tested on MS Access 2003 using the Jet 4.0 engine.
74
75As far as my knowledge it should work on MS Access 2000 or later, but that have not been tested.
76Information about support for different version of MS Access is welcome.
77
78=head1 IMPLEMENTATION NOTES
79
80MS Access supports the @@IDENTITY function for retriving the id of the latest inserted row.
81@@IDENTITY is global to the connection, so to support the possibility of getting the last inserted
82id for different tables, the insert() function stores the inserted id on a per table basis.
83last_insert_id() then just returns the stored value.
84
85=head1 KNOWN ACCESS PROBLEMS
86
87=over
88
89=item Invalid precision value
90
91This error message is received when trying to store more than 255 characters in a MEMO field.
92The problem is (to my knowledge) an error in the MS Access ODBC driver. The problem is fixed
93by setting the C<data_type> of the column to C<SQL_LONGVARCHAR> in C<add_columns>.
94C<SQL_LONGVARCHAR> is a constant in the C<DBI> module.
95
96=back
97
98=head1 IMPLEMENTED FUNCTIONS
99
100=head2 bind_attribute_by_data_type
101
102This function currently supports the SQL_LONGVARCHAR column type.
103
104=head2 insert
105
106=head2 last_insert_id
107
108=head2 sqlt_type
109
110=head1 BUGS
111
112Most likely. Bug reports are welcome.
113
114=head1 AUTHORS
115
116Øystein Torget C<< <oystein.torget@dnv.com> >>
117
118=head1 COPYRIGHT
119
120You may distribute this code under the same terms as Perl itself.
121
122Det Norske Veritas AS (DNV)
123
124http://www.dnv.com
125
126=cut
127