Commit Graph

108 Commits

Author SHA1 Message Date
Martin Kleusberg
c150d1a766 grammar: Fix row value parsing, improve whitespace handling, fix tests
This commit fixes a regression which was introduced in commit
788134eee6 which broke the parsing of row
values.

It also makes sure CHECK expressions are parsed in exactly the same way,
no matter whether they are a column or a table constraint. Before spaces
were added to the query in a different way. The way it was done for
column constaints had also an error were the minus sign of a negative
number was separated from the first digit by a space. This is fixed,
too.

Because of all the changes this commit also adjusts the tests to expect
the new layout of the check expressions. It also adds some new tests for
row values and for complex expressions to make sure both work. Finally,
it also removes all QScintilla dependencies from the tests which don't
seem to be necessary.
2018-07-13 16:54:43 +02:00
Martin Kleusberg
788134eee6 grammar: Fix parsing of complex expression
This fixes parsing of expressions of the form '(x) AND/OR y' and similar
types. It also fixes expression of the '(x)' type and of the '(x op y
AND z op w)' type.

See issue #1454.
2018-07-10 23:07:38 +02:00
mgrojo
2803e163e0 New tests for the new standard quoting and for the other quoting styles
Modified some tests for taking into account the new standard quoting and
added some more for testing the quoting configuration and for correct
parsing of different quoting styles.

Default branch in escapeIdentifier() for trying to avoid warning.
2018-06-23 17:57:18 +02:00
mgrojo
da8057c964 Revert to grave accents as default quoting
The former quoting is expected by the tests, so the former behaviour is
restored as default, until a decision about the best default value is made.
2018-06-18 19:40:53 +02:00
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
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
3bd2dc3bc1 Replace 'foreach' by range-based for loop from C++11 2017-10-30 13:10:08 +01:00
Martin Kleusberg
4a386dd6a3 Add missing include 2017-10-29 11:37:58 +01:00
Martin Kleusberg
56630a20e5 Don't use system locale when parsing SQL statements
Antlr uses the current system locale when parsing SQL statements. This
is problematic because SQL is case-independent and for converting
characters to lower/upper case it is going to use the locale. For
Turkish however this adds implicit conversions between the dotted and
dotless I which triggers another problem in Antlr: it doesn't cover the
whole Unicode character set. This commit fixes the implicit conversions.

See issue #1194.
2017-10-27 18:42:43 +02:00
Jiří Techet
18bcbf138f Fix extra spaces in type definitions with parentheses
At the moment space is inserted between all tokens from which a type
consists. This adds extra spaces to types like VARCHAR(5) which become
"VARCHAR ( 5 )" which causes problems in some applications.

This patch modifies the way tokens are concatenated for a type. It makes
sure that the extra space isn't inserted before "(" and ")" and also
after "(".
2017-09-22 20:10:09 +02:00
Martin Kleusberg
677d36074a grammar: Add support for parsing multiple FKs in column constraints
This adds support for multiple foreign keys in a column constraint.
Example:

CREATE TABLE t1(a int, b int);
CREATE TABLE t2(a int, b int);
CREATE TABLE test(
    x int REFERENCES t1(a) REFERENCES t2(a),	-- This is now supported
    y int
);

Multiple foreign keys if they are a table constraint were already
supported before.
2017-09-15 11:00:25 +02:00
Martin Kleusberg
d73fbfc156 Don't leak memory for multiple PK constraints per field (Coverity)
This should really never happen because SQLite doesn't allow statements
like

CREATE TABLE test(
    a int PRIMARY KEY PRIMARY KEY,
    b int
);
2017-09-15 10:54:08 +02: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
6321d14dd6 Add buttons for changing the column order in Edit Index dialog
Add two buttons for moving index columns up or down in the Edit Index
dialog.
2017-05-14 20:48:43 +02:00
Martin Kleusberg
b953edc8eb grammar: Don't produce unnecessary separator char in index SQL 2017-05-14 14:26:13 +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
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
cf08c26e21 grammar: Fix assignment of table information
See issue #975.
2017-03-16 17:10:00 +01:00
Martin Kleusberg
fd1f4f2d88 grammar: Detect parse errors in primary key and unique constraints
When having a table definition like this, detect the parse errors in the
table constraints correctly:

CREATE TABLE test(
	a INTEGER,
	b TEXT,
	PRIMARY KEY(a ASC),		-- ASC here
	UNIQUE(b COLLATE NOCASE)	-- COLLATE here
);

The next step is to actually parse and store this information.
2017-02-17 15:28:57 +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
bef6dc045f grammar: Simplify code 2017-02-17 13:41:43 +01:00
Martin Kleusberg
81c0cf3d4c Fix memory leak (Coverity) 2017-02-11 21:22:22 +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
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
97b5e4faf3 Make virtual tables browseable
See issue #917.
2017-01-20 23:14:06 +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
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
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
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
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
22b87847c0 grammar: Parse named primary keys in column constraints
Parse named primary keys correctly when they are in a column constraint,
not in a table constraint. E.g.

CREATE TABLE `a` (
	`x`	INTEGER CONSTRAINT c PRIMARY KEY,	-- Name 'c' here
	`y`	INTEGER,
);

See issue #741.
2017-01-08 20:42:34 +01:00
Martin Kleusberg
6740fc4d03 grammar: Fix parsing virtual tables 2017-01-08 16:32:41 +01:00
Martin Kleusberg
d8983cb066 grammar: Support named foreign key constraints in the column definition
Previously the grammar parser would fail to extract and store the name
of a foreign key constraint in statements like these:

CREATE TABLE test(
    a int,
    b int CONSTRAINT this REFERENCES xy(id)	-- See the 'this' name
);

See issue #741.
2017-01-05 22:56:12 +01:00
Martin Kleusberg
94849fccf2 grammar: Parse columns with explicit NULL (un-)constraint correctly
Table definitions like these wouldn't work before:
CREATE TABLE test(
    a int NOT NULL,    -- This worked fine
    b int NULL         -- This didn't but does now.
);

See issue #741.
2017-01-05 22:41:51 +01:00
Martin Kleusberg
99a5d02925 Fix 'modifying table not supported' message
When our grammar parser doesn't fully understand a create table
statement yet, it'll set a flag to indicate the modifying this table
will result in errors: the nonunderstood parts will be removed from the
table while editing it.

The code for this feature, however, had a bug that was triggered by some
compilers (gcc in my case) because of an ambiguous function call. That
ambiguity and thus the resulting bug are fixed by this commit, making
sure the warning appears on all systems.

This was fun to debug...
2017-01-05 21:51:16 +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
31f73df721 Fix removal of primary keys when editing tables
Suppose you have this table:

CREATE TABLE `test` (
	`a`	INTEGER PRIMARY KEY AUTOINCREMENT,
	`b`	INTEGER
);

Editing this and removing the primary key would lead to this table
statement:

CREATE TABLE `test` (
        `a`     INTEGER,
        `b`     INTEGER,
        PRIMARY KEY()
);

This is fixed by this commit, the invalid empty primary key line isn't
outputted anymore.
2017-01-04 18:13:47 +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