Example #1
0
def compile_option(p):
    if not hasattr(compile_option, '_pragma_cache'):
        conn = sqlite3.connect(':memory:')
        curs = conn.execute('pragma compile_options')
        opts = [opt.lower().split('=')[0].strip() for opt, in curs.fetchall()]
        compile_option._pragma_cache = set(opts)
    return p in compile_option._pragma_cache
Example #2
0
def json_installed():
    if sqlite3.sqlite_version_info < (3, 9, 0):
        return False
    # Test in-memory DB to determine if the FTS5 extension is installed.
    tmp_db = sqlite3.connect(':memory:')
    try:
        tmp_db.execute('select json(?)', (1337, ))
    except:
        return False
    finally:
        tmp_db.close()
    return True
Example #3
0
def json_installed():
    if sqlite3.sqlite_version_info < (3, 9, 0):
        return False
    # Test in-memory DB to determine if the FTS5 extension is installed.
    tmp_db = sqlite3.connect(':memory:')
    try:
        tmp_db.execute('select json(?)', (1337,))
    except:
        return False
    finally:
        tmp_db.close()
    return True
Example #4
0
 def check_pysqlite(cls):
     try:
         from pysqlite2 import dbapi2 as sqlite3
     except ImportError:
         import sqlite3
     conn = sqlite3.connect(':memory:')
     try:
         results = conn.execute('PRAGMA compile_options;').fetchall()
     finally:
         conn.close()
     for option, in results:
         if option == 'BERKELEY_DB':
             return True
     return False
Example #5
0
 def check_pysqlite(cls):
     try:
         from pysqlite2 import dbapi2 as sqlite3
     except ImportError:
         import sqlite3
     conn = sqlite3.connect(':memory:')
     try:
         results = conn.execute('PRAGMA compile_options;').fetchall()
     finally:
         conn.close()
     for option, in results:
         if option == 'BERKELEY_DB':
             return True
     return False
Example #6
0
File: db.py Project: Erikun/elogy
def db_dependencies_installed(type='SQLite'):
    if type == 'SQLite':
        #Check that version is high enough to have JSON1
        if sqlite3.sqlite_version_info[:3] < (3, 9, 0):
            sys.exit('Sqlite version too low, 3.9.0 or later required')
        tmp_db = sqlite3.connect(':memory:')
        setup_test_table = 'create table temp(attrib1,attrib2)'
        tmp_db.execute(setup_test_table)
        test_json_ext = 'insert into temp (attrib1, attrib2) values("first", json(\'{"A":"12345", "B":"54321"}\'))'
        try:
            #Test if query with function using JSON1 works
            tmp_db.execute(test_json_ext)
        except:
            tmp_db.close()
            sys.exit('Could not find SQLite JSON1 extension.')
        finally:
            tmp_db.close()
    def fts5_installed(cls):
        if sqlite3.sqlite_version_info[:3] < FTS5_MIN_VERSION:
            return False

        # Test in-memory DB to determine if the FTS5 extension is installed.
        tmp_db = sqlite3.connect(':memory:')
        try:
            tmp_db.execute('CREATE VIRTUAL TABLE fts5test USING fts5 (data);')
        except:
            try:
                sqlite3.enable_load_extension(True)
                sqlite3.load_extension('fts5')
            except:
                return False
            else:
                cls._meta.database.load_extension('fts5')
        finally:
            tmp_db.close()

        return True
import time
from collections import defaultdict
from collections import namedtuple

from peewee import *
from peewee import sqlite3 as _sqlite3
from playhouse.sqlite_ext import *


if sys.version_info[0] == 3:
    basestring = str


USE_JSON_FALLBACK = True
if _sqlite3.sqlite_version_info >= (3, 9, 0):
    conn = _sqlite3.connect(":memory:")
    try:
        conn.execute("select json(?)", (1337,))
    except:
        pass
    else:
        USE_JSON_FALLBACK = False
    conn.close()

split_re = re.compile("(?:(\[\d+\])|\.)")


def _json_extract_fallback(json_text, path):
    json_data = json.loads(json_text)
    path = path.lstrip("$.")
    parts = split_re.split(path)