Commit Graph

144 Commits

Author SHA1 Message Date
mgrojo
e4d57f741e Set SQL editor in Modify Table dialog as read-only programmatically
Otherwise the UI dynamic property does not seem to work, although it
use to and should. Please, improve it if a way to return to the correct
behaviour.

Fixes issue #2078
2020-01-06 00:53:25 +01:00
Martin Kleusberg
ba1270cedb Clean up the code and make some more minor optimisations
This also includes replacing some more Qt containers by their STL
counterparts.
2019-11-06 20:25:18 +01:00
Martin Kleusberg
5f21c23d43 Remove some unnecessary semicolons 2019-10-07 18:18:46 +02:00
Martin Kleusberg
b4c8ec9706 Fix editing of collation in new fiews in the Edit Table dialog
Setting a collation in a newly added field in the Edit Table dialog did
not work when the field name was edited just before. This is fixed now.

See issue #2011.
2019-09-26 16:48:21 +02:00
Martin Kleusberg
a69c62790f Fix foreign key editor not working correctly in Edit Table dialog
When creating a new foreign key constraint in the Edit Table dialog, a
list of tables to reference is displayed. This list is updated whenever
the name of the edited table changes because this is the only table the
name of which can change while the Edit Table dialog is opened. However,
this meant that when the name of the table changes to some existing
table name, the field list of that existing table is replaced by the
field list of the current table. If the name of the current table is
changed once again, it is deleted entirely from the list. This commit
fixes this behaviour by separating the static part of the table and
field list from the one table which can change.

See issue #1991.
2019-09-22 22:06:04 +02:00
Martin Kleusberg
91e036dd74 Add move field to top/bottom buttons to Edit Table dialog
See issue #1988.
2019-09-22 21:57:38 +02:00
Martin Kleusberg
3237e9d2f5 grammar: Rework how PK and unique constraints work
This commit changes the class hierarchy to make primary key constraints
a type of unique constraints. This fits nicely with reality because
primary key columns do not allow duplicate values. It also makes our
life easier as the other changes which are introduced here add some code
required by both unique and primary key constraints and which now can be
shared.

Move the auto increment flag from the field class to the primary key
class. This changes how auto increment fields work and look and might be
a bit unfamiliar but it simplifies things a lot for us because an auto
increment field is always a primary key. So before we had to maintain
two places: the field with the auto increment flag and the primary key
which belongs to it. Now it is all in one place in the primary key.

Add support for storing and manipulating sort order for columns in
primary key and unique constraints. It does not add support for them to
the grammar parser though.

Finally add a way to store and manipulate on conflict clauses for unique
and primary key constraints. Again, parser support for them is not added.
2019-09-11 15:09:23 +02:00
Martin Kleusberg
d9fbdb4bfc Fix collation combo box for newly added fields in Edit Table dialog
This fixes a regression which was introduced by the changes in Commit
0768ccd1db. The newly added combo box for
setting the collation of a field was not created for fields which were
newly added to the table. This broke the setting of the data type for
these fields.

See issue #1973.
2019-08-23 15:12:26 +02:00
Martin Kleusberg
0768ccd1db Add column for editing collations to Edit Table dialog
Add a new column to the field table of the Edit Table dialog which
allows you to set, remove, and modify the collation of each field. This
is done by showing a combo box which lists all currently available
collations.

See issue #1973.
2019-08-21 23:37:16 +02:00
Martin Kleusberg
a9e6fe4ecb Support adding custom constraints in Edit Table dialog
This adds support for adding custom constraint in the Edit Table dialog,
e.g. for adding multi-column unique constraints.
2019-08-10 13:18:18 +02:00
Martin Kleusberg
05e2defe33 Add possibility to change the type of table constraints in Edit Table
Enable the combo box in the Edit Table dialog to change the type of a
table constraint and add the code to try to transform a constraint from
one type into another as best as possible.
2019-07-28 22:33:36 +02:00
Martin Kleusberg
cb694dd2c6 grammar: Change the way the table constraints are stored
This changes the way we store the constraints associated with a table
from using a map to using a set. The map was mapping from the list of
field names to the constraint applied on these fields. Now the field
list is stored inside the constraint and we can store the constraints in
a simple set. This turns out to simplify the code noticeably.
2019-07-28 14:52:03 +02:00
Martin Kleusberg
9d654a19ba Support modifying the column list of a constraint in Edit Table dialog
This adds support for modifying the columns a constraint is applied on
in the Constraints tab of the Edit Table dialog. This is a major step
towards full constraint editing capabilities (adding new constraints,
modifying constraint type, and editing constraint type-dependent
parameters are the other missing pieces).

The reasoning behind the popup dialog is to not introduce another full
dialog on top of the Edit Table dialog. After opening the Edit Table
dialog, then switching to the Constraints tab, then opening another
modal dialog, I felt like losing track of what I am currently editing.
The popup dialog is certainly not great but feels a bit less intrusive.
Any suggestions regarding this are appreciated.
2019-07-27 18:26:01 +02:00
Martin Kleusberg
3f60142abc Support deleting table constraints in Edit Table dialog
This adds support for deleting table constraints in the Edit Table
dialog.
2019-07-27 12:36:46 +02:00
Martin Kleusberg
cd748d07ab Support changing constraint names in the Edit Table dialog
This adds support for changing the names of existing constraints in the
Edit Table dialog. It should be possible to extend the code to allow
further modifications of the constraints.

As a minor change, this commit makes the SQL column of the constraints
table read only.
2019-07-26 18:44:34 +02:00
Martin Kleusberg
64a596a887 Use even less Qt containers 2019-05-06 18:50:05 +02:00
Martin Kleusberg
b803e3c49f Use more STL containers instead of Qt containers 2019-05-02 17:02:59 +02:00
Martin Kleusberg
f821fbb1a8 Silence a couple of warnings 2019-04-29 19:14:10 +02:00
Martin Kleusberg
15c23bb0d3 Use some more SQL containers instead of their Qt equivalents 2019-04-29 18:11:19 +02:00
Martin Kleusberg
f59a2453a2 Fix some warning and other code style changes 2019-04-26 14:48:24 +02:00
Martin Kleusberg
ad60a019f2 Show constraints in Edit Table dialog
Add a new tab to the Edit Table dialog to show a list of all table
constraints. Before this, some of them were visible in the field list
but others were not shown at all. This new view is still rather basic
and currently read-only but will be improved over time.
2019-04-26 12:30:59 +02:00
Martin Kleusberg
fcac61da64 Simplify the WITHOUT ROWID code a bit
In the Table class we need to store whether this is a WITHOUT ROWID
table or now. Instead of just storing a boolean flag for that we were
storing a list of the rowid column(s). This is not just more complicated
to handle than a simple flag but also more error-prone because the list
must always be kept equal to the list of primary key columns. Failing to
keep them equal would result in an invalid SQL statement.
2019-04-03 12:19:53 +02:00
Martin Kleusberg
a615c7b5a0 Initial support for multiple primary key columns in WITHOUT ROWID tables
This add initial and mostly untested support for WITHOUT ROWID tables
with multiple primary key columns. It should now be possible to update
and to delete records in these tables.

This commit also improves the overall handling of multiple primary key
columns in preparation for better support of them in general.

Note that this makes us depend on an SQLite version with a built-in JSON
extension.

See issues #516, #1075, and #1834.
2019-04-01 21:43:00 +02:00
Justin Clift
66c2ad10c0 Fix a misleading error message typo
Also tweaked the message wording slightly, to make it sound more
natural.
2018-12-14 20:00:46 +11:00
Martin Kleusberg
e8a03f462c Fix bug in 9e36f21112
This fixes a bug in the code to modify multiple table columns in one go.
We were accidentally adding more tracked columns when adding a new
column and then changing its name.

See issue #1627.
2018-11-28 12:13:38 +01:00
Martin Kleusberg
9e36f21112 Allow any number of changes to the table schema in one alterTable call
In the Edit Table dialog we used to call our alterTable function (which
works around SQLite's missing full ALTER TABLE support by - besided
other things - copying all the data of the table) for pretty much every
change immediately. This was taking a lot of time for larger tables.

Our alterTable function allowed any number of changes if they affect
only one field of the table at once. So we could have reduced the number
of calls a lot by just using that capability. Instead however, this
commit improves the alterTable function to make possible transforming a
table completely in just one call. It does so by taking the new table
schema and using that without further modification. It also takes a new
parameter to keep track of what column in the old table becomes what
column in the new table, so the data can be preserved.

This commit obviously also changes the Edit Table dialog to make proper
use of the new features. This means that whatever changes you make to a
table, you will only have to wait once until for the alterTable call,
and that's when clicking the OK button.

See issue #1444.
2018-11-16 10:59:20 +01:00
Martin Kleusberg
918248acaa Simplify code 2018-09-26 15:54:39 +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
28b8652ad6 Improve loading of all data
The multithreading patch didn't properly load all data into the cache
when this was necessary. It would only do so if the chunk size was
sufficiently high. This is fixed in this commit.

Show a progress dialog while loading all data which can be cancelled by
the user.

When cancelling the loading of all data in those cases which require all
data to be loaded, stop whatever process needs the data too.
2018-06-08 22:46:47 +02:00
Martin Kleusberg
51dbe72e23 Multi-threading patch
This was done by Michael Krause.
https://lists.sqlitebrowser.org/pipermail/db4s-dev/2018-February/000305.html

In this commit I only fixed two compiler warnings, some whitespace
issues and removed some debug messages.
2018-06-08 22:46:47 +02:00
GortiZ
e7752d7398 KUbuntu 14.04 support restored (#1298)
* - [NEW] Add new interface and functionality to manage database file extension. (Implements feature request #659)

* - [FIX] Fixed CMake file to src.pro

* - Applied changes requested by mgrojo to uniform code with sqlitebrowser standards
- Add "history" when closing editor window, but reopen before closing preferences
- Revert some changes done by QtCreator

* Refuse from previous commit

* Additional changes requested by MKleusberg:
- [CHG] Always add "All files (*)" to filters
- [FIX] Removed unused include

* merged from master

* Merge sqlitebrowser master

* [FIX] Fixed compatibility to compile on KUbuntu 14.04 with Qt 5.2.1

* [FIX] Fix Qt version for QOpenGLWidget support on previous commit

* [CHG] Uniformed QT_VERSION_CHECK style
[CHG] Reverted macOS check on Mainwindow for OpenGL context creation
2018-05-20 15:56:01 +02:00
Martin Kleusberg
2b68afb664 Rename function
Rename the DBBrowserDB::renameColumn() function to alterTable() because
it can do a lot more than just renaming a column.
2017-11-18 11:24:05 +01:00
Martin Kleusberg
ee32b3e4e1 Use nullptr where possible 2017-10-30 21:20:02 +01:00
Martin Kleusberg
7c1ff86900 Fix usage of 'emit' macro
Even though it doesn't expand to anything...
2017-10-30 13:12:28 +01:00
Martin Kleusberg
3bd2dc3bc1 Replace 'foreach' by range-based for loop from C++11 2017-10-30 13:10:08 +01:00
Martin Kleusberg
bfa2fda1ad Attempt to implement multi-threaded loading of data
This is mostly done by trial & error. Don't expect any miracles from
it.
2017-10-11 09:21:41 +02:00
Martin Kleusberg
8a7b662435 Fix crash when editing table after changing its schema
Fix a crash which happened when opening a table in the Edit Table dialog
for modification and changing its schema and then (without reopening the
dialog) change the schema again or doing some other modifications to the
table.

See issue #1131.
2017-10-06 00:04:06 +02:00
Martin Kleusberg
59b39bbb95 Don't query foreign key settings repeatedly in Edit Table dialog
When changing the table name in the Edit Table dialog, don't query the
foreign key pragma for every key stroke.

See issue #1130.
2017-10-05 23:32:06 +02:00
Jiří Techet
969d3e470a Fix custom type saving when only focus changes for user-entered type
At the moment when user types a custom type into the type combo box and
doesn't press enter, the entered type isn't used. This patch tries to fix
the problem by installing an event filter for the combo box and checking
when it loses focus - when it does, it performs type updates too.

On the way the patch also changes the signal used inside moveCurrentField()
from activated() to currentIndexChanged() to make it consistent with the
rest of the file.
2017-09-19 21:10:03 +02:00
Martin Kleusberg
f01ad409ff Improve error handling when moving table to a different schema
When moving an existing table to a different schema which already
contains a table of that name, this causes an error. With this commit we
try to detect this type of error as early as possible.

This commit also updates the error message for that case. The old error
message still mentioned the 'temporary flag' which isn't correct
anymore.

Also, when changing the schema fails, reset the dropdown box back to a
working schema to avoid any confusion about whether the change worked or
not.
2017-09-04 20:21:56 +02:00
Martin Kleusberg
72d64edbe0 Support creating databases in schemata other than main and temp
This replaces the checkbox for creating tables in the temporary schema
by a dropdown box that lets you select between all available schemata,
i.e. main, temp, and all attached databases. This way it becomes
possible to create new tables in attached databases as well as move
existing tables between all schemata.
2017-09-04 18:15:54 +02:00
Martin Kleusberg
7db96cdf13 Improve movement of tables between different schemata
This improves the Edit Table dialog to better handle moving tables from
one schema to another, though the UI currently only knows about the main
and the temp schema.

This also simplifies the grammar code by removing the temporary flag
from all classes because it's redundant now that we support multiple
schemata.
2017-09-04 17:38:08 +02:00
Martin Kleusberg
44eb2d4f99 Add better handling of multiple schemata in the Database Structure tab
Commit 532fcd3f6b added support for
multiple database schemata to the backend code. While doing this, it
removed support for showing temporary database objects in the user
interface.

This functionally is partially reimplemented by this commit. With this
commit temporary database objects are shown in the Database Structure
tab and in the Db Structure dock. Unlike before however, they are
visually separated from 'normal' database objects. Also this commit
tries to make use of the new schema handling code wherever possible to
also separate temporary objects programatically from the normal ones.
This wasn't done in earlier versions and effectively was a source of
all sorts of errors.

This commit still lacks support for temporary tables in the foreign key
editor and in the Browse Data tab. Also a substantial amount of testing
is still required.
2017-09-03 21:36:06 +02:00
Martin Kleusberg
532fcd3f6b Add initial support for multiple database schemata
This adds initial basic support for handling different database schemata
at once to the backend code. This is still far from working properly but
shouldn't break much either - mostly because it's not really used yet in
the user interface code.
2017-09-03 13:22:21 +02:00
Martin Kleusberg
f11c0181ca Improve wording in comment 2017-04-10 14:17:01 +02:00
Martin Kleusberg
1026e9e777 Allow changing case of column name in Edit Table dialog
Allow changing the case of a column name in the Edit Table dialog
without complaining about the name already being taken. This happened
when for example changing a column called 'A' to 'a', making this sort
of changes impossible.

See issue #985.
2017-03-25 22:19:22 +01:00
Martin Kleusberg
f1194d845e Rename all the settings accessor functions
Rename the settings accessor functions from Settings::getSettingsValue()
(and similar) to Settings::getValue() (and similar). The 'Settings' bit
seems a bit redundant and costs a lot of screen space.
2017-03-20 23:16:52 +01:00
Martin Kleusberg
c68303478a Unify and (hopefully) simplify generation of savepoint names
This shouldn't change anything for the user.
2017-01-31 19:35:35 +01:00
schdub
0c10dbdd8d fix: message 'field already exists' for non existent fields 2017-01-26 16:03:21 +03:00
Oleg V. Polivets
8d8207043b FIX: Endless loop in EditTableDialog::addField (#943) 2017-01-25 18:22:49 +01:00