Strip bogus Data::Dump requires
[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 DBI;\r
6 use base qw/DBIx::Class::Storage::DBI/;\r
7 \r
8 my $ERR_MSG_START = __PACKAGE__ . ' failed: ';\r
9 \r
10 sub 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
32 sub 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
39 sub 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
49 sub sqlt_type { 'ACCESS' }\r
50 \r
51 1;\r
52 \r
53 =head1 NAME\r
54 \r
55 DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC\r
56 \r
57 =head1 WARNING\r
58 \r
59 I am not a DBI, DBIx::Class or MS Access guru. Use this module with that in\r
60 mind.\r
61 \r
62 This module is currently considered alpha software and can change without notice.\r
63 \r
64 =head1 DESCRIPTION\r
65 \r
66 This class implements support specific to Microsoft Access over ODBC.\r
67 \r
68 It is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it\r
69 detects a MS Access back-end.\r
70 \r
71 =head1 SUPPORTED VERSIONS\r
72 \r
73 This module have currently only been tested on MS Access 2003 using the Jet 4.0 engine.\r
74 \r
75 As far as my knowledge it should work on MS Access 2000 or later, but that have not been tested.\r
76 Information about support for different version of MS Access is welcome.\r
77 \r
78 =head1 IMPLEMENTATION NOTES\r
79 \r
80 MS 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
82 id for different tables, the insert() function stores the inserted id on a per table basis.\r
83 last_insert_id() then just returns the stored value.\r
84 \r
85 =head1 KNOWN ACCESS PROBLEMS\r
86 \r
87 =over\r
88 \r
89 =item Invalid precision value\r
90 \r
91 This error message is received when trying to store more than 255 characters in a MEMO field.\r
92 The problem is (to my knowledge) an error in the MS Access ODBC driver. The problem is fixed\r
93 by setting the C<data_type> of the column to C<SQL_LONGVARCHAR> in C<add_columns>. \r
94 C<SQL_LONGVARCHAR> is a constant in the C<DBI> module.\r
95 \r
96 =back\r
97 \r
98 =head1 IMPLEMENTED FUNCTIONS\r
99 \r
100 =head2 bind_attribute_by_data_type\r
101 \r
102 This function currently supports the SQL_LONGVARCHAR column type.\r
103 \r
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
112 Most 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
120 You may distribute this code under the same terms as Perl itself.\r
121 \r
122 Det Norske Veritas AS (DNV)\r
123 \r
124 http://www.dnv.com\r
125 \r
126 =cut\r
127 \r