Пример #1
0
def execute_sqlite3(path, cmds):
    """Execute 'cmds' on SQLite database 'path'"""
    import sqlite3
    conn = sqlite3.connect(path)
    cursor = conn.cursor()

    # overwrites deleted content with zeros
    # https://www.sqlite.org/pragma.html#pragma_secure_delete
    from bleachbit.Options import options
    if options.get('shred'):
        cursor.execute('PRAGMA secure_delete=ON')

    for cmd in cmds.split(';'):
        try:
            cursor.execute(cmd)
        except sqlite3.DatabaseError as exc:
            raise sqlite3.DatabaseError(
                '%s: %s' % (bleachbit.decode_str(exc), path))
        except sqlite3.OperationalError as exc:
            if exc.message.find('no such function: ') >= 0:
                # fixme: determine why randomblob and zeroblob are not
                # available
                logger.exception(exc.message)
            else:
                raise sqlite3.OperationalError(
                    '%s: %s' % (bleachbit.decode_str(exc), path))
    cursor.close()
    conn.commit()
    conn.close()
Пример #2
0
def execute_sqlite3(path, cmds):
    """Execute 'cmds' on SQLite database 'path'"""
    import sqlite3
    conn = sqlite3.connect(path)
    cursor = conn.cursor()

    # overwrites deleted content with zeros
    # https://www.sqlite.org/pragma.html#pragma_secure_delete
    from bleachbit.Options import options
    if options.get('shred'):
        cursor.execute('PRAGMA secure_delete=ON')

    for cmd in cmds.split(';'):
        try:
            cursor.execute(cmd)
        except sqlite3.OperationalError as exc:
            if exc.message.find('no such function: ') >= 0:
                # fixme: determine why randomblob and zeroblob are not
                # available
                logger.exception(exc.message)
            else:
                raise sqlite3.OperationalError(
                    '%s: %s' % (bleachbit.decode_str(exc), path))
        except sqlite3.DatabaseError as exc:
            raise sqlite3.DatabaseError('%s: %s' %
                                        (bleachbit.decode_str(exc), path))
    cursor.close()
    conn.commit()
    conn.close()