Beispiel #1
0
 def setUp(self):
     self.con = sqlite.connect(":memory:")
     try:
         del sqlite.adapters[int]
     except:
         pass
     sqlite.register_adapter(int, ObjectAdaptationTests.cast)
     self.cur = self.con.cursor()
Beispiel #2
0
 def setUp(self):
     self.con = sqlite.connect(":memory:")
     try:
         del sqlite.adapters[int]
     except:
         pass
     sqlite.register_adapter(int, ObjectAdaptationTests.cast)
     self.cur = self.con.cursor()
Beispiel #3
0
    def _connectToDb(self):
        """ Opens a db connection
        """
        self.con = sqlite.connect(self.db_path, detect_types=sqlite.PARSE_DECLTYPES)
        sqlite.register_adapter(bool, int)
        sqlite.register_converter("BOOLEAN", lambda v: bool(int(v)))
        self.con.row_factory = self._dictFactory

        # Use PRAGMA key to encrypt / decrypt database.
        cur = self.con.cursor()
        cur.execute("PRAGMA key = 'passphrase';") # TODO: Get passphrase from user.
Beispiel #4
0
    def _connectToDb(self):
        """ Opens a db connection
        """
        self.con = sqlite.connect(self.db_path, detect_types=sqlite.PARSE_DECLTYPES)
        sqlite.register_adapter(bool, int)
        sqlite.register_converter("bool", lambda v: bool(int(v)))
        self.con.row_factory = self._dictFactory

        # Use PRAGMA key to encrypt / decrypt database.
        cur = self.con.cursor()
        cur.execute("PRAGMA key = 'passphrase';")
Beispiel #5
0
    def _connectToDb(self):
        """ Opens a db connection
        """
        self.con = sqlite.connect(self.db_path, detect_types=sqlite.PARSE_DECLTYPES, timeout=10)
        sqlite.register_adapter(bool, int)
        sqlite.register_converter("bool", lambda v: bool(int(v)))
        self.con.row_factory = self._dictFactory

        if not self.disable_sqlite_crypt:
            # Use PRAGMA key to encrypt / decrypt database.
            cur = self.con.cursor()
            cur.execute("PRAGMA key = 'passphrase';")
Beispiel #6
0
    def _connectToDb(self):
        """ Opens a db connection
        """
        self.lock.acquire()
        self.con = sqlite.connect(self.db_path,
                                  detect_types=sqlite.PARSE_DECLTYPES,
                                  timeout=10)
        sqlite.register_adapter(bool, int)
        sqlite.register_converter("bool", lambda v: bool(int(v)))
        self.con.row_factory = self._dictFactory

        if not self.disable_sqlite_crypt:
            # Use PRAGMA key to encrypt / decrypt database.
            with self.con:
                cur = self.con.cursor()
                cur.execute("PRAGMA key = 'passphrase';")
Beispiel #7
0
"""
import datetime
import decimal
import sys

from plover import *
from playhouse.sqlite_ext import SqliteExtDatabase
if sys.version_info[0] != 3:
    from pysqlcipher import dbapi2 as sqlcipher
else:
    try:
        from sqlcipher3 import dbapi2 as sqlcipher
    except ImportError:
        from pysqlcipher3 import dbapi2 as sqlcipher

sqlcipher.register_adapter(decimal.Decimal, str)
sqlcipher.register_adapter(datetime.date, str)
sqlcipher.register_adapter(datetime.time, str)


class _SqlCipherDatabase(object):
    def _connect(self):
        params = dict(self.connect_params)
        passphrase = params.pop('passphrase', '').replace("'", "''")

        conn = sqlcipher.connect(self.database, isolation_level=None, **params)
        try:
            if passphrase:
                conn.execute("PRAGMA key='%s'" % passphrase)
            self._add_conn_hooks(conn)
        except:
Beispiel #8
0
See a more elaborate example with this code at
https://gist.github.com/thedod/11048875
"""
import datetime
import decimal
import sys

from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
if sys.version_info[0] != 3:
    from pysqlcipher import dbapi2 as sqlcipher
else:
    from pysqlcipher3 import dbapi2 as sqlcipher

sqlcipher.register_adapter(decimal.Decimal, str)
sqlcipher.register_adapter(datetime.date, str)
sqlcipher.register_adapter(datetime.time, str)


class _SqlCipherDatabase(object):
    def _connect(self):
        params = dict(self.connect_params)
        passphrase = params.pop('passphrase', '')
        kdf_iter = params.pop('kdf_iter', 64000)

        if len(passphrase) < 8:
            raise ImproperlyConfigured(
                'SqlCipherDatabase passphrase should be at least eight '
                'character long.')