Commit Graph

57 Commits

Author SHA1 Message Date
lufte 0c7b746a4e Restore the sql fixture to close DBs after testing 2021-07-09 01:10:36 -03:00
lufte 484ac43cf1 Fix function name too short 2021-07-03 01:00:32 -03:00
lufte 9949b4c5d6 No need to create new databases each time 2021-07-02 23:35:20 -03:00
lufte 082916b45d Add unit tests for the Transaction class 2021-07-02 23:25:59 -03:00
lufte 3b87db9059 Make version() a plain function 2021-06-30 01:13:54 -03:00
lufte 038d64b901 Update test_sql unit tests 2021-06-28 22:58:15 -03:00
Lembrun e8b05af233 Qtbot methods changed to snake case,snake case check added 2021-02-26 22:07:08 +01:00
Florian Bruhin 2b47bd01db Improve rebuilding of history database
- Re-add the force_rebuild key which we need internally again. This
partially reverts changes from:
  * cd0000f728
  * 1a9b59fcfa
  * 93ecd8f72f

- Instead of checking self.completion to figure out whether we need to
  rebuild anything, check 'self' (i.e. the History table, not the
  CompletionHistory table). If something went wrong during the last
  rebuild, the CompletionHistory might still be empty, but History is what
  actually matters to figure out whether to rebuild.

- Set force_rebuild while rebuilding the history, so that a possible
  interruption of the process (e.g. by a killed process or crash)
  results in another rebuild from scratch.

- Bump up the user version again, so that we re-add force_rebuild to the
  database. This also forces another rebuild which helps with possible
  inconsistent data when someone interrupted the earlier rebuild for
  v2.0.0.

Fixes #6111
2021-02-03 18:30:50 +01:00
Florian Bruhin 1a4fff1a42 doc: Switch URLs to https 2021-01-26 15:19:01 +01:00
Florian Bruhin 222f1f19a1 Bump copyright years
Closes #6015
2021-01-20 20:06:19 +01:00
Florian Bruhin fb5e105c19 sql: Remove .delete(like=True)
Mostly reverts bdab7b35b6 as we didn't end
up using it in b2fcc270ec.
2021-01-14 11:55:34 +01:00
Florian Bruhin 84ad7c990b sql: Improve/fix rows_affected() tests 2021-01-14 11:53:09 +01:00
Florian Bruhin 4d893e75a1 sql: Add Query.__bool__
Makes it clearer what the intent is (rather than implicitly falling back
on __len__ via Python) and also happens to be a small (most probably
insignificant) performance improvement.

On my machine, without a __bool__:

  Name (time in us)            Min       Max    Median
  test_bool_benchmark     144.2940  879.5960  167.2730

With it:

  Name (time in us)            Min       Max    Median
  test_bool_benchmark     133.3990  876.1080  152.1879
2021-01-14 11:24:31 +01:00
Florian Bruhin 0e4b807beb sql: Fix test 2021-01-14 10:58:06 +01:00
Florian Bruhin fcfa069a06 sql: Add major/minor user version infra
Not used at the moment, but allows for future changes.
2021-01-05 18:32:57 +01:00
Florian Bruhin bdab7b35b6 sql: Add .delete(..., like=True) 2021-01-05 18:32:57 +01:00
Florian Bruhin cd0000f728 history: Remove old force_rebuild values 2021-01-02 17:09:44 +01:00
Florian Bruhin ada468a8d7 old qt: Drop SQL error workaround 2020-11-04 18:30:04 +01:00
Florian Bruhin 9e4276db9b Adjust copyrights for 2020 2020-01-04 18:21:17 +01:00
Florian Bruhin 217cfb519e Remove Sql prefix for SqlKnownError and SqlBugError
We already have the sql module as namespace, no need to repeat it.
2019-04-03 10:34:37 +02:00
Florian Bruhin 03af6bb9b8 Finish environmental -> known rename 2019-04-03 10:31:24 +02:00
Jay Kamat 32802651da
Refactor LongQueryError and EnvironmentError into KnownError
- Also generalize catch on histcategory sql query to fix #4687
2019-04-02 21:35:32 -07:00
Jay Kamat 3e816f5f8b
Update copyright for 2019 2019-02-22 21:45:08 -08:00
Florian Bruhin 3b8964183e Use caplog.messages 2018-10-24 10:57:17 +02:00
Florian Bruhin 91b8002dd5 Clean up workaround for sqlite opening errors
Now that we know the real cause, we can be a bit stricter with our workaround.
2018-09-12 16:06:57 +02:00
Florian Bruhin c2a072f9fe Fix handling of sqlite out of memory errors
The "error_code == -1" check never passed, as error_code (confusingly) is a
string of a number.
2018-09-12 01:36:50 +02:00
Florian Bruhin 37396d68f3 Define names for sqlite error codes 2018-09-01 22:25:22 +02:00
Florian Bruhin f5c92ded41 Merge Sql{Environment,Bug}Error with Sqlite{Environment,Bug}Error 2018-09-01 22:25:22 +02:00
Florian Bruhin 50ae2bf2f9 Redesign SQL error handling
Instead of having an environmental attribute on exceptions, we now have two
different exception classes.

Fixes #3341
See #3073
2018-09-01 22:25:22 +02:00
Florian Bruhin 3f2a468750 Also detect missing bound values for sql.Query.run_batch 2018-09-01 18:25:58 +02:00
Florian Bruhin fa1fe63a93 Add some more sql.Query tests 2018-09-01 18:25:58 +02:00
Florian Bruhin 0e284944e7 Use composition instead of inheritance for sql.Query
This means we're more loosely coupled to Qt's QSqlQuery, and also can move some
logic for handling batch queries from the table to there.
2018-09-01 18:25:58 +02:00
Florian Bruhin 6b719fb218 Make sure queries don't have any missing bindings 2018-09-01 18:25:58 +02:00
Florian Bruhin 1d6282fd6c Add some tests for sql.Query 2018-09-01 18:25:58 +02:00
Florian Bruhin 6f028e9ad0 Update copyright years 2018-02-05 12:19:50 +01:00
Florian Bruhin e65c0dd8a7 pylint: Re-enable bad-continuation
And lots and lots of whitespace changes.
2017-12-15 19:16:55 +01:00
Florian Bruhin e76732693c Fix wrong import order 2017-12-15 14:35:07 +01:00
Florian Bruhin 96bec9f9d7 Fix error code for "database is locked"
See #2930
2017-10-17 15:35:23 +02:00
Florian Bruhin b5777299fd Fix getting a short text from the SqlError 2017-10-09 16:08:56 +02:00
Florian Bruhin b608259751 Handle some sqlite errors gracefully
We mark some SQL errors as "environmental", and then show those as error
messages instead of raising an exception.

Fixes #3004
Workaround for #2930
2017-10-09 16:06:24 +02:00
Florian Bruhin 5af8a95c82 Refactor SQL error handling
This renames SqlException to SqlError (to be more consistent with how Python
names exceptions), and adds an utility function which logs a few more useful
details about errors.

See #3004
2017-10-02 09:48:15 +02:00
Ryan Roden-Corrent c007f592b3 Use more intuitive argument order in sql.delete. 2017-06-29 20:43:42 -04:00
Ryan Roden-Corrent 891a6bcf14 Fix flake8 errors 2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent 4e87773d89 Use a dict instead of named params for insert.
This allows replace to be a named parameter and allows consolidating
some duplicate code between various insert methods.

This also fixes some tests that broke because batch insert was broken.
2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent 22b7b21d5a Use named placeholders for sql queries. 2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent 478a719f77 Use a prepared query for historyContains.
This is called often, hopefully a prepared query will speed it up.
This also modifies Query.run to return self for easier chaining, so you
can use `query.run.value()` instead of `query.run` ; query.value()`.
2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent 20000088de Add debug-dump-history and fix sql history tests.
Trying to read from the sql database from another process was flaky.
This adds a debug-dump-history command which is used by the history BDD
tests to validate the history contents.

It outputs history in the old pre-SQL text format, so it might be
useful for those who want to manipulate their history as text.
2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent f110cf4d53 Fix long hang after importing history.
Turns out historyContains was getting called for the webkit backend multiple
times when the browser starts. This was calling `url in history`, which was
enumerating the entire history as `__contains__` was not defined.
2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent 8ff45331df Clean up sql implementation.
Now that sql is only used for history (not quickmarks/bookmarks) a number of
functions are no longer needed. In addition, primary key support was removed as
we actually need to support multiple entries for the same url with different
access times. The completion model will have to handle this by selecting
something like (url, title, max(atime)).

This also fixes up a number of tests that were broken with the last few
sql-related commits.
2017-06-19 07:44:11 -04:00
Ryan Roden-Corrent de5be0dc5a Store history in an on-disk sqlite database.
Instead of reading sqlite history from a file and storing it in an in-memory
database, just directly use an on-disk database. This resolves #755, where
history entries don't pop in to the completion menu immediately as they are
still being read asynchronously for a few seconds after the browser starts.
2017-06-19 07:44:11 -04:00