Daniel Westermann-Clark <danieltwc@cpan.org>
+Alexander Hartmaier <alex_hartmaier@hotmail.com>
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
Note that L<DBIx::Class::Schema> does not cache connnections for you. If you
use multiple connections, you need to do this manually.
+To execute some sql statements on every connect you can pass them to your schema after the connect:
+
+ $schema->storage->on_connect_do(\@on_connect_sql_statments);
+
The simplest way to get a record is by primary key:
my $schema = My::Schema->connect( ... );
__PACKAGE__->load_components(qw/Exception AccessorGroup/);
__PACKAGE__->mk_group_accessors('simple' =>
- qw/connect_info _dbh _sql_maker debug cursor/);
+ qw/connect_info _dbh _sql_maker debug cursor on_connect_do/);
our $TRANSACTION = 0;
=cut
+=head2 on_connect_do
+
+Executes the sql statements given as a listref on every db connect.
+
+=cut
+
sub dbh {
my ($self) = @_;
my $dbh;
my ($self) = @_;
my @info = @{$self->connect_info || []};
$self->_dbh($self->_connect(@info));
+
+ # if on-connect sql statements are given execute them
+ foreach my $sql_statement (@{$self->on_connect_do || []}) {
+ $self->_dbh->do($sql_statement);
+ }
}
sub _connect {