# Buggy code
def insert_batch(self, values, replace=False):
    """Performantly append multiple rows to the table.

    Args:
        values: A dict with a list of values to insert for each field name.
        replace: If true, overwrite rows with a primary key match.
    """
    q = self._insert_query(values, replace)
    for key, val in values.items():
        q.bindValue(":{}".format(key), val)

    db = QSqlDatabase.database()
    db.transaction()
    if not q.execBatch():
        _handle_query_error("exec", q.lastQuery(), q.lastError())
    db.commit()
    self.changed.emit()


# Traceback (qutebrowser.misc.sql.SqlException)
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:Privacy_policy'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000158 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:About'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000111 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:General_disclaimer'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 9.4e-05 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php?title=Tor&amp;mobileaction=toggle_view_mobile'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000114 seconds.
20:42:34 DEBUG    sql        sql:__init__:80 Preparing SQL query: "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)"
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':atime': 1501461754, ':redirect': False, ':title': 'Tor - ArchWiki', ':url': 'https://wiki.archlinux.org/index.php/Tor#Usage'}
20:42:34 ERROR    misc       crashsignal:exception_hook:210 Uncaught exception
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/history.py", line 144, in add_from_tab
self.add_url(url, title)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/history.py", line 166, in add_url
'redirect': redirect})
File "/usr/lib/python3.6/site-packages/qutebrowser/misc/sql.py", line 214, in insert
q.run(**values)
File "/usr/lib/python3.6/site-packages/qutebrowser/misc/sql.py", line 105, in run
self.lastQuery(), self.lastError().text()))
qutebrowser.misc.sql.SqlException: Failed to exec query "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)": "database is locked Unable to fetch row"

# Fixed code
def insert_batch(self, values, replace=False):
    """Performantly append multiple rows to the table.

    Args:
        values: A dict with a list of values to insert for each field name.
        replace: If true, overwrite rows with a primary key match.
    """
    q = self._insert_query(values, replace)
    for key, val in values.items():
        q.bindValue(":{}".format(key), val)

    db = QSqlDatabase.database()
    db.transaction()
    if not q.execBatch():
        raise SqliteError.from_query("exec", q.lastQuery(), q.lastError())
    db.commit()
    self.changed.emit()