Python sqlite3.register_adapter() Examples

The following are 30 code examples of sqlite3.register_adapter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlite3 , or try the search function .
Example #1
Source File: sqlite.py    From attention-lvcsr with MIT License 6 votes vote down vote up
def __init__(self, database=None, **kwargs):
        if database is None:
            database = config.sqlite_database
        self.database = database
        self.conn = sqlite3.connect(database)
        sqlite3.register_adapter(numpy.ndarray, adapt_ndarray)
        with self.conn:
            self.conn.execute("""CREATE TABLE IF NOT EXISTS entries (
                                   uuid TEXT NOT NULL,
                                   time INT NOT NULL,
                                   "key" TEXT NOT NULL,
                                   value,
                                   PRIMARY KEY(uuid, time, "key")
                                 );""")
            self.conn.execute("""CREATE TABLE IF NOT EXISTS status (
                                   uuid TEXT NOT NULL,
                                   "key" text NOT NULL,
                                   value,
                                   PRIMARY KEY(uuid, "key")
                                 );""")
        self.status = SQLiteStatus(self)
        super(SQLiteLog, self).__init__(**kwargs) 
Example #2
Source File: source.py    From script.tvguide.fullscreen with GNU General Public License v2.0 6 votes vote down vote up
def _updateProgramList(self, programList, channel):
        # todo workaround service.py 'forgets' the adapter and convert set in _initialize.. wtf?!
        sqlite3.register_adapter(datetime.datetime, self.adapt_datetime)
        sqlite3.register_converter('timestamp', self.convert_datetime)

        c = self.conn.cursor()
        c.execute('DELETE FROM programs WHERE source=? AND channel=? ', [self.source.KEY, channel.id])
        updatesId = 1 #TODO why?
        for program in programList:
            c.execute(
                'INSERT OR REPLACE INTO programs(channel, title, sub_title, start_date, end_date, description, categories, image_large, image_small, season, episode, is_new, is_movie, language, source, updates_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
                [channel.id, program.title, program.sub_title, program.startDate, program.endDate, program.description, program.categories,
                 program.imageLarge, program.imageSmall, program.season, program.episode, program.is_new, program.is_movie,
                 program.language, self.source.KEY, updatesId])

        self.conn.commit() 
Example #3
Source File: types.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #4
Source File: regression.py    From Imogen with MIT License 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #5
Source File: types.py    From Imogen with MIT License 5 votes vote down vote up
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() 
Example #6
Source File: regression.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #7
Source File: types.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
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() 
Example #8
Source File: regression.py    From datafari with Apache License 2.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #9
Source File: types.py    From datafari with Apache License 2.0 5 votes vote down vote up
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() 
Example #10
Source File: sql.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        # GH 8341
        # register an adapter callable for datetime.time object
        import sqlite3
        # this will transform time(12,34,56,789) into '12:34:56.000789'
        # (this is what sqlalchemy does)
        sqlite3.register_adapter(time, lambda _: _.strftime("%H:%M:%S.%f"))
        super(SQLiteTable, self).__init__(*args, **kwargs) 
Example #11
Source File: regression.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #12
Source File: regression.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #13
Source File: sql.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        # GH 8341
        # register an adapter callable for datetime.time object
        import sqlite3
        # this will transform time(12,34,56,789) into '12:34:56.000789'
        # (this is what sqlalchemy does)
        sqlite3.register_adapter(time, lambda _: _.strftime("%H:%M:%S.%f"))
        super(SQLiteTable, self).__init__(*args, **kwargs) 
Example #14
Source File: dependency.py    From doit with MIT License 5 votes vote down vote up
def _sqlite3(self, name):
        """Open/create a sqlite3 DB file"""

        # Import sqlite here so it's only imported when required
        import sqlite3
        def dict_factory(cursor, row):
            """convert row to dict"""
            data = {}
            for idx, col in enumerate(cursor.description):
                data[col[0]] = row[idx]
            return data
        def converter(data):
            return self.codec.decode(data.decode('utf-8'))

        sqlite3.register_adapter(list, self.codec.encode)
        sqlite3.register_adapter(dict, self.codec.encode)
        sqlite3.register_converter("json", converter)
        conn = sqlite3.connect(
            name,
            detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES,
            isolation_level='DEFERRED')
        conn.row_factory = dict_factory
        sqlscript = """
            create table if not exists doit (
                task_id text not null primary key,
                task_data json
            );"""
        try:
            conn.execute(sqlscript)
        except sqlite3.DatabaseError as exception:
            new_message = (
                'Dependencies file in %(filename)s seems to use '
                'an bad format or is corrupted.\n'
                'To fix the issue you can just remove the database file(s) '
                'and a new one will be generated.'
                'Original error: %(msg)s'
                % {'filename': repr(name), 'msg': str(exception)})
            raise DatabaseException(new_message)
        return conn 
Example #15
Source File: regression.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #16
Source File: types.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #17
Source File: sqlite_util.py    From aq with MIT License 5 votes vote down vote up
def connect(path):
    sqlite3.register_adapter(dict, jsonify)
    sqlite3.register_adapter(list, jsonify)
    db = sqlite3.connect(path)
    db.create_function('json_get', 2, json_get)
    return db 
Example #18
Source File: db_manager.py    From EyeWitness with GNU General Public License v3.0 5 votes vote down vote up
def initialize_db(self):
        c = self.connection.cursor()
        sqlite3.register_adapter(bool, int)
        sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v)))
        c.execute('''CREATE TABLE opts
             (object blob)''')
        c.execute('''CREATE TABLE http
            (id integer primary key, object blob, complete boolean)''')
        c.execute('''CREATE TABLE rdpvnc
            (id integer primary key, object blob, complete boolean)''')
        c.execute('''CREATE TABLE ua
            (id integer primary key, parent_id integer, object blob,
                complete boolean, key text)''')
        self.connection.commit()
        c.close() 
Example #19
Source File: regression.py    From android_universal with MIT License 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #20
Source File: types.py    From android_universal with MIT License 5 votes vote down vote up
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() 
Example #21
Source File: regression.py    From BinderFilter with MIT License 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #22
Source File: rmDatabase.py    From rainmachine-developer-resources with GNU General Public License v3.0 5 votes vote down vote up
def registerAdapter(self, type, callable):
        sqlite3.register_adapter(type, callable) 
Example #23
Source File: source.py    From script.tvguide.fullscreen with GNU General Public License v2.0 5 votes vote down vote up
def _invokeAndBlockForResult(self, method, *args):
        sqlite3.register_adapter(datetime.datetime, self.adapt_datetime)
        sqlite3.register_converter('timestamp', self.convert_datetime)
        event = [method, None]
        event.extend(args)
        self.eventQueue.append(event)
        self.event.set()
        while not method.__name__ in self.eventResults:
            time.sleep(0.1)
        result = self.eventResults.get(method.__name__)
        del self.eventResults[method.__name__]
        return result 
Example #24
Source File: regression.py    From vsphere-storage-for-docker with Apache License 2.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #25
Source File: types.py    From vsphere-storage-for-docker with Apache License 2.0 5 votes vote down vote up
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() 
Example #26
Source File: regression.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CheckRegisterAdapter(self):
        """
        See issue 3312.
        """
        self.assertRaises(TypeError, sqlite.register_adapter, {}, None) 
Example #27
Source File: types.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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() 
Example #28
Source File: sql.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        # GH 8341
        # register an adapter callable for datetime.time object
        import sqlite3
        # this will transform time(12,34,56,789) into '12:34:56.000789'
        # (this is what sqlalchemy does)
        sqlite3.register_adapter(time, lambda _: _.strftime("%H:%M:%S.%f"))
        super(SQLiteTable, self).__init__(*args, **kwargs) 
Example #29
Source File: types.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #30
Source File: types.py    From BinderFilter with MIT License 5 votes vote down vote up
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()