Returns connection to sqlite db.

        Returns:
            connection to the sqlite db who stores mpr data.
425503
def _get_connection(self):
        
        if getattr(self, '_connection', None):
            logger.debug('Connection to sqlite db already exists. Using existing one.')
        else:
            dsn = self._dsn
            if dsn == 'sqlite://':
                dsn = ':memory:'
            else:
                dsn = dsn.replace('sqlite:///', '')

            logger.debug(
                'Creating new apsw connection.\n   dsn: {}, config_dsn: {}'
                .format(dsn, self._dsn))
            self._connection = apsw.Connection(dsn)

        return self._connection
342228
protected DatabaseConnection getSavedConnection() {
		NestedConnection nested = specialConnection.get();
		if (nested == null) {
			return null;
		} else {
			return nested.connection;
		}
	}
416505
def connect(self):
        

        attempt = 0
        for i in self.max_tries_counter:
            attempt += 1
            try:
                self._conn = self._connect()
            except ConnectionError as exc:
                logger.warning('Attempt %s/%s. Connection to %s:%s failed after %sms.',
                               attempt, self.max_tries if self.max_tries != 0 else '∞',
                               self.host, self.port, self.connection_timeout)
                if attempt == self.max_tries:
                    logger.critical('Cannot connect to the Database. Giving up.')
                    raise ConnectionError() from exc
            else:
                break
524211
private Connection getConnection() {
        final JdbcTransaction jdbcTransaction = TX.get();
        if (null != jdbcTransaction && jdbcTransaction.isActive()) {
            return jdbcTransaction.getConnection();
        }

        Connection ret = CONN.get();
        try {
            if (null != ret && !ret.isClosed()) {
                return ret;
            }

            ret = Connections.getConnection();
        } catch (final SQLException e) {
            LOGGER.log(Level.ERROR, "Gets a connection failed", e);
        }

        CONN.set(ret);

        return ret;
    }
397792
def connect_db(database_name=":memory:"):
    
    db = repo.Repo.connect_db(database_name)
    base.Repo.db = db
    query.Repo.db = db
903743
DB db() {
    DB _db = this._db.get();
    if (_db == null) {
      throw new IllegalStateException("DB is closed.");
    }
    return _db;
  }
1082343
private Connection getConn() {
        Connection connection = localConnection.get();
        return ifNotNullReturn(connection, connection, this.getSql2o().open());
    }
302312
def _connectSimpleDB(self):
        
        db = boto.sdb.connect_to_region(self.region)
        if db is None:
            raise ValueError("Could not connect to SimpleDB. Make sure '%s' is a valid SimpleDB "
                             "region." % self.region)
        assert db is not None
        monkeyPatchSdbConnection(db)
        return db
132450
def connect_db(Repo, database=":memory:"):
        
        Repo.db = sqlite3.connect(database,
                                  detect_types=sqlite3.PARSE_DECLTYPES)
        return Repo.db
386335
def GetDatabaseAccount(self, url_connection=None):
        
        if url_connection is None:
            url_connection = self.url_connection

        initial_headers = dict(self.default_headers)
        headers = base.GetHeaders(self,
                                  initial_headers,
                                  'get',
                                  '',  # path
                                  '',  # id
                                  '',  # type
                                  {})

        request = request_object._RequestObject('databaseaccount', documents._OperationType.Read, url_connection)
        result, self.last_response_headers = self.__Get('',
                                                        request,
                                                        headers)
        database_account = documents.DatabaseAccount()
        database_account.DatabasesLink = '/dbs/'
        database_account.MediaLink = '/media/'
        if (http_constants.HttpHeaders.MaxMediaStorageUsageInMB in
            self.last_response_headers):
            database_account.MaxMediaStorageUsageInMB = (
                self.last_response_headers[
                    http_constants.HttpHeaders.MaxMediaStorageUsageInMB])
        if (http_constants.HttpHeaders.CurrentMediaStorageUsageInMB in
            self.last_response_headers):
            database_account.CurrentMediaStorageUsageInMB = (
                self.last_response_headers[
                    http_constants.HttpHeaders.CurrentMediaStorageUsageInMB])
        database_account.ConsistencyPolicy = result.get(constants._Constants.UserConsistencyPolicy)

        # WritableLocations and ReadableLocations fields will be available only for geo-replicated database accounts
        if constants._Constants.WritableLocations in result:
            database_account._WritableLocations = result[constants._Constants.WritableLocations]
        if constants._Constants.ReadableLocations in result:
            database_account._ReadableLocations = result[constants._Constants.ReadableLocations]
        if constants._Constants.EnableMultipleWritableLocations in result:
            database_account._EnableMultipleWritableLocations = result[constants._Constants.EnableMultipleWritableLocations]

        self._useMultipleWriteLocations = self.connection_policy.UseMultipleWriteLocations and database_account._EnableMultipleWritableLocations
        return database_account
500004
def make_connection(config=None, default_model=None,
                    _api_version=datastore_rpc._DATASTORE_V3,
                    _id_resolver=None):
  
  return datastore_rpc.Connection(
      adapter=ModelAdapter(default_model, id_resolver=_id_resolver),
      config=config,
      _api_version=_api_version)
658784
function getDatabase(database, options, callback) {
    getDatabaseConnector(database, options, returnDatabase)

    function returnDatabase(err, databaseConnector) {
        if (err) {
            return callback(err)
        }

        var db = databaseConnector.db(database)

        callback(null, db)
    }
}
888036
def get_cursor(self, instance, db_key, db_name=None):
        '''
        
        '''
        conn_key = self._conn_key(instance, db_key, db_name)
        try:
            conn = self.connections[conn_key]['conn']
        except KeyError:
            # We catch KeyError to avoid leaking the auth info used to compose the key
            # FIXME: we should find a better way to compute unique keys to map opened connections other than
            # using auth info in clear text!
            raise SQLConnectionError("Cannot find an opened connection for host: {}".format(instance.get('host')))
        return conn.cursor()
184186
def _connect(dbapi_connection, connection_record):
    """"""

    # If back end is sqlite
    if type(dbapi_connection) is sqlite3.Connection:

        # Respect foreign key constraints by default
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON")
        cursor.close()
273695
def _get_database(self, database_name):
        
        try:
            return self._client[database_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot connect to database %s!"
                                  % self._database) from ex
543992
def connect_db(config):
    """"""
    rv = sqlite3.connect(config["database"]["uri"])
    rv.row_factory = sqlite3.Row
    return rv
135032
public Connection getConnection()
    {
        Connection connection;

        try
        {
            if (getLogger().isDebugEnabled())
            {
                getLogger().debug("before: active : " + connectionPool.getNumActive() + " idle: " + connectionPool.getNumIdle());
            }
            connection = dataSource.getConnection();
            if (getLogger().isDebugEnabled())
            {
                getLogger().debug("after: active : " + connectionPool.getNumActive() + " idle: " + connectionPool.getNumIdle() + " giving " + connection);
            }
        }
        catch (Exception e)
        {
            getLogger().error("Unable to get connection " + this, e);
            throw new MithraDatabaseException("could not get connection", e);
        }
        if (connection == null)
        {
            throw new MithraDatabaseException("could not get connection"+this);
        }
        return connection;
    }