How to use the apsw.SQLITE_OPEN_CREATE function in apsw

To help you get started, we’ve selected a few apsw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plasticityai / magnitude / pymagnitude / third_party / _apsw / tools / docmissing.py View on Github external
klass, funcname=funcname.split(".",1)
                else:
                    klass="apsw"
                if klass not in classes:
                    classes[klass]=[]
                classes[klass].append(funcname)


# ok, so we know what was documented.  Now lets see what exists

con=apsw.Connection(":memory:")
cur=con.cursor()
cur.execute("create table x(y); insert into x values(x'abcdef1012');select * from x")
blob=con.blobopen("main", "x", "y", con.last_insert_rowid(), 0)
vfs=apsw.VFS("aname", "")
vfsfile=apsw.VFSFile("", ":memory:", [apsw.SQLITE_OPEN_MAIN_DB|apsw.SQLITE_OPEN_CREATE|apsw.SQLITE_OPEN_READWRITE, 0])

# virtual tables aren't real - just check their size hasn't changed
assert len(classes['VTModule'])==2
del classes['VTModule']
assert len(classes['VTTable'])==13
del classes['VTTable']
assert len(classes['VTCursor'])==6
del classes['VTCursor']

for name, obj in ( ('Connection', con),
                   ('Cursor', cur),
                   ('blob', blob),
                   ('VFS', vfs),
                   ('VFSFile', vfsfile),
                   ('apsw', apsw),
                   ):
github trakt / Plex-Trakt-Scrobbler / Trakttv.bundle / Contents / Libraries / Shared / plugin / core / helpers / database.py View on Github external
def db_connect(path, type):
    # Connect to new database
    if type == 'peewee':
        db = APSWDatabase(path, autorollback=True, journal_mode='WAL', timeout=BUSY_TIMEOUT)
    elif type == 'raw':
        db = apsw.Connection(path, flags=apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE | apsw.SQLITE_OPEN_WAL)
        db.setbusytimeout(BUSY_TIMEOUT)
    else:
        raise ValueError('Unknown database type: %r' % type)

    log.debug('Connected to database at %r', path)
    return db
github octobear2 / ob2 / ob2 / database / __init__.py View on Github external
def __init__(self, path=None, read_only=False):
        if path is None:
            path = config.database_path
        if read_only:
            flags = apsw.SQLITE_OPEN_READONLY
        else:
            flags = apsw.SQLITE_OPEN_CREATE | apsw.SQLITE_OPEN_READWRITE

        # The global lock is acquired in the constructor, so you must never instantiate a DbCursor
        # object without actually using it.
        global_database_lock.acquire()

        try:
            # The connection setup must be done in the constructor, NOT in __enter__.
            # If __enter__ raises an exception, then the __exit__ method will also be called.
            self.connection = apsw.Connection(path, flags)
            self.connection.setbusytimeout(5000)
            for module in apply_filters("database-vtmodules", [self.get_assignments_vtmodule()]):
                module.registerWithConnection(self.connection)
        except Exception:
            global_database_lock.release()
            raise
github bioidiap / bob / python / bob / db / utils.py View on Github external
def __call__(self):

    from sqlite3 import connect

    if (self.readonly or (self.vfs is not None)) and self.APSW_IS_AVAILABLE:
      # and not self.lockable
      import apsw
      if self.readonly: flags = apsw.SQLITE_OPEN_READONLY #1
      else: flags = apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE #2|4
      apsw_con = apsw.Connection(self.filename, vfs=self.vfs, flags=flags)
      return connect(apsw_con)

    return connect(self.filename)
github lbryio / lbry-sdk / lbry / lbry / wallet / server / db / writer.py View on Github external
def open(self):
        self.db = apsw.Connection(
            self._db_path,
            flags=(
                apsw.SQLITE_OPEN_READWRITE |
                apsw.SQLITE_OPEN_CREATE |
                apsw.SQLITE_OPEN_URI
            )
        )
        def exec_factory(cursor, statement, bindings):
            tpl = namedtuple('row', (d[0] for d in cursor.getdescription()))
            cursor.setrowtrace(lambda cursor, row: tpl(*row))
            return True
        self.db.setexectrace(exec_factory)
        self.execute(self.PRAGMAS)
        self.execute(self.CREATE_TABLES_QUERY)
        register_canonical_functions(self.db)
        register_trending_functions(self.db)