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