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