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