How to use the apsw.SQLITE_OPEN_URI 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 kovidgoyal / calibre / src / calibre / utils / apsw_shell.py View on Github external
def _ensure_db(self):
        "The database isn't opened until first use.  This function ensures it is now open."
        if not self._db:
            if not self.dbfilename:
                self.dbfilename=":memory:"
            self._db=apsw.Connection(self.dbfilename, flags=apsw.SQLITE_OPEN_URI | apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE)
        return self._db
github norbusan / calibre-debian / src / calibre / utils / apsw_shell.py View on Github external
def _ensure_db(self):
        "The database isn't opened until first use.  This function ensures it is now open."
        if not self._db:
            if not self.dbfilename:
                self.dbfilename=":memory:"
            self._db=apsw.Connection(self.dbfilename, flags=apsw.SQLITE_OPEN_URI | apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE)
        return self._db
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / mterm.py View on Github external
def createConnection(db):
    try:
        if 'SQLITE_OPEN_URI' in apsw.__dict__:
            connection = functions.Connection(db, flags=apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE | apsw.SQLITE_OPEN_URI)
        else:
            connection = functions.Connection(db)
        functions.register(connection)
        connection.enableloadextension(True)
    except Exception, e:
        exitwitherror(e)

    # Change TEMP store to where the mterm is run from
    try:
        connection.cursor().execute("PRAGMA temp_store_directory='.';PRAGMA page_size=16384;PRAGMA default_cache_size=3000;")
        # if pipedinput:
    except:
        pass

    functions.settings['stacktrace'] = True
github plasticityai / magnitude / pymagnitude / third_party / _apsw / example-code.py View on Github external
def xRead(self, amount, offset):
        return encryptme(super(ObfuscatedVFSFile, self).xRead(amount, offset))

    def xWrite(self, data, offset):
        super(ObfuscatedVFSFile, self).xWrite(encryptme(data), offset)

# To register the VFS we just instantiate it
obfuvfs=ObfuscatedVFS()
# Lets see what vfs are now available?
#@@CAPTURE
print (apsw.vfsnames())
#@@ENDCAPTURE

# Make an obfuscated db, passing in some URI parameters
obfudb=apsw.Connection("file:myobfudb?fast=speed&level=7&warp=on",
                       flags=apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE | apsw.SQLITE_OPEN_URI,
                       vfs=obfuvfs.vfsname)
# Check it works
obfudb.cursor().execute("create table foo(x,y); insert into foo values(1,2)")

# Check it really is obfuscated on disk
#@@CAPTURE
print (open("myobfudb", "rb").read()[:20])
#@@ENDCAPTURE

# And unobfuscating it
#@@CAPTURE
print (encryptme(open("myobfudb", "rb").read()[:20]))
#@@ENDCAPTURE

# Tidy up
obfudb.close()
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / functions / __init__.py View on Github external
def register(connection=None):
    global firstimport, oldexecdb

    if connection == None:
        if 'SQLITE_OPEN_URI' in apsw.__dict__:
            connection = Connection(':memory:', flags=apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE | apsw.SQLITE_OPEN_URI)
        else:
            connection = Connection(':memory:')

    connection.openiters = {}
    connection.registered = True
    connection.cursor().execute("attach database ':memory:' as mem;", parse=False)

    variables.filename = connection.filename

    # To avoid db corruption set connection to fullfsync mode when MacOS is detected
    if sys.platform == 'darwin':
        c = connection.cursor().execute('pragma fullfsync=1;', parse=False)

    functionspath=os.path.abspath(__path__[0])

    def findmodules(abspath, relativepath):
github plasticityai / magnitude / pymagnitude / third_party / _apsw / tools / shell.py View on Github external
def _ensure_db(self):
        "The database isn't opened until first use.  This function ensures it is now open."
        if not self._db:
            if not self.dbfilename:
                self.dbfilename=":memory:"
            self._db=apsw.Connection(self.dbfilename, flags=apsw.SQLITE_OPEN_URI | apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE)
        return self._db
github lbryio / lbry-sdk / lbry / lbry / wallet / server / db / reader.py View on Github external
def initializer(log, _path, _ledger_name, query_timeout, _measure=False):
    db = apsw.Connection(_path, flags=apsw.SQLITE_OPEN_READONLY | apsw.SQLITE_OPEN_URI)
    def row_factory(cursor, row):
        return {k[0]: row[i] for i, k in enumerate(cursor.getdescription())}
    db.setrowtrace(row_factory)
    ctx.set(
        ReaderState(
            db=db, stack=[], metrics={}, is_tracking_metrics=_measure,
            ledger=MainNetLedger if _ledger_name == 'mainnet' else RegTestLedger,
            query_timeout=query_timeout, log=log
        )
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)