Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ACCESS.pm
CommitLineData
726c8f65 1package DBIx::Class::Storage::DBI::ACCESS;
2
3use strict;
4use warnings;
5use base 'DBIx::Class::Storage::DBI::UniqueIdentifier';
6use mro 'c3';
7
696ba760 8use DBI ();
726c8f65 9
10__PACKAGE__->sql_limit_dialect ('Top');
11__PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::ACCESS');
12__PACKAGE__->sql_quote_char ([qw/[ ]/]);
13
14sub sqlt_type { 'ACCESS' }
15
16__PACKAGE__->new_guid(undef);
17
18=head1 NAME
19
20DBIx::Class::Storage::DBI::ACCESS - Support specific to MS Access
21
22=head1 DESCRIPTION
23
24This is the base class for Microsoft Access support.
25
26This driver supports L<last_insert_id|DBIx::Class::Storage::DBI/last_insert_id>,
27empty inserts for tables with C<AUTOINCREMENT> columns, nested transactions via
28L<auto_savepoint|DBIx::Class::Storage::DBI/auto_savepoint>, C<GUID> columns via
29L<DBIx::Class::Storage::DBI::UniqueIdentifier>.
30
31=head1 SUPPORTED VERSIONS
32
33This module has currently only been tested on MS Access 2010.
34
35Information about how well it works on different version of MS Access is welcome
36(write the mailing list, or submit a ticket to RT if you find bugs.)
37
38=head1 USING GUID COLUMNS
39
40If you have C<GUID> PKs or other C<GUID> columns with
41L<auto_nextval|DBIx::Class::ResultSource/auto_nextval> you will need to set a
42L<new_guid|DBIx::Class::Storage::DBI::UniqueIdentifier/new_guid> callback, like
43so:
44
45 $schema->storage->new_guid(sub { Data::GUID->new->as_string });
46
47Under L<Catalyst> you can use code similar to this in your
48L<Catalyst::Model::DBIC::Schema> C<Model.pm>:
49
50 after BUILD => sub {
51 my $self = shift;
52 $self->storage->new_guid(sub { Data::GUID->new->as_string });
53 };
54
55=cut
56
57sub _dbh_last_insert_id { $_[1]->selectrow_array('select @@identity') }
58
59# support empty insert
60sub insert {
61 my $self = shift;
62 my ($source, $to_insert) = @_;
63
64 my $columns_info = $source->columns_info;
65
66 if (keys %$to_insert == 0) {
87b12551 67 my ($autoinc_col) = grep {
726c8f65 68 $columns_info->{$_}{is_auto_increment}
69 } keys %$columns_info;
70
e705f529 71 $self->throw_exception(
72 'empty insert only supported for tables with an autoincrement column'
73 ) unless $autoinc_col;
726c8f65 74
75 my $table = $source->from;
76 $table = $$table if ref $table;
77
78 $to_insert->{$autoinc_col} = \"dmax('${autoinc_col}', '${table}')+1";
79 }
80
81 return $self->next::method(@_);
82}
83
84sub bind_attribute_by_data_type {
85 my $self = shift;
86 my ($data_type) = @_;
87
88 my $attributes = $self->next::method(@_) || {};
89
90 if ($self->_is_text_lob_type($data_type)) {
91 $attributes->{TYPE} = DBI::SQL_LONGVARCHAR;
92 }
93 elsif ($self->_is_binary_lob_type($data_type)) {
94 $attributes->{TYPE} = DBI::SQL_LONGVARBINARY;
95 }
96
97 return $attributes;
98}
99
100# savepoints are not supported, but nested transactions are.
101# Unfortunately DBI does not support nested transactions.
102# WARNING: this code uses the undocumented 'BegunWork' DBI attribute.
103
90d7422f 104sub _exec_svp_begin {
726c8f65 105 my ($self, $name) = @_;
106
726c8f65 107 local $self->_dbh->{AutoCommit} = 1;
108 local $self->_dbh->{BegunWork} = 0;
90d7422f 109 $self->_exec_txn_begin;
726c8f65 110}
111
112# A new nested transaction on the same level releases the previous one.
90d7422f 113sub _exec_svp_release { 1 }
726c8f65 114
90d7422f 115sub _exec_svp_rollback {
726c8f65 116 my ($self, $name) = @_;
117
726c8f65 118 local $self->_dbh->{AutoCommit} = 0;
119 local $self->_dbh->{BegunWork} = 1;
90d7422f 120 $self->_exec_txn_rollback;
726c8f65 121}
122
a2bd3796 123=head1 FURTHER QUESTIONS?
726c8f65 124
a2bd3796 125Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
726c8f65 126
a2bd3796 127=head1 COPYRIGHT AND LICENSE
726c8f65 128
a2bd3796 129This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
130by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
131redistribute it and/or modify it under the same terms as the
132L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
726c8f65 133
134=cut
a2bd3796 135
1361;
137
726c8f65 138# vim:sts=2 sw=2: