Connect to a sqlite database only if no connection exists. Isolation level
        for the connection is automatically set to autocommit
164686
def connect(self, *args, **kwargs):
        
        self.db = sqlite3.connect(*args, **kwargs)
        self.db.isolation_level = None
637347
def connect(self, fn):
        """"""
        self.conn = sqlite3.connect(fn)
        cur = self.get_cursor()
        cur.execute('PRAGMA page_size=4096')
        cur.execute('PRAGMA FOREIGN_KEYS=ON')
        cur.execute('PRAGMA cache_size=10000')
        cur.execute('PRAGMA journal_mode=MEMORY')
1039223
def _get_connection(self, key, host='', port='', user='', password='', database_url='', tags=None, use_cached=True):
        ""
        if key in self.dbs and use_cached:
            return self.dbs[key]
        try:
            connect_kwargs = self._get_connect_kwargs(
                host=host, port=port, user=user, password=password, database_url=database_url
            )

            connection = pg.connect(**connect_kwargs)
            connection.set_isolation_level(pg.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

        # re-raise the CheckExceptions raised by _get_connect_kwargs()
        except CheckException:
            raise

        except Exception:
            redacted_url = self._get_redacted_dsn(host, port, user, database_url)
            message = u'Cannot establish connection to {}'.format(redacted_url)

            self.service_check(
                self.SERVICE_CHECK_NAME,
                AgentCheck.CRITICAL,
                tags=self._get_service_checks_tags(host, port, database_url, tags),
                message=message,
            )
            raise

        self.dbs[key] = connection
        return connection
283047
public void setAutoCommit(boolean autoCommit) throws SQLException {
    if (autoCommit == getAutoCommit()) {
      return;
    }

    try (Statement stmt = createStatement()) {
      stateFlag |= ConnectionState.STATE_AUTOCOMMIT;
      stmt.executeUpdate("set autocommit=" + ((autoCommit) ? "1" : "0"));
    }
  }
523549
def connect(url=None, schema=None, sql_path=None, multiprocessing=False):
    
    if url is None:
        url = os.environ.get("DATABASE_URL")
    return Database(url, schema, sql_path=sql_path, multiprocessing=multiprocessing)
520375
def close(self):
        
        if getattr(self, '_connection', None):
            logger.debug('Closing sqlite connection.')
            self._connection.close()
            self._connection = None
860961
boolean assertConnection() {
    try {
      if (getDatabaseConnection() == null
          || getDatabaseConnection().connection == null) {
        return error(loc("no-current-connection"));
      }

      if (getDatabaseConnection().connection.isClosed()) {
        return error(loc("connection-is-closed"));
      }
    } catch (SQLException sqle) {
      return error(loc("no-current-connection"));
    }

    return true;
  }
527834
private void connect(Session session, boolean withReadOnlyData) {

        // Open new cache:
        if ((dataSource.length() == 0) || isConnected) {

            // nothing to do
            return;
        }

        PersistentStore store =
            database.persistentStoreCollection.getStore(this);

        this.store = store;

        DataFileCache cache = null;

        try {
            cache = (TextCache) database.logger.openTextCache(this,
                    dataSource, withReadOnlyData, isReversed);

            store.setCache(cache);

            // read and insert all the rows from the source file
            Row row     = null;
            int nextpos = 0;

            if (((TextCache) cache).ignoreFirst) {
                nextpos += ((TextCache) cache).readHeaderLine();
            }

            while (true) {
                row = (Row) store.get(nextpos, false);

                if (row == null) {
                    break;
                }

                Object[] data = row.getData();

                nextpos = row.getPos() + row.getStorageSize();

                ((RowAVLDiskData) row).setNewNodes();
                systemUpdateIdentityValue(data);
                enforceRowConstraints(session, data);

                for (int i = 0; i < indexList.length; i++) {
                    indexList[i].insert(null, store, row);
                }
            }
        } catch (Exception e) {
            int linenumber = cache == null ? 0
                                           : ((TextCache) cache)
                                               .getLineNumber();

            clearAllData(session);

            if (cache != null) {
                database.logger.closeTextCache(this);
                store.release();
            }

            // everything is in order here.
            // At this point table should either have a valid (old) data
            // source and cache or have an empty source and null cache.
            throw Error.error(ErrorCode.TEXT_FILE, 0, new Object[] {
                new Integer(linenumber), e.getMessage()
            });
        }

        isConnected = true;
        isReadOnly  = withReadOnlyData;
    }
64460
public void releaseConnection()
    {
        if (this.con == null)
        {
            return;
        }
        if(isInLocalTransaction())
        {
            log.error("Release connection: connection is in local transaction, missing 'localCommit' or" +
                    " 'localRollback' call - try to rollback the connection");
            localRollback();
        }
        else
        {
            this.connectionFactory.releaseConnection(this.jcd, this.con);
            this.con = null;
            this.batchCon = null;
        }
    }
575250
def reconnect(self, query = None, log_reconnect = False):
        
        uri = list(urisup.uri_help_split(self.sqluri))
        if uri[1]:
            authority   = list(uri[1])
            if authority[1]:
                authority[1] = None
            uri[1]      = authority

        if log_reconnect:
            LOG.warning('reconnecting to %r database (query: %r)', urisup.uri_help_unsplit(uri), query)
        self.__connect()
105621
def reset_database(self):
        
        if self._database_exists():
            con = psycopg2.connect(host=self.host, database="postgres",
                user=self.user, password=self.password, port=self.port)
            con.set_isolation_level(
                psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
            query = "DROP DATABASE {0};".format(self.dbname)
            c = con.cursor()
            c.execute(query)
            con.close()
        self.create_database()
560480
protected boolean isSingleConnection(DatabaseConnection conn1, DatabaseConnection conn2) throws SQLException {
		// initialize the connections auto-commit flags
		conn1.setAutoCommit(true);
		conn2.setAutoCommit(true);
		try {
			// change conn1's auto-commit to be false
			conn1.setAutoCommit(false);
			if (conn2.isAutoCommit()) {
				// if the 2nd connection's auto-commit is still true then we have multiple connections
				return false;
			} else {
				// if the 2nd connection's auto-commit is also false then we have a single connection
				return true;
			}
		} finally {
			// restore its auto-commit
			conn1.setAutoCommit(true);
		}
	}
274978
def connection(self, shareable=False):
        
        try:
            con = self.thread.connection
        except AttributeError:
            con = self.steady_connection()
            if not con.threadsafety():
                raise NotSupportedError("Database module is not thread-safe.")
            self.thread.connection = con
        con._ping_check()
        return con
1339741
def _conn(queue):
    '''
    
    '''
    queue_dir = __opts__['sqlite_queue_dir']
    db = os.path.join(queue_dir, '{0}.db'.format(queue))
    log.debug('Connecting to: %s', db)

    con = sqlite3.connect(db)
    tables = _list_tables(con)
    if queue not in tables:
        _create_table(con, queue)
    return con
307064
private void addConnection() throws SQLException {

    //create new connection
    Protocol protocol = Utils.retrieveProxy(urlParser, globalInfo);
    MariaDbConnection connection = new MariaDbConnection(protocol);
    MariaDbPooledConnection pooledConnection = createPoolConnection(connection);

    if (options.staticGlobal) {
      //on first connection load initial state
      if (globalInfo == null) {
        initializePoolGlobalState(connection);
      }
      //set default transaction isolation level to permit resetting to initial state
      connection.setDefaultTransactionIsolation(globalInfo.getDefaultTransactionIsolation());
    } else {
      //set default transaction isolation level to permit resetting to initial state
      connection.setDefaultTransactionIsolation(connection.getTransactionIsolation());
    }

    if (poolState.get() == POOL_STATE_OK
        && totalConnection.incrementAndGet() <= options.maxPoolSize) {
      idleConnections.addFirst(pooledConnection);

      if (logger.isDebugEnabled()) {
        logger.debug("pool {} new physical connection created (total:{}, active:{}, pending:{})",
            poolTag, totalConnection.get(), getActiveConnections(), pendingRequestNumber.get());
      }
      return;
    }

    silentCloseConnection(pooledConnection);
  }
995919
protected function _connect($create_db = false, $read_only = false){

		if($create_db && $read_only){

			ExceptionHandler::notice('SQLite::_connect() was called with both
				$create_db and $read_only enabled: Assuming read-only');

			$create_db = false;
		}

		if(!file_exists($this->_database) && !$create_db){

			throw new SQLException('Unable to load SQLite database file "'
				. basename($this->_database) . '", file not found');
		}

		try{

			if($read_only){

				$options = SQLITE3_OPEN_READONLY;
			}
			else{

				$options = SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE;
			}

			$this->_Connection = new \SQLite3($this->_database, $options);
			$this->_Connection->busyTimeout(static::BUSY_TIMEOUT);
		}
		catch(\Exception $e){

			throw new SQLException($e->getMessage());
		}

		if(!($this->_Connection instanceof \SQLite3)){

			throw new SQLException('Unspecified error while opening
				SQLite database');
		}
	}
708322
def close(self):
        

        if self.__delayed_connection_path and self.__connection is None:
            self.__initialize_connection()
            return

        try:
            self.check_connection()
        except (SystemError, NullDatabaseConnectionError):
            return

        logger.debug("close connection to a SQLite database: path='{}'".format(self.database_path))

        self.commit()
        self.connection.close()
        self.__initialize_connection()