Пример #1
0
Файл: geo.py Проект: kball/ambry
def _on_connect_geo(dbapi_con, con_record):
    '''ISSUE some Sqlite pragmas when the connection is created'''
    from ..util import RedirectStdStreams
    from sqlite import _on_connect_bundle as ocb

    ocb(dbapi_con, con_record)

    ## NOTE ABOUT journal_mode = WAL: it improves concurency, but has some downsides.
    ## See http://sqlite.org/wal.html

    dbapi_con.execute('PRAGMA page_size = 8192')
    dbapi_con.execute('PRAGMA temp_store = MEMORY')
    dbapi_con.execute('PRAGMA cache_size = 50000')
    dbapi_con.execute('PRAGMA foreign_keys = OFF')
    dbapi_con.execute('PRAGMA journal_mode = WAL')
    dbapi_con.execute('PRAGMA synchronous = OFF')

    try:
        dbapi_con.execute('select spatialite_version()')
        return
    except:
        try:
            dbapi_con.enable_load_extension(True)
        except AttributeError as e:
            raise


    try:
        with RedirectStdStreams():  # Spatialite prints its version header always, this supresses it.
            dbapi_con.execute("select load_extension('/usr/lib/libspatialite.so')")
    except:
        with RedirectStdStreams():  # Spatialite prints its version header always, this supresses it.
            dbapi_con.execute("select load_extension('/usr/lib/libspatialite.so.3')")
Пример #2
0
def _on_connect_geo(dbapi_con, con_record):
    """ISSUE some Sqlite pragmas when the connection is created."""
    from ..util import RedirectStdStreams
    from sqlite import _on_connect_bundle as ocb
    from ..dbexceptions import DatabaseError
    from pysqlite2.dbapi2 import OperationalError

    ocb(dbapi_con, con_record)

    # NOTE ABOUT journal_mode = WAL: it improves concurency, but has some
    # downsides.
    # See http://sqlite.org/wal.html

    dbapi_con.execute('PRAGMA page_size = 8192')
    dbapi_con.execute('PRAGMA temp_store = MEMORY')
    dbapi_con.execute('PRAGMA cache_size = 50000')
    dbapi_con.execute('PRAGMA foreign_keys = OFF')
    dbapi_con.execute('PRAGMA journal_mode = WAL')
    dbapi_con.execute('PRAGMA synchronous = OFF')

    def load_extension():
        try:
            dbapi_con.execute('select spatialite_version()')
            return
        except:
            try:
                dbapi_con.enable_load_extension(True)
            except AttributeError:
                raise

        # This is so wrong, but I don't know what's right.
        # ( My code has become a Country song. )

        libs = [
            "select load_extension('/usr/lib/x86_64-linux-gnu/libspatialite')",
            "select load_extension('/usr/lib/libspatialite.so')",
            "select load_extension('/usr/lib/libspatialite.so.3')",
            "select "
            "load_extension('/usr/lib/x86_64-linux-gnu/libspatialite.so.5')",

        ]

        for l in libs:
            try:
                # Spatialite prints its version header always, this supresses
                # it.
                with RedirectStdStreams():
                    dbapi_con.execute(l)

                return
            except OperationalError:
                continue

        raise DatabaseError(
            "Could not load the spatialite extension. Tried: {}".format(libs))

    load_extension()
Пример #3
0
def _on_connect_geo(dbapi_con, con_record):
    """ISSUE some Sqlite pragmas when the connection is created."""
    from ..util import RedirectStdStreams
    from sqlite import _on_connect_bundle as ocb
    from ..dbexceptions import DatabaseError
    from pysqlite2.dbapi2 import OperationalError

    ocb(dbapi_con, con_record)

    # NOTE ABOUT journal_mode = WAL: it improves concurency, but has some downsides.
    # See http://sqlite.org/wal.html

    dbapi_con.execute('PRAGMA page_size = 8192')
    dbapi_con.execute('PRAGMA temp_store = MEMORY')
    dbapi_con.execute('PRAGMA cache_size = 50000')
    dbapi_con.execute('PRAGMA foreign_keys = OFF')
    dbapi_con.execute('PRAGMA journal_mode = WAL')
    dbapi_con.execute('PRAGMA synchronous = OFF')

    def load_extension():
        try:
            dbapi_con.execute('select spatialite_version()')
            return
        except:
            try:
                dbapi_con.enable_load_extension(True)
            except AttributeError as e:
                raise

        # This is so wrong, but I don't know what's right.
        # ( My code has become a Country song. )

        libs = [
            "select load_extension('/usr/lib/x86_64-linux-gnu/libspatialite')",
            "select load_extension('/usr/lib/libspatialite.so')",
            "select load_extension('/usr/lib/libspatialite.so.3')",
            "select load_extension('/usr/lib/x86_64-linux-gnu/libspatialite.so.5')",
        ]

        for l in libs:
            try:
                # Spatialite prints its version header always, this supresses
                # it.
                with RedirectStdStreams():
                    dbapi_con.execute(l)

                return
            except OperationalError:
                continue

        raise DatabaseError(
            "Could not load the spatialite extension. Tried: {}".format(libs))

    load_extension()
Пример #4
0
def _on_connect_partition(dbapi_con, con_record):
    '''ISSUE some Sqlite pragmas when the connection is created'''
    from sqlite import _on_connect_bundle as ocb

    ocb(dbapi_con, con_record)