ensembl-hive  2.6
Bio::EnsEMBL::DBSQL::DBConnection Class Reference
+ Inheritance diagram for Bio::EnsEMBL::DBSQL::DBConnection:

Public Member Functions

public Bio::EnsEMBL::DBSQL::DBConnection new ()
 
public void connect ()
 
public Undef connected ()
 
public disconnect_count ()
 
public timeout ()
 
public query_count ()
 
public Boolean equals ()
 
public String driver ()
 
public String port ()
 
public String dbname ()
 
public String username ()
 
public String user ()
 
public String host ()
 
public String hostname ()
 
public String password ()
 
public String pass ()
 
public Boolean disconnect_when_inactive ()
 
public Boolean reconnect_when_lost ()
 
public String locator ()
 
public DBI db_handle ()
 
public DBI prepare ()
 
public DBI prepare_cached ()
 
public void reconnect ()
 
public Result do ()
 
public Any work_with_db_handle ()
 
public void prevent_disconnect ()
 
public ArrayRef quote_identifier ()
 
public Boolean disconnect_if_idle ()
 
public SQLStatement add_limit_clause ()
 
public String from_date_to_seconds ()
 
public String from_seconds_to_date ()
 
public Bio::EnsEMBL::Utils::SqlHelper sql_helper ()
 
public Hash to_hash ()
 
protected _driver_object ()
 

Detailed Description

Synopsis

-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 42 of file DBConnection.pm.

Member Function Documentation

◆ _driver_object()

protected Bio::EnsEMBL::DBSQL::DBConnection::_driver_object ( )
 
Code:
click to view

◆ add_limit_clause()

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

◆ connect()

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

◆ connected()

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

◆ db_handle()

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

◆ dbname()

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

◆ disconnect_count()

public Bio::EnsEMBL::DBSQL::DBConnection::disconnect_count ( )

Undocumented method

Code:
click to view

◆ disconnect_if_idle()

public Boolean 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 : 1 or 0
               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

◆ disconnect_when_inactive()

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

◆ do()

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

◆ driver()

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

◆ equals()

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

◆ from_date_to_seconds()

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

◆ from_seconds_to_date()

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

◆ host()

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

◆ hostname()

public String Bio::EnsEMBL::DBSQL::DBConnection::hostname ( )
  Arg [1]    : (optional) string $arg
               The new value of the host used by this connection.
  Example    :
$hostname = $db_connection->hostname()
  Description: Convenience alias for the host method
  Returntype : String
 
Code:
click to view

◆ locator()

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

◆ new()

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    :
(-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

◆ pass()

public String Bio::EnsEMBL::DBSQL::DBConnection::pass ( )
  Arg [1]    : (optional) string $arg
               The new value of the password used by this connection.
  Example    :
$pass = $db_connection->pass()
  Description: Convenience alias for the password method
  Returntype : String
 
Code:
click to view

◆ password()

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

◆ port()

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

◆ prepare()

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

◆ prepare_cached()

public DBI Bio::EnsEMBL::DBSQL::DBConnection::prepare_cached ( )
  Arg [1]    : string $string
               the SQL statement to prepare
  Example    :
$sth = $db_connection->prepare_cached("SELECT column FROM table");
  Description: Prepares a SQL statement using the internal DBI database handle
               and returns the DBI statement handle. The prepared statement is
               cached so that it does not have to be prepared again.
               If only a subset of rows are required, finish() should be called
               on the object to free up the statement handle.
               For further information please consult https://metacpan.org/pod/DBI#prepare_cached
  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     : Experimental
 
Code:
click to view

◆ prevent_disconnect()

public void Bio::EnsEMBL::DBSQL::DBConnection::prevent_disconnect ( )
  Arg[1]      : CodeRef $callback
  Example     :
$dbc->prevent_disconnect(sub { $dbc->do('do something'); $dbc->do('something else')});
  Description : A wrapper method which prevents database disconnection for the
                duration of the callback. This is very useful if you need
                to make multiple database calls avoiding excessive database
                connection creation/destruction but still want the API
                to disconnect after the body of work.
                The value of disconnect_when_inactive() is set to 0 no
                matter what the original value was & after $callback has
                been executed. If disconnect_when_inactive() was
                already set to 0 then this method will be an effective no-op.
  Returntype  : None
  Exceptions  : Raised if there are issues with reverting the connection to its
                default state.
  Caller      : DBConnection methods
  Status      : Beta
 
Code:
click to view

◆ query_count()

public Bio::EnsEMBL::DBSQL::DBConnection::query_count ( )

Undocumented method

Code:
click to view

◆ quote_identifier()

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

◆ reconnect()

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

◆ reconnect_when_lost()

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

◆ sql_helper()

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

◆ timeout()

public Bio::EnsEMBL::DBSQL::DBConnection::timeout ( )

Undocumented method

Code:
click to view

◆ to_hash()

public Hash Bio::EnsEMBL::DBSQL::DBConnection::to_hash ( )
  Example    :
my $hash = $dbc->to_hash();
my $new_dbc = $dbc->new(%{$hash});
  Description: Provides a hash which is compatible with the
               parameters for DBConnection's new() method. This can be
               useful during serialisation
  Returntype : Hash
  Exceptions : none
  Caller     : general
  Status     : New
 
Code:
click to view

◆ user()

public String Bio::EnsEMBL::DBSQL::DBConnection::user ( )
  Arg [1]    : (optional) string $arg
               The new value of the username used by this connection.
  Example    :
$user = $db_connection->user()
  Description: Convenience alias for the username method
  Returntype : String
 
Code:
click to view

◆ username()

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

◆ work_with_db_handle()

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:
Bio::EnsEMBL::DBSQL::DBConnection::username
public String username()
Bio::EnsEMBL::DBSQL::DBConnection::locator
public String locator()
Bio::EnsEMBL::DBSQL::DBConnection::pass
public String pass()
Bio::EnsEMBL::DBSQL::DBConnection::driver
public String driver()
Bio::EnsEMBL::DBSQL::DBConnection::from_date_to_seconds
public String from_date_to_seconds()
Bio::EnsEMBL::DBSQL::DBConnection::prepare_cached
public DBI prepare_cached()
Bio::EnsEMBL::DBSQL::DBConnection::disconnect_if_idle
public Boolean disconnect_if_idle()
Bio::EnsEMBL::DBSQL::DBConnection::reconnect_when_lost
public Boolean reconnect_when_lost()
Bio::EnsEMBL::DBSQL::DBConnection::disconnect_count
public disconnect_count()
Bio::EnsEMBL::DBSQL::DBConnection::db_handle
public DBI db_handle()
Bio::EnsEMBL::DBSQL::DBConnection::user
public String user()
Bio::EnsEMBL::DBSQL::DBConnection::from_seconds_to_date
public String from_seconds_to_date()
Bio::EnsEMBL::DBSQL::DBConnection::work_with_db_handle
public Any work_with_db_handle()
Bio::EnsEMBL::DBSQL::DBConnection::_driver_object
protected _driver_object()
Bio::EnsEMBL::DBSQL::DBConnection::quote_identifier
public ArrayRef quote_identifier()
Bio::EnsEMBL::DBSQL::DBConnection::equals
public Boolean equals()
Bio::EnsEMBL::DBSQL::DBConnection::to_hash
public Hash to_hash()
Bio::EnsEMBL::DBSQL::DBConnection::disconnect_when_inactive
public Boolean disconnect_when_inactive()
Bio::EnsEMBL::DBSQL::DBConnection::timeout
public timeout()
Bio::EnsEMBL::DBSQL::DBConnection::password
public String password()
Bio::EnsEMBL::DBSQL::DBConnection::hostname
public String hostname()
Bio::EnsEMBL::DBSQL::DBConnection::prepare
public DBI prepare()
Bio::EnsEMBL::DBSQL::DBConnection::connect
public void connect()
Bio::EnsEMBL::DBSQL::DBConnection::prevent_disconnect
public void prevent_disconnect()
Bio::EnsEMBL::Utils::SqlHelper::new
public Instance new()
Bio::EnsEMBL::DBSQL::DBConnection
Definition: DBConnection.pm:42
Bio::EnsEMBL::DBSQL::DBConnection::add_limit_clause
public SQLStatement add_limit_clause()
Bio::EnsEMBL::DBSQL::DBConnection::host
public String host()
Bio::EnsEMBL::DBSQL::DBConnection::new
public Bio::EnsEMBL::DBSQL::DBConnection new()
Bio::EnsEMBL::Utils::SqlHelper
Definition: SqlHelper.pm:55
Bio::EnsEMBL::DBSQL::DBConnection::sql_helper
public Bio::EnsEMBL::Utils::SqlHelper sql_helper()
Bio::EnsEMBL::DBSQL::DBConnection::dbname
public String dbname()
Bio::EnsEMBL::DBSQL::DBConnection::query_count
public query_count()
Bio::EnsEMBL::DBSQL::DBConnection::connected
public Undef connected()
Bio::EnsEMBL::DBSQL::DBConnection::reconnect
public void reconnect()
Bio::EnsEMBL::DBSQL::DBConnection::port
public String port()