Commit Graph

546 Commits

Author SHA1 Message Date
Martin Kleusberg
37a5645bf5 Fix some shadow warnings 2018-11-15 15:24:00 +01:00
Martin Kleusberg
c91009c7f3 Fix old-style-cast warnings 2018-11-15 15:11:09 +01:00
Martin Kleusberg
5a606fd194 Fix bug introduced in f1e01dde8c
Thanks to @mgrojo for pointing this out in #1606.
2018-11-15 14:32:23 +01:00
Martin Kleusberg
a393bbf25d Improve read only project file loading
This slightly changes the behaviour regarding the read-only mode in
project files. It makes sure that we always respect the user's choice to
open a file in read-only mode, even if the project file says it wasn't
opened in read-only mode before.
2018-11-08 16:59:08 +01:00
Martin Kleusberg
a8338406c9 Save read-only state in project file
When opening a database in read-only mode and creating a project file,
save the read-only flag in the project file.

When loading a project file with a read only flag set, open the database
in read-only mode.

See issue #1598.
2018-11-08 16:55:52 +01:00
Martin Kleusberg
a81ea2b983 Fix possible warnings
See issue #1603.
2018-11-08 16:55:51 +01:00
Martin Kleusberg
11ace1efa6 Show current database action in status bar and add cancel button
This adds a label to the status bar which becomes visible whenever the
database is busy. It also specifies the currently running action. Also
add a button which allows you to cancel this action at the next
opportunity.

Note that this doesn't work for the Execute SQL tab yet which requires
some more rewriting of the code there.
2018-11-08 16:52:38 +01:00
Martin Kleusberg
f1e01dde8c Use new Query class from outside SqliteTableModel to assemble queries 2018-11-08 16:20:34 +01:00
Manuel
23f7346f78 Avoid setting the db dirty with some trailing whitespace and comments (#1543)
If we execute a select statement and there is some trailing whitespace or
comments in the buffer, we are passing that to SQLite and fooling
ourselves thinking that it may be a query modifying the database. Since
we aren't very smart about knowing which queries modify the database, this
change at least avoids this particular case by breaking when there is only
trailing whitespace and comments.

The issue has probably origin in #1455, since previously we didn't pass
the comments to SQLite.
2018-10-30 22:01:21 +01:00
Martin Kleusberg
1da7ca8d43 Change project file format to support multiple sort columns (#1593)
This commit changes the project file format (and some internal data
structures) to support multiple sort columns in the Browse Data tab.
Note that this does not add actual support for multiple sort columns,
it's just a preparation for that.
2018-10-30 21:47:55 +01:00
Manuel
abb6f686a3 Initial implementation of "conditional formatting" (#1503)
After setting a filter, the user can select from the context menu in the
filter line a new option "Use for Conditional Format", that assigns
automatically a colour to the background of cells fulfilling that
condition.

The formatting is preserved after the user has removed the filter. Several
conditional formats can be successively added to a column using different
filters.

The conditional formats of a column can be cleared when the filter is empty
selecting "Clear All Conditional Formats" from the filter line context
menu.

The conditional formats are saved and loaded in project files as other
browse table settings.

A new class Palette has been added for reusing the automatic colour
assignment of the Plot Dock. It takes into account the theme kind of the
application (dark, light) for the colour selection.

A new class CondFormat for using the conditional formatting settings from
several classes. The conversion of a filter string from our format to an
SQL condition has been moved here for reuse in filters and conditional
formatting.

Whether the conditional format applies is resolved by SQLite, so filters
and conditional formats give the same exact results.

Code for getting a pragma value has been reused for getting the condition
result, and consequently renamed to selectSingleCell.

Possible future improvement:
- New dialog for editing the conditional formatting (at least colour and
application order of conditions, but maybe too: adding new conditions and
editing the condition itself).
2018-10-30 21:22:14 +01:00
Iulian Onofrei
d526fa0b64 Add last location saving and loading per action type (#1587)
* Fixed code style

* Added last location saving and loading per action type

This saves and loads different paths per action type when presenting the
native file dialog popup.
2018-10-27 22:24:01 +02:00
Manuel
eab31b69ee Unlock view status was lost after switching view or refresh (#1565)
This solves these two problems that seem to have being introduced in
d5a049062d

- The unlocked-view status was not applied again when switching back to the
view (you cannot edit and the Delete Record button is not reenabled) or
after refreshing.

- The 'Unlock view editing' check state persisted when switching between
views.

See issue #141.
2018-10-19 22:04:08 +02:00
Manuel
16ba6db2dc Problems with WITHOUT ROWID tables with PK of string type (#1559)
* Problems with WITHOUT ROWID tables with PK of string type

This fixes two related problems:
- When the PK is updated the hidden column 0 must be updated too,
  otherwise any further editing of the same row before a table refresh is
  broken.
- When a new record is inserted and the PK has string type we cannot
  simply make a pseudo auto-increment and insert that value as rowid
  because that added key would be impossible to update because our
  UPDATE clause will try to update a column with a string and it contains
  an integer. In this case it's better to let the user enter the PK value,
  so the new Add Record dialog is directly invoked.

See issue #1332 and (tangentially) #1049. The first should be fixed now.
The later not, but at least there is now a workaround: removing the
AUTOINCREMENT option and use the WITHOUT ROWID one.

* Problems with WITHOUT ROWID tables with PK of string type (alternative 2)

Update after review:

- cached_row is not modified after unlock();

- Alternative solution to initial key value insertion:
  When a new record is inserted and the PK has string type we still make a
  pseudo auto-increment and insert that value as a string literal. In this
  way we can later update that row. When we inserted it as integer an
  actual integer will be inserted by SQLite, and our UPDATE clause, which
  always uses string in the WHERE condition, won't match the row (SQLite
  does not convert to integer when the column is of type string in this
  context).

See issue #1332.
2018-10-09 22:37:27 +02:00
mgr
fd0b34265c Printing support #1525: pre-formatted, wrapped output of Schema column
The schema column of objects is pre-formatted with wrapped style. In this
way, if the "db.hideschemalinebreaks" setting is enabled, the printed
output is formatted in the same way, but with a wrapping style, so long
lines do not extend the Schema column too much.

Added tooltip to Preferences dialog, so it isn't a so hidden feature.
Translations updated accordingly for the release.

The header style is not applied in that same case.
2018-10-03 21:40:44 +02:00
mgrojo
c78c03bf0b Avoid unnecessary queries when populating filtered table
When a table is filtered and the browsed tabled is changed and then we
return to this filtered table, the table view shows several incorrect
disabled rows. The same may happen when refreshing this table. This seems
to be produced by a (yet unsolved) concurrency problem triggered by
several consecutive queries, that are signalled by setting the text of
the stored filters in the table header filter.

These unnecessary queries are avoided by setting the stored filter values
at the same time as the table in the SQL table model, making sure that
no intermediate queries are executed while the filters are set.

This seems to work around the concurrency problem and the symptom of the
invalid rows does not appear in those situations.
2018-10-03 15:42:49 +02:00
mgr
8b656cdeaa Printing support #1525: add print button to Data Browse tab
For consistency for the other application tabs, a print button is added
to the Data Browse Tab for printing the currently browsed table or
selection of cells.
2018-10-01 23:07:17 +02:00
mgr
f42b614084 A bit of polishing of the main window user-interface
Reorder the context menu of the table header and use separators for
coherent grouping: column actions, misc and encoding.

Set buttons invisible in the DB Structure toolbar when the object is
different to the supported ones. Disabling wasn't enough because the logic
for changing icon and text wasn't working well for fields and other items.

Separate Print from object actions in that same toolbar.

New icon for Project Save so it uses the same metaphor (floppy disk) as
other save actions.

Improved the look in the clear filters icon by editing it in gimp. It had
a glitch in the funnel base.
2018-09-29 17:28:12 +02:00
mgr
071f963fcc Better messages for a table edition when foreign-key check detect problems
The message when there are problems and the user has made changes and
accepted them must be different to the case when the user has cancelled
and any possible changes have been already reverted by the dialog.

In the first case the fault may be ours and we actually revert changes.
In the second case, we know for sure the problems were there before
editing the table. We warn user about it, since we already know.

The last error from the DB is inappropriate for both cases because it
hasn't been updated by the foreign-key check.

Also fixed the typo in a function identifier.

Room for improvement: maybe the check should be done before opening the
dialog, so we don't let the user edit the table until the issues have
been solved.

See issue #1547
2018-09-29 16:22:03 +02:00
Martin Kleusberg
f4867e5c6d Remove unused code
Since we replaced the project file format by a pure XML representation
we don't need this function anymore.
2018-09-28 18:42:34 +02:00
mgr
903e66485c Simplify the URL for a feature request
As suggested by @karim at #1497, the template in GitHub can be reused if
set as parameter. Then we can discard the long body parameter and have
a single definition of the Feature Request template text.
2018-09-27 23:43:30 +02:00
Martin Kleusberg
320c71eed8 Save and load attached databases to/from the project file
We were already saving information on tables, etc. of attached
databases, so it only makes sense to save the path and name of the
databases as well.

See issue #1532.
2018-09-27 22:04:28 +02:00
Martin Kleusberg
717ff075b5 Avoid some possible crashes
This adds some extra sanity checks in the code to avoid possible
crashes. The most likely way to trigger them is loading an outdated
project file which references tables that no longer exist.
2018-09-27 21:36:11 +02:00
mgr
54cf4cf140 Printing support #1525: add print preview dialog
This adds a print preview step before printing in the Database Structure
tab.

This is nice to have, but it also aims to work around the problem found in
Windows, reported at issue #760.
2018-09-27 21:06:59 +02:00
mgr
4f0d3505ed Printing support #1525: print DB structure
New action and button for printing the database structure.

The data in the Database Structure tree widget is converted to HTML and set
in a document that can then be printed, opening the dialog as done for
other components.
2018-09-25 23:00:17 +02:00
mgr
99c53a436e Fix positioning issues with multibyte characters in SQL executions
QScintilla counts characters for the index inside a line and number of
bytes for the global positions. When we use index we have to use text
lengths (number of characters) and when we use global position, we have to
convert previously to byte arrays. Otherwise offsets are produced in
executions containing non US-ASCII characters (accented letters, most
symbols, etc).

The bug could lead to final statements not executed by the execute-all
action, more than one line executed by the execute line action and
incorrect line references in the log.
2018-09-22 17:49:45 +02:00
mgr
18f0ef60ba Enhancement #1435: pragmas invoked from Tools menu
Pragmas integrity_check, quick_check, foreign_key_check and optimize are
integrated in the Tools menu. The actions open a confirmation dialog
(with Help button that opens the corresponding reference page in
sqlite.org) and, after confirmation, opens a new SQL editor tab and runs
there the pragma, showing the possible results.

Sender in executeQuery is null in this case, so a check is added.

Added accelerator to Tools menu entry, which lacked one.
2018-09-16 18:54:25 +02:00
mgr
60c229c1c4 Printing support: print dialog from QScintilla widgets
Add printing support for QScintilla widgets (SQL, JSON and XML). It can be
access through the contextual menu, shortcut (Ctrl+P) or (in the case of
the "Execute SQL" tab) from a button in the toolbar.

Ctrl+P was previously assigned to Plot Dock since
63c338c359 but, as it was foreseen in that
commit, it should be assign to print is ever supported. This change must
be mentioned in release notes.

First part of printing support. See issue #1525.
2018-09-16 16:06:27 +02:00
mgrojo
5b4dea9b7c Add "Feature Request..." entry and body templates in both types of issue
New entry under Help menu for requesting issues with the same template
used for a New Issue inside GitHub.

The "Bug Report..." entry has also been updated for adding the
corresponding template body.

Separators added in Help menu, since there are currently several different
options.

See related issue #1497
2018-09-10 22:17:02 +02:00
mgrojo
dfa599de44 Merge branch 'qualified_completion' 2018-09-10 21:03:29 +02:00
mgrojo
f33943f4cf Improvements for drag and drop of items from the DB Schema dock to editor
Two new options editable from a new context menu of the dock:
- Drag & Drop Qualified Names: add table name to fields and schema name
to other objects (except for "main" schema)
- Drag & Drop Enquoted Names: whether to surround the identifiers by the
configured quoting characters for identifiers.

Support for dragging & dropping of attached databases names.

Add "." as separator for multiple dropped objects other than fields (since
they are not usually used in SQL as a list). This allows to compose
qualified names by dropping the parent and the child items together. This
is only generally useful when the "Qualified Names" option is disabled.

See related issue #1433
2018-09-09 19:52:36 +02:00
mgrojo
2081af207b Cursor Doesn't Change After Importing Database SQL File #1526
restoreOverrideCursor() is called before asking the user to accept the
warning or information message.
2018-09-06 21:30:20 +02:00
mgrojo
d0b5ff10a7 Completion of qualified table names
This adds the schema names to the possible completions and adds support
for cascading completion of schema.table.field.

See related issue #1433
2018-09-05 23:03:47 +02:00
Martin Kleusberg
bf505edf66 Code refactoring
This commit refactors vast parts of the sqlitetypes.h interface. Its
main goals are: less code, easier code, a more modern interface, reduced
likelihood for strange errors and more flexibility for future
extensions.

The main reason why the sqlitetypes.h functions were working so well in
DB4S was not because they were that stable but because they were
extremely interlinked with the rest of the code. This is fine because we
do not plan to ship them as a separate library. But it makes it hard to
find the obvious spot to fix an issue or to put a new function. It can
always be done in the sqlitetypes function or in the rest of the DB4S
code because it is just not clear what the interface between the two
should look like. This is supposed to be improved by this commit. One
main thing here is to make ownership of objects a bit clearer.

In theory the new code should be faster too but that difference will be
neglectable from a user POV.

This commit also fixes a hidden bug which caused all table constraints
to be removed in the Edit Table dialog when a single field was removed
from the table.

This is all still WIP and more work is needed to be done here.
2018-09-05 22:24:46 +02:00
Martin Kleusberg
f3e6aec57d Load SQLite extensions earlier
In the Preferences dialog we allow the user to configure a list of
SQLite extensions which should be loaded whenever a new database file is
create or an existing database file is loaded. This commit changes the
order of actions after creating or opening a file so that the extensions
are loaded significantly earlier. This way they are already loaded for
most of the time during the process.

This fixes some subtle bugs. One of the more prominent ones was
triggered when there is a view which uses some function which is
defined in such an extension. After loading the file, parsing would fail
and you couldn't see the fields of the view. Browsing it would work but
trying to edit the display format crashed the application.
2018-09-04 22:06:12 +02:00
Martin Kleusberg
effb4e0ac6 Fix typo
Thanks to @mgrojo for spotting this before any user or any translator
could see it.
2018-08-28 23:07:00 +02:00
Martin Kleusberg
4a3273b359 Add some PRAGMA which are only connection persistent to the project file
The temp_store, wal_autocheckpoint and synchronous PRAGMAs are only
stored for the current database connection but not saved in the database
file. So to fully restore the working environment after closing a
database, this commit adds these three PRAGMAs to the project file
format.

See issue #1518.
2018-08-28 21:45:43 +02:00
Martin Kleusberg
049d4ba76f Fix foreign key check after editing a table
After editing a table we perform a foreign key check to see if the
modifications caused any problems. This check doesn't seem to work
because it expected that in case of a problem the PRAGMA would fail.
This however isn't the case - it just doesn't return any results but it
doesn't fail. This commit fixes the check and only shows rolls back if
the PRAGMA returned any data.
2018-08-28 21:17:14 +02:00
Martin Kleusberg
406734a2c9 Defer foreign keys during SQL import
When importing an SQL file, defer foreign keys until the import is
finished. This is necessary if there are foreign key constraints in the
imported table and the order of the INSERT statements doesn't match the
hierarchy of the constraints.

Also perform an integrity check at the end of the import.

See issue #1519.
2018-08-28 21:14:09 +02:00
Manuel
ce032d95e6 Issue #530: constraints on table prevents new record being added (#1477)
* Issue #530: constraints on table prevents new record being added

This adds a new dialog for adding records to a table. The current approach
is broken for several cases where foreign keys and check constraints are
impeding the insertion of an empty record. With the dialog, the user can
inspect the constraints (tooltip) and type of fields and add values
consistent with the requirements. The data is only inserted when the user
presses the Save button.

The dialog is modelled after the Edit Table or Edit Index dialog. An upper
frame allows entering the data using widgets. The lower frame previews the
SQL statement that will be used.

The old approach for adding records is still accessible pressing Tab on
the last cell of the table.

* Fix build problem introduced in previous commit on this branch

* Dialog as fallback for failure after empty row insertion and read only text

The insertion of an empty row is always tried. When it fails due to
constraints and foreign keys, the Add Record Dialog is open so the user
can enter values for the new record considering the constraints.

When the table has not constraints, or the row insertion provides valid
values, the user is still able to insert rows using the simple approach.

SQL preview in dialog is now read-only.

* Visual improvements for the Add Record dialog

QLineEdit as item delegate for the value, so it is more visible that we
are supposed to edit the value.

Remove last end-of-line in tool-tip.

* Improvements in the "Add Record" dialog

Display of NULL values using DisplayRole (no focus) or place holder text
(when focus).

Set value to NULL through a context menu and shortcut in the value line
edit.

Take text type affinity into account for quoting or not entered numbers.
New isType and affinity functions in sqlitetypes.

Clarify wording of constraints in tooltip for value. Added the same tooltip
for the type.

Escape quotes inside string values.

Removed unused parameters warnings.

Other wording or code improvements based on the pull-request review: #1477.

* User access to the Add Record dialog

The Add Record dialog is now accessible for the user. The New Record button
is converted to a QToolButton and a new pop-up menu is added to it for
invoking the in-line table insertion (New Record) or the Add Record dialog
(Insert Values...). What's This information for the button updated.
2018-08-27 21:35:09 +02:00
Martin Kleusberg
d5a049062d Fix crash when browsing a view
This was introduced by 2b6153d9b8.
2018-08-21 20:28:58 +02:00
Martin Kleusberg
c4109e6a10 Fix plot from disappearing when refreshing the view
The plot and all plot settings disappear when you click the Refresh
button in the Browse Data tab. This problem was introduced in the
multithreading patch.
2018-08-16 18:35:44 +02:00
Justin Clift
06363f8083 Retrieve the currentrelease file from our new download servers
In theory this should "just work", without any weirdness.  Only
one way to find out for sure though. :)
2018-08-13 01:18:16 +01:00
Martin Kleusberg
1a780ebddc Add menu item for our Patreon page
See issue #1425.
2018-08-12 22:25:02 +02:00
Martin Kleusberg
b219edbbfb Fix hidden columns being unhidden in Browse Data tab when sorting
This is required for Qt version < 5.10. For Qt versions >= 5.10 the
unhiding of all columns before rehiding the desired ones does nothing
because there the table view doesn't store its state anymore. And when
it does nothing we don't change the state of our view settings which in
turn triggers the mentioned problem.

See issue #1475.
2018-08-12 13:48:48 +02:00
Martin Kleusberg
060c406549 Include SQLite/SQLCipher and Qt version in bug report body 2018-08-10 19:18:00 +02:00
Martin Kleusberg
2b6153d9b8 Fix browse table settings not being reapplied correctly
We have already fixed the rowid column from appearing after almost every
action in the Browse Data tab, for example in commit
39302f5b60.

This didn't fix every issue related to this problem though. Hidden
columns are shown too and modified column widths are reset. Also this
happens for different actions, for example the column widths are also
reset when sorting the view or when changing the filters. All these
problems are hopefully fixed by this commit.

See issue #1475.
2018-08-10 13:52:39 +02:00
mgrojo
d3d9d10ecd Untranslatable message in SQL Log 2018-08-09 22:23:16 +02:00
Martin Kleusberg
8a07f0e655 Change page_size PRAGMA from spin box to combo box
Change the control of the page_size PRAGMA from a spin box to a combo
box in the Edit Pragma tab. This makes sure no values are entered which
aren't a power of two. The same change was done in the Cipher dialog a
while ago for the same reasons.
2018-08-09 14:39:34 +02:00
Martin Kleusberg
a23c0a0852 Fix PRAGMA view when loading a project file
When loading a project file which changes the foreign_keys or the
case_sensitive_like PRAGMAs while being in the Edit Pragma tab didn't
update the UI accordingly. Only after changing the tab and returning to
the Edit Pragma tab updated the controls.
2018-08-09 14:08:09 +02:00