Initial import of storage class for MS Acccess
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ODBC / ACCESS.pm
1 package DBIx::Class::Storage::DBI::ODBC::ACCESS;\r
2 use strict;\r
3 use warnings;\r
4 \r
5 use Data::Dump qw( dump );\r
6 \r
7 use base qw/DBIx::Class::Storage::DBI/;\r
8 \r
9 my $ERR_MSG_START = __PACKAGE__ . ' failed: ';\r
10 \r
11 sub 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
33 sub 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
40 sub sqlt_type { 'ACCESS' }\r
41 \r
42 1;\r
43 \r
44 =head1 NAME\r
45 \r
46 DBIx::Class::Storage::ODBC::ACCESS - Support specific to MS Access over ODBC\r
47 \r
48 =head1 WARNING\r
49 \r
50 I am not a DBI, DBIx::Class or MS Access guru. Use this module with that in\r
51 mind.\r
52 \r
53 This module is currently considered alpha software and can change without notice.\r
54 \r
55 =head1 DESCRIPTION\r
56 \r
57 This class implements support specific to Microsoft Access over ODBC. It currently only\r
58 implements functions necessary for working with auto-incremented primary keys.\r
59 \r
60 It is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it\r
61 detects a MS Access back-end.\r
62 \r
63 =head1 SUPPORTED VERSIONS\r
64 \r
65 This module have currently only been tested on MS Access 2003 using the Jet 4.0 engine.\r
66 \r
67 As far as my knowledge it should work on MS Access 2000 or later, but that have not been tested.\r
68 Information about support for different version of MS Access is welcome.\r
69 \r
70 =head1 IMPLEMENTATION NOTES\r
71 \r
72 MS 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
74 id for different tables, the insert() function stores the inserted id on a per table basis.\r
75 last_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
87 Most 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
95 You may distribute this code under the same terms as Perl itself.\r
96 \r
97 Det Norske Veritas AS (DNV)\r
98 \r
99 http://www.dnv.com\r
100 \r
101 \r
102 \r
103 =cut\r
104 \r