1 package DBIx::Class::Storage::DBI::ODBC::ACCESS;
\r
5 use Data::Dump qw( dump );
\r
8 use base qw/DBIx::Class::Storage::DBI/;
\r
10 my $ERR_MSG_START = __PACKAGE__ . ' failed: ';
\r
14 my ( $source, $to_insert ) = @_;
\r
16 my $bind_attributes = $self->source_bind_attributes( $source );
\r
17 my ( undef, $sth ) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert );
\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
26 my $row = $max_sth->fetchrow_arrayref()
\r
27 or $self->throw_exception( $ERR_MSG_START . "$identity did not return any result." );
\r
29 $self->{ last_pk }->{ $source->name() } = $row;
\r
34 sub last_insert_id {
\r
36 my ( $result_source ) = @_;
\r
38 return @{ $self->{ last_pk }->{ $result_source->name() } };
\r
41 sub bind_attribute_by_data_type {
\r
44 my ( $data_type ) = @_;
\r
46 return { TYPE => $data_type } if $data_type == DBI::SQL_LONGVARCHAR;
\r
51 sub sqlt_type { 'ACCESS' }
\r
57 DBIx::Class::Storage::ODBC::ACCESS - Support specific to MS Access over ODBC
\r
61 I am not a DBI, DBIx::Class or MS Access guru. Use this module with that in
\r
64 This module is currently considered alpha software and can change without notice.
\r
68 This class implements support specific to Microsoft Access over ODBC.
\r
70 It is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it
\r
71 detects a MS Access back-end.
\r
73 =head1 SUPPORTED VERSIONS
\r
75 This module have currently only been tested on MS Access 2003 using the Jet 4.0 engine.
\r
77 As far as my knowledge it should work on MS Access 2000 or later, but that have not been tested.
\r
78 Information about support for different version of MS Access is welcome.
\r
80 =head1 IMPLEMENTATION NOTES
\r
82 MS 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
84 id for different tables, the insert() function stores the inserted id on a per table basis.
\r
85 last_insert_id() then just returns the stored value.
\r
87 =head1 KNOWN ACCESS PROBLEMS
\r
91 =item Invalid precision value
\r
93 This error message is received when trying to store more than 255 characters in a MEMO field.
\r
94 The problem is (to my knowledge) an error in the MS Access ODBC driver. The problem is fixed
\r
95 by setting the C<data_type> of the column to C<SQL_LONGVARCHAR> in C<add_columns>.
\r
96 C<SQL_LONGVARCHAR> is a constant in the C<DBI> module.
\r
100 =head1 IMPLEMENTED FUNCTIONS
\r
102 =head2 bind_attribute_by_data_type
\r
104 This function currently supports the SQL_LONGVARCHAR column type.
\r
108 =head2 last_insert_id
\r
114 Most likely. Bug reports are welcome.
\r
118 Øystein Torget C<< <oystein.torget@dnv.com> >>
\r
122 You may distribute this code under the same terms as Perl itself.
\r
124 Det Norske Veritas AS (DNV)
\r