Commit Graph

1738 Commits

Author SHA1 Message Date
Martin Kleusberg
f728ff73ab Remove useless function in Edit Table dialog 2017-01-23 22:08:19 +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
383925652f Don't use base table name where the actual table name is appropriate
In the SQL export don't use the base table name of a table when you
should actually use the table name itself. The way SQLite reports its
data these just happen to be the same for tables.

This doesn't change anything when it comes to functionality but is
semantically more correct.
2017-01-23 17:21:58 +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
00ac4aaa51 Try fixing the Travis build 2017-01-22 21:36:53 +01:00
Martin Kleusberg
d1e3e98006 cipher: Add support for encryption using the raw key format
See issue #264.
2017-01-22 15:36:54 +01:00
Martin Kleusberg
ef399d1770 Save foreign keys settings in the project files
Save the value of the foreign keys PRAGMA in the project files and
restore it when loading a project file.

See issue #848.
2017-01-22 12:17:01 +01:00
Martin Kleusberg
97b5e4faf3 Make virtual tables browseable
See issue #917.
2017-01-20 23:14:06 +01:00
Martin Kleusberg
e43dbddbd3 Remove unnecessary includes
Hopefully this reduces the compile time a little bit.
2017-01-20 22:37:59 +01:00
Martin Kleusberg
cc4084fd83 Simplify code 2017-01-20 22:01:14 +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
c0d2e9131e Try using the system version of libscintilla2
See issue #832.
2017-01-20 18:57:20 +01:00
Martin Kleusberg
3abad3fe30 Fix tests
How could I even think they would work after the refactor?!
2017-01-20 18:20:30 +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
e3ef13a916 Fix bug introduced by 194979edb0 2017-01-20 16:54:27 +01:00
Martin Kleusberg
0f0b18d427 Show better error message when recreating objects after renaming column fails
When renaming a column of a table it might be necessary to recreate any
triggers nd indices referencing this column. There are several reasons
why this might fail and which are difficult to catch for us. For this
reason we just show an error message to the user in these cases so they
can fix the statements and run them manually. Previously to this commit
this error message contained a list of all SQL statements which were
tried to execute. So if you had 10 references to the table (not the
column!) and 7 of them could be recreated, the error message would still
have shown all 10 SQL statements. With this commit it only shows the
remaining 3 statements. This should make the dialog much easier to print
for large databases and makes it much easier for the user to grasp.
2017-01-20 12:58:32 +01:00
Martin Kleusberg
dc934a7ec7 When renaming a table column try to fix all indices referencing the column
Suppose you have this database:
CREATE TABLE a(
    x INTEGER,
    y INTEGER
);
CREATE INDEX i ON a(x ASC);

Now, when trying to rename column x of table a to some other name using
the Edit Table dialog will work but index i will be lost during the
process. This is because it needs to be recreated after having modified
the table, however its create statement isn't valid anymore because the
column name x doesn't exist anymore. This is changed by this commit to
significantly increase the chance that renaming a column won't throw an
error, thus making the Edit Table dialog a lot safer to use.
2017-01-20 12:51:14 +01:00
Martin Kleusberg
2c7f32c699 Rename Create Index dialog to Edit Index dialog
Just like the Edit Table dialog, this dialog handles both creating and
editing. For consistency's sake this dialog is therefore renamed to Edit
Index dialog.
2017-01-20 12:35:07 +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
9570d4b332 Remove unnecessary include 2017-01-19 23:11:04 +01:00
Iulian Onofrei
c657ffb7b3 Update README.md
Fix code style and add hyperlink to Qt badge
2017-01-19 09:00:15 +02:00
Justin Clift
49c2ccbba5 Add Qt badge as per @dridk 2017-01-18 22:37:10 +00:00
Martin Kleusberg
5858ea448d Allow table names consisting only of spaces in Edit Table dialog
SQLite allows this, so we should too.
2017-01-17 19:31:17 +01:00
Vladyslav Tronko
194979edb0 Slight optimization of loop in populateTable() method 2017-01-17 03:24:14 +02: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
Vladyslav Tronko
0c60b01770 Replace obsolete key combination in comments 2017-01-16 18:30:55 +02:00
Vladyslav Tronko
e7de02b18d Fix Travis build error 2017-01-16 17:17:37 +02:00
Martin Kleusberg
d868f4c85d Make last database error message private
It's not supposed to be edited by anyone else.
2017-01-16 15:52:37 +01:00
Martin Kleusberg
45580865d3 Merge branch 'plotrefactoring' 2017-01-16 12:46:52 +01:00
Martin Kleusberg
6cc850c167 Allow setting the temporary table flag in Edit Table dialog
Add a new option to the Edit Table dialog for creating temporary tables.
This also allows the conversion between temporary and permanent tables.
2017-01-16 11:15:16 +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
Vladyslav Tronko
4ecb50277c Set adjustment rules for combobox within foreign key editor 2017-01-16 04:16:17 +02:00
Martin Kleusberg
0584d0380d Don't try opening database for writing when not necessary 2017-01-15 21:23:05 +01:00
Martin Kleusberg
1a6c34951b Fix error handling in open database procedure
When opening a database fails a proper error message is now shown which
hopefully tells the user what the source of the problem is. Note: this
will only work for newer versions of SQLite.

This requires a bug fix which is included in this commit. The error
message wasn't taken from the correct database handle, so it had nothing
to do with the actual error source. This is fixed by this commit as
well.
2017-01-15 21:22:03 +01:00
Martin Kleusberg
fa81c0b1e3 Fix possible warning 2017-01-15 20:29:45 +01:00
Martin Kleusberg
50ef6cd7c3 Allow opening databases in read only mode
See issue #325.
2017-01-15 20:22:01 +01:00
Vladyslav Tronko
d3dde35f90 Use references for iterating through object map 2017-01-15 03:08:00 +02:00
Martin Kleusberg
59bf2aeecc tests: Fix tests
This is an easy fix for the failing test case after commit
64fdd78105.
2017-01-14 15:13:19 +01:00
Martin Kleusberg
64fdd78105 grammar: Fix parsing of exotic column data types
This fixes two issues with unusual but valid data types for columns:

1) When having a data type that consists of more than one word these
wouldn't be separated anymore after parsing. This is fixed now. Example:
CREATE TABLE test(a long int);
would have become
CREATE TABLE test(a longint);

2) Some keywords are allowed to be used as data types. Parsing these
tables would have failed entire prior to this. This is fixed, too.
Example:
CREATE TABLE test(a no);
would fail.
2017-01-14 14:46:04 +01:00
Martin Kleusberg
09b679252e grammar: Fix using unquoted keywords as DEFAULT values in constraints
This fixes tables like these where a keyword (in this case NO) is used
as an unquoted default value for a column:

CREATE TABLE test(a DEFAULT NO);

See issue #877.
2017-01-14 14:34:24 +01:00
Martin Kleusberg
ec9e05ee7f grammar: Add support for columns named 'no'
Fix parsing of tables with columns named 'no' and no quoting, like this one:

CREATE TABLE test(no int);
2017-01-14 14:11:16 +01:00
Martin Kleusberg
396589d3d4 grammar: Add support for tables named 'no'
This fixes parsing for tables named 'no', like this one:

CREATE TABLE NO(a int);
2017-01-14 14:07:50 +01:00