Archive Ensembl HomeArchive Ensembl Home
Bio::EnsEMBL::DBSQL::DBConnection Class Reference
Inheritance diagram for Bio::EnsEMBL::DBSQL::DBConnection:

List of all members.


Class Summary

Synopsis

  $dbc = Bio::EnsEMBL::DBSQL::DBConnection-\>new(
    -user   =\> 'anonymous',
    -dbname =\> 'homo_sapiens_core_20_34c',
    -host   =\> 'ensembldb.ensembl.org',
    -driver =\> 'mysql',
  );

  # SQL statements should be created/executed through this modules
  # prepare() and do() methods.

  $sth = $dbc-\>prepare("SELECT something FROM yourtable");

  $sth-\>execute();

  # do something with rows returned ...

  $sth-\>finish();

Description

This class is a wrapper around DBIs datbase handle.  It provides some
additional functionality such as the ability to automatically disconnect
when inactive and reconnect when needed.
Generally this class will be used through one of the object adaptors or
the Bio::EnsEMBL::Registry and will not be instantiated directly.
 

Definition at line 43 of file DBConnection.pm.

Available Methods

protected _rearrange ()
public SQLStatement add_limit_clause ()
public void connect ()
public Undef connected ()
public DBI db_handle ()
public String dbname ()
public disconnect_count ()
public disconnect_if_idle ()
public Boolean disconnect_when_inactive ()
public Result do ()
public String driver ()
public Boolean equals ()
public String from_date_to_seconds ()
public String from_seconds_to_date ()
public group ()
public String host ()
public String locator ()
public
Bio::EnsEMBL::DBSQL::DBConnection 
new ()
public String password ()
public String port ()
public DBI prepare ()
public prevent_disconnect ()
public query_count ()
public ArrayRef quote_identifier ()
public void reconnect ()
public Boolean reconnect_when_lost ()
public species ()
public
Bio::EnsEMBL::Utils::SqlHelper 
sql_helper ()
public stack_trace ()
public stack_trace_dump ()
public throw ()
public timeout ()
public String username ()
public verbose ()
public warn ()
public Any work_with_db_handle ()

Method Documentation

protected Bio::EnsEMBL::Root::_rearrange ( ) [inherited]
Deprecated:
 
Code:
click to view
public SQLStatement Bio::EnsEMBL::DBSQL::DBConnection::add_limit_clause ( )
  Arg [1]    : string $sql
  Arg [2]    : int $max_number
  Example    : my $new_sql = $dbc->add_limit_clause($sql,$max_number);
  Description: Giving an SQL statement, it adds a limit clause, dependent on the database 
               (in MySQL, should add a LIMIT at the end, MSSQL uses a TOP clause)									 
  Returntype : String containing the new valid SQL statement        
  Exceptions : none
  Caller     : general
  Status     : at risk
 
Code:
click to view
public void Bio::EnsEMBL::DBSQL::DBConnection::connect ( )
  Example    : $dbcon->connect()
  Description: Connects to the database using the connection attribute 
               information.
  Returntype : none
  Exceptions : none
  Caller     : new, db_handle
  Status     : Stable
 
Code:
click to view
public Undef Bio::EnsEMBL::DBSQL::DBConnection::connected ( )
  Example    : $dbcon->connected()
  Description: Boolean which tells if DBConnection is connected or not.
               State is set internally, and external processes should not alter state.
  Returntype : undef or 1
  Exceptions : none
  Caller     : db_handle, connect, disconnect_if_idle, user processes
  Status     : Stable
 
Code:
click to view
public DBI Bio::EnsEMBL::DBSQL::DBConnection::db_handle ( )
  Arg [1]    : DBI Database Handle $value
  Example    : $dbh = $db_connection->db_handle() 
  Description: Getter / Setter for the Database handle used by this
               database connection.
  Returntype : DBI Database Handle
  Exceptions : none
  Caller     : new, DESTROY
  Status     : Stable
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::dbname ( )
  Arg [1]    : (optional) string $arg
               The new value of the database name used by this connection. 
  Example    : $dbname = $db_connection->dbname()
  Description: Getter/Setter for the name of the database used by this 
               connection.  There is currently no point in setting this value
               after the connection has already been established by the 
               constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::disconnect_count ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::disconnect_if_idle ( )
  Arg [1]    : none
  Example    : $dbc->disconnect_if_idle();
  Description: Disconnects from the database if there are no currently active
               statement handles. 
               It is called automatically by the DESTROY method of the
               Bio::EnsEMBL::DBSQL::SQL::StatementHandle if the
               disconect_when_inactive flag is set.
               Users may call it whenever they want to disconnect. Connection will
               reestablish on next access to db_handle()
  Returntype : 0,1
               1=problem trying to disconnect while a statement handle was still active
  Exceptions : none
  Caller     : Bio::EnsEMBL::DBSQL::SQL::StatementHandle::DESTROY
               Bio::EnsEMBL::DBSQL::DBConnection::do
  Status     : Stable
 
Code:
click to view
public Boolean Bio::EnsEMBL::DBSQL::DBConnection::disconnect_when_inactive ( )
  Arg [1]    : (optional) boolean $newval
  Example    : $db->disconnect_when_inactive(1);
  Description: Getter/Setter for the disconnect_when_inactive flag.  If set
               to true this DBConnection will continually disconnect itself
               when there are no active statement handles and reconnect as
               necessary.  Useful for farm environments when there can be
               many (often inactive) open connections to a database at once.
  Returntype : boolean
  Exceptions : none
  Caller     : Pipeline
  Status     : Stable
 
Code:
click to view
public Result Bio::EnsEMBL::DBSQL::DBConnection::do ( )
  Arg [1]    : string $string
               the SQL statement to prepare
  Example    : $sth = $db_connection->do("SELECT column FROM table");
  Description: Executes a SQL statement using the internal DBI database handle.
  Returntype : Result of DBI dbh do() method
  Exceptions : thrown if the SQL statement is empty, or if the internal
               database handle is not present.
  Caller     : Adaptor modules
  Status     : Stable
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::driver ( )
  Arg [1]    : (optional) string $arg
               the name of the driver to use to connect to the database
  Example    : $driver = $db_connection->driver()
  Description: Getter / Setter for the driver this connection uses.
               Right now there is no point to setting this value after a
               connection has already been established in the constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public Boolean Bio::EnsEMBL::DBSQL::DBConnection::equals ( )
  Example    : warn 'Same!' if($dbc->equals($other_dbc));
  Description: Equality checker for DBConnection objects
  Returntype : boolean
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::from_date_to_seconds ( )
  Arg [1]    : date $date
  Example    : my $string = $dbc->from_date_to_seconds($date);
  Description: Giving a string representing a column of type date 
                applies the database function to convert to the number of seconds from 01-01-1970
  Returntype : string
  Exceptions : none
  Caller     : general
  Status     : at risk
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::from_seconds_to_date ( )
  Arg [1]    : int $seconds
  Example    : my $string = $dbc->from_seconds_to_date($seconds);
  Description: Giving an int representing number of seconds
                applies the database function to convert to a date 
  Returntype : string
  Exceptions : none
  Caller     : general
  Status     : at risk
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::group ( )
   group is no longer available in DBConnection and should be accessed if needed
   from an adaptor.
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::host ( )
  Arg [1]    : (optional) string $arg
               The new value of the host used by this connection. 
  Example    : $host = $db_connection->host()
  Description: Getter/Setter for the domain name of the database host use by 
               this connection.  There is currently no point in setting 
               this value after the connection has already been established 
               by the constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::locator ( )
  Arg [1]    : none
  Example    : $locator = $dbc->locator;
  Description: Constructs a locator string for this database connection
               that can, for example, be used by the DBLoader module
  Returntype : string
  Exceptions : none
  Caller     : general
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection Bio::EnsEMBL::DBSQL::DBConnection::new ( )
  Arg [DBNAME] : (optional) string
                 The name of the database to connect to.
  Arg [HOST] : (optional) string
               The domain name of the database host to connect to.  
               'localhost' by default. 
  Arg [USER] : string
               The name of the database user to connect with 
  Arg [PASS] : (optional) string
               The password to be used to connect to the database
  Arg [PORT] : (optional) int
               The port to use when connecting to the database
               3306 by default if the driver is mysql.
  Arg [DRIVER] : (optional) string
                 The type of database driver to use to connect to the DB
                 mysql by default.
  Arg [DBCONN] : (optional)
                 Open another handle to the same database as another connection
                 If this argument is specified, no other arguments should be
                 specified.
  Arg [DISCONNECT_WHEN_INACTIVE]: (optional) boolean
                 If set to true, the database connection will be disconnected
                 everytime there are no active statement handles. This is
                 useful when running a lot of jobs on a compute farm
                 which would otherwise keep open a lot of connections to the
                 database.  Database connections are automatically reopened
                 when required.Do not use this option together with RECONNECT_WHEN_CONNECTION_LOST.
  Arg [WAIT_TIMEOUT]: (optional) integer
                 Time in seconds for the wait timeout to happen. Time after which
                 the connection is deleted if not used. By default this is 28800 (8 hours)
                 on most systems. 
                 So set this to greater than this if your connection are getting deleted.
                 Only set this if you are having problems and know what you are doing.
  Arg [RECONNECT_WHEN_CONNECTION_LOST]: (optional) boolean
                 In case you're reusing the same database connection, i.e. DISCONNECT_WHEN_INACTIVE is 
                 set to false and running a job which takes a long time to process (over 8hrs), 
                 which means that the db connection may be lost, set this option to true. 
                 On each prepare or do statement the db handle will be pinged and the database 
                 connection will be reconnected if it's lost.
  Example    : $dbc = Bio::EnsEMBL::DBSQL::DBConnection->new
                  (-user   => 'anonymous',
                   -dbname => 'homo_sapiens_core_20_34c',
                   -host   => 'ensembldb.ensembl.org',
                   -driver => 'mysql');
  Description: Constructor for a Database Connection. Any adaptors that require
               database connectivity should inherit from this class.
  Returntype : Bio::EnsEMBL::DBSQL::DBConnection
  Exceptions : thrown if USER or DBNAME are not specified, or if the database
               cannot be connected to.
  Caller     : Bio::EnsEMBL::Utils::ConfigRegistry ( for newer code using the registry)
               Bio::EnsEMBL::DBSQL::DBAdaptor        ( for old style code)
  Status     : Stable
 
Code:
click to view

Reimplemented from Bio::EnsEMBL::Root.

public String Bio::EnsEMBL::DBSQL::DBConnection::password ( )
  Arg [1]    : (optional) string $arg
               The new value of the password used by this connection.
  Example    : $host = $db_connection->password()
  Description: Getter/Setter for the password of to use for this
               connection.  There is currently no point in setting
               this value after the connection has already been
               established by the constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::port ( )
  Arg [1]    : (optional) int $arg
               the TCP or UDP port to use to connect to the database
  Example    : $port = $db_connection->port();
  Description: Getter / Setter for the port this connection uses to communicate
               to the database daemon.  There currently is no point in 
               setting this value after the connection has already been 
               established by the constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public DBI Bio::EnsEMBL::DBSQL::DBConnection::prepare ( )
  Arg [1]    : string $string
               the SQL statement to prepare
  Example    : $sth = $db_connection->prepare("SELECT column FROM table");
  Description: Prepares a SQL statement using the internal DBI database handle
               and returns the DBI statement handle.
  Returntype : DBI statement handle
  Exceptions : thrown if the SQL statement is empty, or if the internal
               database handle is not present
  Caller     : Adaptor modules
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::prevent_disconnect ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::query_count ( )

Undocumented method

Code:
click to view
public ArrayRef Bio::EnsEMBL::DBSQL::DBConnection::quote_identifier ( )
  Arg [n]    : scalar/ArrayRef
  Example    : $q = $dbc->quote_identifier('table', 'other');
               $q = $dbc->quote_identifier([undef, 'my_db', 'table'], [undef, 'my_db', 'other']);
  Description: Executes the DBI quote_identifier method which will quote
               any given string using the database driver's quote character.
  Returntype : ArrayRef
  Exceptions : None
  Caller     : General
  Status     : Stable
 
Code:
click to view
public void Bio::EnsEMBL::DBSQL::DBConnection::reconnect ( )
  Example    : $dbcon->reconnect()
  Description: Reconnects to the database using the connection attribute 
               information if db_handle no longer pingable.
  Returntype : none
  Exceptions : none
  Caller     : new, db_handle
  Status     : Stable
 
Code:
click to view
public Boolean Bio::EnsEMBL::DBSQL::DBConnection::reconnect_when_lost ( )
  Arg [1]    : (optional) boolean $newval
  Example    : $db->reconnect_when_lost(1);
  Description: Getter/Setter for the reconnect_when_lost flag.  If set
               to true the db handle will be pinged on each prepare or do statement 
               and the connection will be reestablished in case it's lost.
               Useful for long running jobs (over 8hrs), which means that the db 
               connection may be lost.
  Returntype : boolean
  Exceptions : none
  Caller     : Pipeline
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::species ( )
   species is no longer available in DBConnection and should be accessed if needed
   from an adaptor.
 
Code:
click to view
public Bio::EnsEMBL::Utils::SqlHelper Bio::EnsEMBL::DBSQL::DBConnection::sql_helper ( )
  Example    : my $h = $dbc->sql_helper();
  Description: Lazy generated instance of Bio::EnsEMBL::Utils::SqlHelper
               which provides useful wrapper methods for interacting with a
               DBConnection instance.
  Returntype : Bio::EnsEMBL::Utils::SqlHelper
  Exceptions : none
  Caller     : general
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::Root::stack_trace ( ) [inherited]
Deprecated:
 
Code:
click to view
public Bio::EnsEMBL::Root::stack_trace_dump ( ) [inherited]
Deprecated:
 
Code:
click to view
public Bio::EnsEMBL::Root::throw ( ) [inherited]
Deprecated:
 
Code:
click to view
public Bio::EnsEMBL::DBSQL::DBConnection::timeout ( )

Undocumented method

Code:
click to view
public String Bio::EnsEMBL::DBSQL::DBConnection::username ( )
  Arg [1]    : (optional) string $arg
               The new value of the username used by this connection. 
  Example    : $username = $db_connection->username()
  Description: Getter/Setter for the username used by this 
               connection.  There is currently no point in setting this value
               after the connection has already been established by the 
               constructor.
  Returntype : string
  Exceptions : none
  Caller     : new
  Status     : Stable
 
Code:
click to view
public Bio::EnsEMBL::Root::verbose ( ) [inherited]
Deprecated:
 
Code:
click to view
public Bio::EnsEMBL::Root::warn ( ) [inherited]
Deprecated:
 
Code:
click to view
public Any Bio::EnsEMBL::DBSQL::DBConnection::work_with_db_handle ( )
  Arg [1]    : CodeRef $callback
  Example    : my $q_t = $dbc->work_with_db_handle(sub { my ($dbh) = @_; return $dbh->quote_identifier('table'); });
  Description: Gives access to the DBI handle to execute methods not normally
               provided by the DBConnection interface
  Returntype : Any from callback
  Exceptions : If the callback paramater is not a CodeRef; all other 
               errors are re-thrown after cleanup.
  Caller     : Adaptor modules
  Status     : Stable
 
Code:
click to view

The documentation for this class was generated from the following file: