Returns the sqlite database for the current thread.

        :return     <variant> || None
193763
def open(self, writeAccess=False):
        
        host = self.database().writeHost() if writeAccess else self.database().host()
        pool = self.__pool[host]

        if self.__poolSize[host] >= self.__maxSize or pool.qsize():
            if pool.qsize() == 0:
                log.warning('Waiting for connection to database!!!')
            return pool.get()
        else:
            db = self.database()

            # process a pre-connect event
            event = orb.events.ConnectionEvent()
            db.onPreConnect(event)

            self.__poolSize[host] += 1
            try:
                conn = self._open(self.database(), writeAccess=writeAccess)
            except Exception:
                self.__poolSize[host] -= 1
                raise
            else:
                event = orb.events.ConnectionEvent(success=conn is not None, native=conn)
                db.onPostConnect(event)
                return conn
181884
def _getThread(self, given_thread_id=None, given_thread_type=None):
        
        if given_thread_id is None:
            if self._default_thread_id is not None:
                return self._default_thread_id, self._default_thread_type
            else:
                raise ValueError("Thread ID is not set")
        else:
            return given_thread_id, given_thread_type
1143193
def Query(self, query):
    
    cursor = self._database.cursor()
    cursor.execute(query)
    return cursor
1215926
def convert_to_sqlite(self, destination=None, method="shell", progress=False):
        """"""
        # Display progress bar #
        if progress: progress = tqdm.tqdm
        else:        progress = lambda x:x
        # Default path #
        if destination is None: destination = self.replace_extension('sqlite')
        # Delete if it exists #
        destination.remove()
        # Method with shell and a temp file #
        if method == 'shell':     return self.sqlite_by_shell(destination)
        # Method without a temp file #
        if method == 'object':    return self.sqlite_by_object(destination, progress)
        # Method with dataframe #
        if method == 'dataframe': return self.sqlite_by_df(destination, progress)
957888
static synchronized SQLiteDatabase getDatabase() {
        if(sInstance == null) {
           throw new SprinklesNotInitializedException();
        }

        if(sDatabase == null) {
            DbOpenHelper dbOpenHelper = new DbOpenHelper(sInstance.mContext, sInstance.databaseName, sInstance.initialDatabaseVersion);
            sDatabase = dbOpenHelper.getWritableDatabase();
        }

        return sDatabase;
    }
1116353
def db(cls, dbname=None):
        

        cls._load_entry_points()

        dbname = dbname or config.get('eop', 'dbname', fallback=cls.DEFAULT_DBNAME)

        if dbname not in cls._dbs.keys():
            raise EopError("Unknown database '%s'" % dbname)

        if isclass(cls._dbs[dbname]):
            # Instanciation
            try:
                cls._dbs[dbname] = cls._dbs[dbname]()
            except Exception as e:
                # Keep the exception in cache in order to not retry instanciation
                # every single time EopDb.db() is called, as instanciation
                # of database is generally a time consumming operation.
                # If it failed once, it will most probably fail again
                cls._dbs[dbname] = e

        if isinstance(cls._dbs[dbname], Exception):
            raise EopError("Problem at database instanciation") from cls._dbs[dbname]

        return cls._dbs[dbname]
779434
def db(self):
        

        # Initialize the database handle; we're running in a separate
        # process, so we need to get_database() ourself
        if not self._db:
            self._db = self.config.get_database()

        return self._db
195573
function getDatabase(index, opts) {
  var db;
  if(!this._databases[index]) {
    db = new Database(this, opts);
    this._databases[index] = db;
  }
  return this._databases[index];
}
1212945
def get_last_id(self, cur, table='reaction'):
        
        cur.execute("SELECT seq FROM sqlite_sequence WHERE name='{0}'"
                    .format(table))
        result = cur.fetchone()
        if result is not None:
            id = result[0]
        else:
            id = 0
        return id
987588
def load_sqlite(self, db, query=None, table=None, cls=None,
                    column_map=None):
        """"""
        if column_map is None:
            column_map = {}
        db_path = self.profile_path(db, must_exist=True)

        def obj_factory(cursor, row):
            dict_ = {}
            for idx, col in enumerate(cursor.description):
                new_name = column_map.get(col[0], col[0])
                dict_[new_name] = row[idx]
            return cls(**dict_)

        con = sqlite3.connect(str(db_path))
        con.row_factory = obj_factory
        cursor = con.cursor()
        if not query:
            columns = [f.name for f in attr.fields(cls)]
            for k, v in column_map.items():
                columns[columns.index(v)] = k
            query = 'SELECT %s FROM %s' % (','.join(columns), table)
        cursor.execute(query)
        while True:
            item = cursor.fetchone()
            if item is None:
                break
            yield item
        con.close()
139159
def query(self, command):
        
        if self.closed:
            Log.error("database is closed")

        signal = _allocate_lock()
        signal.acquire()
        result = Data()
        trace = extract_stack(1) if self.get_trace else None

        if self.get_trace:
            current_thread = Thread.current()
            with self.locker:
                for t in self.available_transactions:
                    if t.thread is current_thread:
                        Log.error(DOUBLE_TRANSACTION_ERROR)

        self.queue.add(CommandItem(command, result, signal, trace, None))
        signal.acquire()

        if result.exception:
            Log.error("Problem with Sqlite call", cause=result.exception)
        return result
415945
def database(key='default', slave=False):
    
    if slave:
        key += '.slave'
        return choice(__db[key])
    return __db.get(key)
169790
def _db(self):
        
        if not hasattr(self, "_db_client") or getattr(self, "_db_client") is None:
            self._db_client = get_db_client()
        return self._db_client
414666
def getDatabases(self):
        
        cur = self._conn.cursor()
        cur.execute("""SHOW DATABASES;""")
        rows = cur.fetchall()
        if rows:
            return [row[0] for row in rows]
        else:
            return []
130647
def sqlite_default():
    '''
    
    '''
    def parse_url(url):
        # TODO: need separate option for a config file
        if url.endswith('.db') or url.endswith('.sqlite'):
            if not url.startswith('sqlite:///'):
                url = 'sqlite:///' + url
        elif url.endswith('.cfg') or url.endswith('.conf'):
            conf = configparser.SafeConfigParser(allow_no_value=True)
            conf.optionxform = str  # options are case-sensitive
            conf.read(url)
            url = conf.get('sqlalchemy', 'url')

        return url
    return parse_url
559894
def database_dsn(self):
        """"""

        if not self._config.library.database:
            return 'sqlite:///{root}/library.db'.format(root=self._root)

        return self._config.library.database.format(root=self._root)
811754
def available(self):
        '''  '''
        return self.db_name in map(
            lambda x: x['name'], self._db.get_database_list()
        )