Show error dialog is sql isn't available.
If creating the sql database fails, show an error dialog assuming sqlite is not installed. This removes the isDriverAvailable check as it was true even with sqlite uninstalled. sql.version now inits itself if sql is not already initialized and prints 'UNAVAILABLE (<error message>)' if init fails. This is to avoid cascading errors, where one error would create a crash dialog, which calls sql.version, which would create another error.
This commit is contained in:
parent
dc4472470e
commit
cee0aa3adc
@ -85,7 +85,6 @@ def run(args):
|
|||||||
if args.version:
|
if args.version:
|
||||||
# we need to init sql to print the sql version
|
# we need to init sql to print the sql version
|
||||||
# we can use an in-memory database as we just want to query the version
|
# we can use an in-memory database as we just want to query the version
|
||||||
sql.init(':memory:')
|
|
||||||
print(version.version())
|
print(version.version())
|
||||||
sys.exit(usertypes.Exit.ok)
|
sys.exit(usertypes.Exit.ok)
|
||||||
|
|
||||||
@ -429,7 +428,12 @@ def _init_modules(args, crash_handler):
|
|||||||
keyconf.init(qApp)
|
keyconf.init(qApp)
|
||||||
|
|
||||||
log.init.debug("Initializing sql...")
|
log.init.debug("Initializing sql...")
|
||||||
sql.init(os.path.join(standarddir.data(), 'history.sqlite'))
|
try:
|
||||||
|
sql.init(os.path.join(standarddir.data(), 'history.sqlite'))
|
||||||
|
except sql.SqlException as e:
|
||||||
|
error.handle_fatal_exc(e, args, 'Is sqlite installed?',
|
||||||
|
pre_text='Failed to initialize SQL')
|
||||||
|
sys.exit(usertypes.Exit.err_init)
|
||||||
|
|
||||||
log.init.debug("Initializing web history...")
|
log.init.debug("Initializing web history...")
|
||||||
history.init(qApp)
|
history.init(qApp)
|
||||||
|
@ -396,12 +396,6 @@ def check_optimize_flag():
|
|||||||
"unexpected behavior may occur.")
|
"unexpected behavior may occur.")
|
||||||
|
|
||||||
|
|
||||||
def check_sqlite():
|
|
||||||
from PyQt5.QtSql import QSqlDatabase
|
|
||||||
if not QSqlDatabase.isDriverAvailable('QSQLITE'):
|
|
||||||
_die('sqlite driver not available! Is sqlite installed?')
|
|
||||||
|
|
||||||
|
|
||||||
def set_backend(backend):
|
def set_backend(backend):
|
||||||
"""Set the objects.backend global to the given backend (as string)."""
|
"""Set the objects.backend global to the given backend (as string)."""
|
||||||
from qutebrowser.misc import objects
|
from qutebrowser.misc import objects
|
||||||
@ -441,5 +435,4 @@ def earlyinit(args):
|
|||||||
check_libraries(backend)
|
check_libraries(backend)
|
||||||
check_ssl_support(backend)
|
check_ssl_support(backend)
|
||||||
check_optimize_flag()
|
check_optimize_flag()
|
||||||
check_sqlite()
|
|
||||||
set_backend(backend)
|
set_backend(backend)
|
||||||
|
@ -37,6 +37,8 @@ class SqlException(Exception):
|
|||||||
def init(db_path):
|
def init(db_path):
|
||||||
"""Initialize the SQL database connection."""
|
"""Initialize the SQL database connection."""
|
||||||
database = QSqlDatabase.addDatabase('QSQLITE')
|
database = QSqlDatabase.addDatabase('QSQLITE')
|
||||||
|
if not database.isValid():
|
||||||
|
raise SqlException('Failed to add database. Is sqlite installed?')
|
||||||
database.setDatabaseName(db_path)
|
database.setDatabaseName(db_path)
|
||||||
if not database.open():
|
if not database.open():
|
||||||
raise SqlException("Failed to open sqlite database at {}: {}"
|
raise SqlException("Failed to open sqlite database at {}: {}"
|
||||||
@ -50,9 +52,15 @@ def close():
|
|||||||
|
|
||||||
def version():
|
def version():
|
||||||
"""Return the sqlite version string."""
|
"""Return the sqlite version string."""
|
||||||
q = Query("select sqlite_version()")
|
try:
|
||||||
q.run()
|
if not QSqlDatabase.database().isOpen():
|
||||||
return q.value()
|
init(':memory:')
|
||||||
|
ver = Query("select sqlite_version()").run().value()
|
||||||
|
close()
|
||||||
|
return ver
|
||||||
|
return Query("select sqlite_version()").run().value()
|
||||||
|
except SqlException as e:
|
||||||
|
return 'UNAVAILABLE ({})'.format(e)
|
||||||
|
|
||||||
|
|
||||||
class Query(QSqlQuery):
|
class Query(QSqlQuery):
|
||||||
|
Loading…
Reference in New Issue
Block a user