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