The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::Model::DBI - Model to use DBI for Egg.

SYNOPSIS

  my $dbh= $e->model('dbi::main');
  
  # Or, if Egg::Model::DBI is default.
  my $dbh= $e->model;
  
  my $sth= $dbh->prepare( ........ );
  
  $dbh->do('......', undef, ....);
  
  $dbh->disconnect;

DESCRIPTION

It is a model component to use DBI.

If Ima::DBI can be used, Ima::DBI is used. As a result, Apache::DBI is not needed for the perpetuity connection environment.

Two or more connection destination can be treated at the same time.

CONFIGURATION

To use it, 'DBI' is added to the MODEL setting of the configuration of the project.

  % vi /path/to/MyApp/lib/MyApp/config.pm
  ..............
  .....
  MODEL=> [
   [ DBI => {
       dns      => 'dbi: ......... ',
       user     => '...',
       password => '...',
       options  => { ....... },
       },
     ],
   ],

Egg::Helper::Model::DBI when there is two or more connection destination The component module that is used and this model uses is made under the control of the project.

  # Generation of component module.
  % cd /path/to/MyApp/bin
  % ./myapp_helper M::Model [CONNECTION_NAME] -d ... -u ... -p ...

The parameter passed to DBI in the generated module is set.

  % vi /path/to/MyApp/lib/MyApp/Modle/DBI/[CONNECTION_NAME].pm
  ...........
  .....
  __PACKAGE__->config(
    default  => 0,
    dsn      => 'dbi: ......',
    user     => '......',
    password => '......',
    options  => {
      AutoCommit => 1,
      RaiseError => 1,
      PrintError => 0,
      },
    );

And, 'DBI' is added to the configuration.

  % vi /path/to/MyApp/lib/MyApp/config.pm
  .........
  ...
  MODEL=> ['DBI'],

When you set default

The data base handler at the connection destination returns only by calling $e->model if the connection destination always becomes default, this model defaults, and it operates when the connection destination is only one.

  my $dbh= $e->model;

The data base handler at the connection to which 'default' is effective in the component module destination returns by default when two or more connection destination has been treated.

If 'default' of all components is invalid, it defaults to the component sorted most first and it treats.

dsn

DSN passed to DBI module.

user

Data base user who passes it to DBI module.

password

Data base password passed to DBI module.

options

Option to pass to DBI module.

An undefined option item is buried by the default of this module. Especially, default makes the transaction of PostgreSQL and Oracle effective. It is options and AutoCommit? to invalidate this. It is necessary to describe clearly.

 options => { AutoCommit => 1 },

The following settings are done in default.

When Ima::DBI is effective.

  FetchHashKeyName? = 1
  And, it defaults about Ima::DBI.

When Ima::DBI is invalid.

  RaiseError         = 1
  PrintError         = 0
  Taint              = 1
  ChopBlanks         = 1
  ShowErrorStatement = 1
  FetchHashKeyName   = 1

HANDLER METHODS

This module only does manager operation.

The document that relates to the data base handler is Egg::Model::DBI::Base. Egg::Model::DBI::dbh Please drink and refer to Cata.

handlers

The list of the data base handler that has been called is returned by the HASH reference. Please note that the call order is not secured.

  if (my $handlers= $dbi->handlers) {
      while (my($label, $obj)= each %$handlers) {
         ........
         ....
      }
  }

new

Constructor.

When $e->model('dbi') and the label are described clearly and called, the object is restored from this constructor.

 my $dbi= $e->model('dbi');

disconnect_all

The acquired data base handler is done in the handlers method and all disconnect is done.

SEE ALSO

Egg::Release, Egg::Model, Egg::Model::DBI::Base, Egg::Model::DBI::dbh, Egg::Helper::Model::DBI, DBI, Ima::DBI, UNIVERSAL::require,

AUTHOR

Masatoshi Mizuno, <lushe@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.