Commit Graph

69 Commits

Author SHA1 Message Date
mgrojo
5c7238d3d0 Preference for quoting identifier mechanism
A new option is added to the SQL tab in Preferences for choosing which
quoting characters must be used by the application when it inserts an
identifier in SQL code. The three options supported by SQLite are
available.

Default quoting characters have been changed from `Grave accents` to
"Double quotes" (SQL standard).

This options also affect the highlighting of double quoted strings: when
the SQL standard is selected, double quoted expressions are highlighted as
identifiers, otherwise as literal strings.
2018-06-18 17:49:12 +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
39a5460500 Fix crashes in Edit Index dialog when database has no tables
Fix some crashes in the Edit Index dialog which happen if you try to add
a new index when there are no tables in the database yet.

See issue #1293.
2018-01-15 22:38:10 +01:00
Martin Kleusberg
743e7985c2 Add support for conflict clauses to the grammar parser
Add support for parsing and generating CREATE statements with an ON
CONFLICT clause for their primary key.
2018-01-05 17:35:26 +01:00
Martin Kleusberg
5a14e47419 Mark some more constructors as explicit 2017-10-31 12:11:03 +01:00
Martin Kleusberg
5f6a1a1688 Try to fix the Windows builds
See issue #1120.
2017-09-05 16:57:15 +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
ea1659e1d0 Support schemata other than main in the Browse Data tab
Similar to commit 44eb2d4f99 this commit
makes use of the backend code improvements introduced in commit
532fcd3f6b.

It adds support for database schemata other than "main" to the Browse
Data tab. With this it's possible again to browse and edit data of
temporary tables using the Browse Data tab. This time, however, they are
separated logically from "main" tables. So handling temporary tables
should be a lot less error prone now, plus it's easier to tell for the
user what tables goes in what schema.

This commit changes the project file format. There is some code included
which allows loading of project files in the old format. However,
project files generated using versions after this commit can't be loaded
by older versions of DB4S.
2017-09-04 12:27:52 +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
037b3c0113 Some improvements to the Export SQL dialog
When possible, don't write 'CREATE TABLE/VIEW/... `name`' but 'CREATE
TABLE/VIEW/... IF NOT EXISTS `name`' to the file.

Add an option to add DROP TABLE statements before each create statement.
This needs to be enhanced to apply to views, indices, and triggers as
well. See issue #629.

Clean up code.
2017-05-12 15:38:46 +02:00
Martin Kleusberg
6e6f7cdc18 Add support for building with Qt 5.5 2017-05-12 10:40:24 +02:00
Martin Kleusberg
3596bf6c8d grammar: Add support for CHECK table constraints
This adds support for CHECK table constraints. We already had support
for CHECK column constraints and still mostly use that but with this
commit there are no more hickups when encountering such a table. It also
adds basic support for editing those tables: the CHECK constraint isn't
removed anymore when editing a different part of the table.

Example:
CREATE TABLE test(
	a int CHECK a IN(1,2,3),	-- This was supported before
	b int,
	CHECK b IN (1,2,3)		-- This is added by this commit
);
2017-04-30 23:35:48 +02:00
Martin Kleusberg
0f75ad54b2 Fix possible build error 2017-03-18 21:09:43 +01:00
Martin Kleusberg
9ea807f67f grammar: Parse collations in column definitions
Parse the COLLATE term in CREATE TABLE statements like these:

CREATE TABLE test(a TEXT COLLATE NOCASE);

See issue #411.
2017-02-17 13:50:42 +01:00
Martin Kleusberg
901e087c98 Add index columns to database structure tree
In the Database Structure tab and dock tree widgets, make the indices
expandable and show their indexed columns as child nodes.
2017-01-27 12:31:08 +01:00
Martin Kleusberg
b6b94a8a93 Overload the assignment operators for the Table and Index classes
This fixes issues that assigning the main representation of the database
in DBBrowserDB::objectMap is modified when playing around with the
database in the Edit Table and Edit Index dialogs.

These bugs were caused by my refactoring. Let's hope there's not much
more fallout from this refactoring...
2017-01-23 22:04:28 +01:00
Martin Kleusberg
38144bbcad Finish main part of the recent refactoring effort
This finally gets rid of the DBBrowserObject class entirely and moves
all its functionality to the newer classes in the sqlb namespace.

I'm still not entirely happy with this but at least things should be a
little more consistent now.
2017-01-23 20:59:12 +01:00
Martin Kleusberg
9266d207cd grammar: Add stub for the trigger class 2017-01-23 17:20:42 +01:00
Martin Kleusberg
f8165d475c Make a method private 2017-01-23 17:09:24 +01:00
Martin Kleusberg
d236f6df9f grammar: Introduce basic View class stub
Parsing views or generating a CREATE VIEW statement isn't implemented
yet.

Also unify the process by which it's possible to retrieve information on
the fields of a database object.
2017-01-23 17:06:41 +01:00
Martin Kleusberg
ebc3869627 Rename sqlb::Object::ObjectTypes enum to sqlb::Object::Types
The 'Object' parts seemed a little redundant before.
2017-01-23 13:44:36 +01:00
Martin Kleusberg
649f2b8b93 Simplify include file 2017-01-23 13:36:31 +01:00
Martin Kleusberg
6684fc2159 grammar: Simplify code
Simplify the code by storing the flag that indicates if the parsing was
successful in the parsed object itself instead of handing around pairs
of parsed objects and bools.
2017-01-20 19:57:58 +01:00
Martin Kleusberg
5455fd8cb7 Mark some more methods as const 2017-01-20 19:10:07 +01:00
Martin Kleusberg
e5a79ec0fa Code refactoring
This changes the class structure in the sqlb namespace as well as the
DBBrowserObject class. The rest of the commit are changes that are
required by the modifications in sqlb and DBBrowserObject.

The idea behind this refactoring is this: we currently have the
DBBrowserObject class which holds some basic information about the
database object (name, type, SQL string, etc.). It also contains a
sqlb::Table and a sqlb::Index object. Those are used if the type of
the object is table or index and they contain a whole lot more
information on the object than the DBBrowserObject class, including the
name, the type, the SQL string, etc.

So we have a duplication here. There are two class structures for
storing the same information. This has historic reasons but other than
that there is no point in keeping it this way. With this commit I start
the work of consolidating the sqlb classes in order to get rid of the
DBBrowserObject class entirely.

This commit only starts this task, it doesn't finish it. This is why it
is a little messy here and there, but then again the old structure was a
little messy, too. We will need at least a very basic trigger and view
parser before finishing this is even possible. When this is done, I hope
the ode will be much easier to read and understand. But even in the
current state there already is some progress: we save a little bit of
memory, don't copy big objects all the time anymore, and replace a lot
of unnecessary string comparisons with integer comparisons.
2017-01-20 17:42:15 +01:00
Martin Kleusberg
c9ceb5da59 Add Edit Index feature
Improve the Create Index dialog so that it allows creating as well as
editing indices.

Chenge the code for the main window to allow editing existing indices.
2017-01-20 12:15:49 +01:00
Martin Kleusberg
81dedbf98b grammar: Add support for parsing CREATE INDEX statements
This commit adds support for CREATE INDEX statements to our grammar
parser. The new parser is called for each index when reloading the
database schema. However, the resulting index representation isn't used
yet. Also note that this duplicates some code, though not much. The idea
is to consolidate this later in a way that includes triggers and views
as well.
2017-01-20 10:15:03 +01:00
Martin Kleusberg
1bd1009588 Add live SQL preview to the Create Index dialog
Add a fancy live preview of the SQL statement that is about to be
executed, just as we have one in the Edit Table dialog.
2017-01-16 18:17:52 +01:00
Martin Kleusberg
00e01080c9 Add new Index class and use in Create Index dialog
This adds a new class for indices, similar to the one for tables. This
class is supposed to make creating and editing indices a lot easier,
making all manual string concatenation unnecessary.

For now this is only used for simplifying the index creation procedure
in the Create Index dialog.
2017-01-16 18:17:52 +01:00
Martin Kleusberg
cd2f14e2dc Remember when a table is only a temporary table
You can create temporary table using CREATE TEMPORARY TABLE xxx
statements. DB4S shows them as ordinary tables which is fine most of the
time. However, it wouldn't remember the temporary status when editing
them via the Edit Table dialog. This means that editing them would
create a normal, non-temporary table. This is fixed by this commit.
2017-01-16 11:01:18 +01:00
Martin Kleusberg
01e68f0821 grammar: Add very, very basic support for virtual tables to the parser
This adds basic support for parsing CREATE VIRTUAL TABLE statements to
the grammar parser.

This doesn't mean that those tables are handled correctly at all.
Especially editing them and browsing them isn't working. But it didn't
work before this either.

See issue #917.
2017-01-05 21:42:02 +01:00
Martin Kleusberg
d3ac0bdb81 Fix editing of foreign keys in Edit Table dialog
Fix a bug when removing a foreign key from a table.

Fix a bug when editing an existing foreign key on a table.

See issue #918.
2017-01-04 19:32:06 +01:00
Martin Kleusberg
f7a29ff541 Fix editing of primary and foreign keys for existing tables
See issues #872 and #918.
2017-01-04 17:54:59 +01:00
Vladislav Tronko
c677872ba5 Make it possible to remove table constraints of specific type 2016-12-30 04:56:11 +02:00
Martin Kleusberg
f3dcf5a0c8 Store contraints in a hash structure instead of a map
Our key type here is a vector of fields and vectors aren't less than
comparable by default (and I have no idea how to implement a sane
operator<() for them). But because maps require less than comparability,
change the map to a hash which only requires an operator==() which a
vector should have by default.

No idea how this ever worked with a map?!

See issue #854.
2016-11-04 18:02:59 +01:00
Martin Kleusberg
b9e4433318 Drop Qt4 support
This commit removes all code and configuration that was required for
building with Qt4. Hopefully noone really needs it anymore.

See issue #603.
2016-10-18 18:07:38 +02:00
Martin Kleusberg
1ced897793 Switch to using C++11 and Qt5 (#808)
* grammar: Simplify code thanks to C++11 being there

* Use lambdas instead verbose slots for duplicating record

* travis: Use Qt5
2016-10-18 17:31:20 +02:00
Martin Kleusberg
5c17115c03 grammar: Move primary key handling over to the new system
This adds support for named primary keys.

It also makes it easier to store extra information in the future as
needed for ordered primary keys.
2016-09-06 15:40:16 +02:00
Martin Kleusberg
9a7e042302 grammar: Consolidate constraint handling 2016-08-26 16:56:04 +02:00
Martin Kleusberg
e1ff34e286 grammar: Add support for multiple constraints on the same field(s)
Example:
CREATE TABLE `y` (
	`a` int,
	`b` int,
	CONSTRAINT `c1` UNIQUE(`a`,`b`),
	CONSTRAINT `c2` UNIQUE(`a`,`b`)
);
2016-08-26 14:31:33 +02:00
Martin Kleusberg
5e6900ef5a grammar: Support named unique constraints
Also restructure the unique constraint handling a bit to be more
parallel to the foreign key handling.

Note that this (intentionally) introduces a bit of unnecessary
code duplication which is to be eliminated in one of the next commits.
2016-08-26 14:28:40 +02:00
Martin Kleusberg
ce75ccf035 grammar: Support named foreign keys 2016-08-26 14:16:07 +02:00
Martin Kleusberg
d98338ce89 Move all foreign key handling form the fields to the tables
Foreign keys used to be stored along with the column information even
though it's more or less a table constraint. However, as we only support
single column foreign keys it was easier to store it inside that single
column. Now with multi-column foreign keys coming, a mechanism has been
introduced to store those multi-column foreign keys in the table data.
This lead to two different storing places for foreign key information:
inside the field for one-column foreign keys and inside the table for
multi-column foreign keys. This commit deletes the foreign key storage
inside fields and changes all code to use the table storage.
2016-08-19 20:01:25 +02:00
Martin Kleusberg
91615f940f Try fixing compilation with Qt4 2016-08-18 23:29:37 +02:00
Martin Kleusberg
6a4d58042c Parse foreign keys based on multiple columns
See issue #558.
2016-08-18 23:17:35 +02:00
Martin Kleusberg
225d3437e0 Add parsing support for UNIQUE table constraints
See issue #540.
2016-08-18 20:33:39 +02:00
Martin Kleusberg
631979c330 Improve escpaing support
When generating SQL statements properly escape all identifiers, even
those containing backticks which apparently are allowed inside
identifiers in SQLite.

See issue #387.
2015-08-17 00:17:48 +02:00
Martin Kleusberg
743bdf9941 Fix a few warnings 2015-07-06 22:48:18 +02:00
Martin Kleusberg
0e18e36aa9 Parse foreign key clauses instead of just treating them as a big string
This changes the SQL grammar parser so that it parses foreign key
clauses instead of just reading to the end of the clause when
encoutering one. This allows using the information inside the clause
later in a more effective way. However, as of now this isn't used yet.
This commit only attempts to imitate the old behaviour using the new
approach (and might fail doing so, causing new errors...).
2015-06-21 22:09:36 +02:00