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