Commit Graph

46 Commits

Author SHA1 Message Date
Martin Kleusberg
517743ff3f grammar: Add window functions to parser
We don't do anything with the extended parser yet but I'm not even sure
the window functions can be used in CREATE TABLE or CREATE INDEX
statements anyway.
2018-09-28 16:11:11 +02:00
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
Martin Kleusberg
e72df17bc3 grammar: Support signed default values
This adds support for table definitions with a signed default value,
like this:

CREATE TABLE test(
    a int DEFAULT -1
);
2017-04-29 13:49:00 +02:00
Martin Kleusberg
bef6dc045f grammar: Simplify code 2017-02-17 13:41:43 +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
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
Martin Kleusberg
7822a2058f grammar: Fix some warnings caused by the antlr file
This shouldn't change anything for the end user.
2017-01-14 13:51:40 +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
e9894b47fa grammar: Add support for row values
SQLite version 3.15.0 introduced a new feature called row values. These
are basically vectors of values that can be used to simplify some
expressions.

For example instead of this
CREATE TABLE x(a int, b int, c int, CHECK(a=1 and b=2));
you could write this:
CREATE TABLE x(a int, b int, c int, CHECK((a,b) = (1,2)));

However, the new syntax wasn't supported by our grammar parser which
made it impossible to access or edit that table. This commit attempts to
fix this.
2016-10-30 21:50:30 +01:00
Martin Kleusberg
5381bff244 grammar: Fix recognising numbers in the '.x' format, i.e. omitting the 0
See issue #623.
2016-08-14 17:44:55 +02:00
Martin Kleusberg
1efec0cc5a grammar: Fix tablename.columnname notation in subexpressions
When specifying a table name along with a column name you have to put a
dot between them. This wasn't taken into account by our grammar parser,
an error which could lead up to misinterpretations in other places as
well.

See issue #505.
2016-01-28 21:38:37 +01:00
Martin Kleusberg
160bc87d3c grammar: Support escaping backticks using double backticks
This adds support for escaping backticks inside an identifier using
backticks as quote characters by adding a second backtick following the
first one (e.g. `test``test`  => 'test`test').
2015-08-17 00:16:03 +02:00
Martin Kleusberg
a6bd96774a grammar: Support conflict clause in primary key constraint
Support conflict clauses (like ON CONFLICT REPLACE) inside a PRIMARY KEY
column constraint.

See https://www.sqlite.org/syntax/column-constraint.html
2015-01-16 23:35:55 +01:00
Peinthor Rene
c6f585e9c4 grammar: also allow ID tokens as default argument 2015-01-12 17:29:18 +01:00
Martin Kleusberg
1ea67c33d2 grammar: Fix string literals in CHECK expressions (and maybe other places)
Fix parsing of table definitions like this one where there is a complex
check constraint using string literals:
CREATE TABLE "a" (
    `b` TEXT CHECK(`b`='A' or `b`='B')
);
The grammar parser would fail to parse this statement correctly prior to
this fix.

See issue #179.
2015-01-06 14:11:28 +01:00
Martin Kleusberg
19baeb2a7a grammar: Fix double quote characters as used for escaping one
SQL allows you to use two quote characters instead of just one in order
to escape them. Example: ['aa''bb'] is read as [aa'bb]. Add detection
for these doubled quote characters to our grammar parser.

See issue #128.
2014-10-15 19:29:19 +02:00
Martin Kleusberg
cf62b78a1e Grammar: 'NOT' is not a valid column name 2014-08-31 12:30:37 +02:00
Martin Kleusberg
cbc324b205 Grammar: Allow rowid as column name
This fixes #80.
2014-08-22 14:10:19 +02:00
Martin Kleusberg
51014a7ddc Grammar: Allow key as column name 2014-08-22 14:07:05 +02:00
Peinthor Rene
aff96bf709 grammar: remove trailing WS 2014-08-18 19:17:24 +02:00
Peinthor Rene
6d47c749f8 grammar: proper support the index_column rule 2014-08-18 19:16:45 +02:00
Peinthor Rene
e9fc2229c2 grammar: disable antlr's default error handling
We(I) did not count on that behavior anyway and this should have never
been in place
2014-08-18 18:47:35 +02:00
Peinthor Rene
9fdc71be2c grammar: fix crash and autoincrement in primary key table_constraints 2014-08-17 12:55:22 +02:00
Martin Kleusberg
2dd0e9516f Grammar: Allow multiple table keys which are not separated by commas
Fix table definitions like this...
CREATE TABLE [player_tech_branches]
(
	[from_id] INTEGER NOT NULL REFERENCES [techs](id),
	[to_id] INTEGER NOT NULL REFERENCES [techs](id),

	UNIQUE ([from_id], [to_id]) PRIMARY KEY ([from_id], [to_id])
)
...where there are multiple keys which are not separated by commas.

This partially fixed EoD's database in issue #63.
2014-07-26 21:41:12 +02:00
Martin Kleusberg
7f007824fa Grammar: Support ON INSERT in foreign key clauses
Allow ON INSERT in foreign key clauses like this:
CREATE TABLE x
(
	y INTEGER REFERENCES ref(id) ON INSERT CASCADE
)
Note that ON INSERT is allowed by SQLite but missing in the SQLite
documentation.

This partially fixes EoD's problem in issue #63.
2014-07-26 21:41:12 +02:00
Martin Kleusberg
64bcc42241 Grammar: Add 'NO' identifier
See issue #56.
2014-07-21 21:24:53 +02:00
Peinthor Rene
f3a2a74953 grammar: fix missing literalvalues in default constraint 2014-07-10 07:30:05 +02:00
Peinthor Rene
dd85b16660 grammar: cleanup expr and fix between suffix expression 2014-06-25 19:20:40 +02:00
Martin Kleusberg
d85672511c Grammar: Fix parsing of NOT IN/GLOB/MATCH/REGEXP constraints
See issue #40.
2014-06-23 12:37:09 +02:00
Martin Kleusberg
9cb0614ecf Grammar: Parse NOT LIKE constraints correctly
Parse column constraints with a 'NOT LIKE' expression correctly. For
example in a table definition like this:
CREATE TABLE not_working(
    value TEXT CONSTRAINT "value" CHECK(value NOT LIKE "prefix%")
);

This fixes issue #40.
2014-06-20 12:47:20 +02:00
Peinthor Rene
b02b36b2a2 fix create table statements with IN operator
fixes issue #34
IN wasn't added to the token list and not enabled in the suffix expression
as this gives a parser generator warning, because of an ambiguity with IN as an operator
we stick with the warning right now
2014-06-11 22:48:51 +02:00
Martin Kleusberg
6e5c98b653 Grammar: Allow 'NULL' constraints
Allow NULL constraints in a column definition when parsing a CREATE
TABLE statement. Before this only NOT NULL constraints were parsed
correctly even though NULL is proper SQL as well - it's just a redundant
information.
2014-06-04 20:50:08 +02:00
Martin Kleusberg
3761acfd02 Extend SQL grammar to recognise 'without rowid' tables correctly
Since version 3.8.2 SQLite supports tables without the internal rowid
column added to the table. For these tables the primary key serves as a
replacement for the rowid column.

These changes update the grammar parser to correctly handle 'without
rowid' tables and also generate 'without rowid' SQL statements.
2014-05-09 14:46:42 +02:00
Peinthor Rene
d2246b79d7 grammar: fix column constrain
DEFAULT also takes quoted literals
2014-04-28 21:22:32 +02:00
Peinthor Rene
7ad887b0b3 Fix lexer to allow a lot more unicode characters in column and table identifier 2014-02-12 19:13:58 +01:00
Peinthor Rene
fd89ef72a6 Fix an issue with keywords in table or column names
note: table names are a bit more restrictive than column names
And btw. you can always have any name you want, just put it in quotes.
2013-11-24 10:23:55 +01:00
Peinthor Rene
e80f445c53 grammar: fix ambiguous string literal lexer part 2013-07-18 15:44:39 +02:00
Martin Kleusberg
ed04128a74 Grammar: Support table names in single quotes
Don't fail when parsing a CREATE statement like this:
CREATE TABLE 'test' (id INT);
2013-06-23 22:16:13 +02:00
Peinthor Rene
7bf3b87411 Fix incorrect single line comment syntax
Did never check if this syntax was correct,
now it should be fine see:
http://www.sqlite.org/lang_comment.html
2013-06-13 06:52:46 +02:00
Peinthor Rene
32ba32bbae add missing tokens
I hope I got all now
2013-05-03 21:10:10 +02:00
Peinthor Rene
ba6d51edf2 fix all warnings in the grammar and some bugs
literals were case sensitive so lower keywords broke parsing
2013-03-22 15:50:04 +01:00
Peinthor Rene
5737925079 Add a sqlite3 antlr2 "create table" grammar + generated parser files
There is also a "create table" ast walker which fills
info for the new sqlitetype objects.
A dependency to the antlr2 runtime was added.
The grammar most probably still contain bugs.
Why all this?
First writing grammars is fun and this is the only way
we can get all information for proper table editing + some time
in the future when the grammar is finished we can provide real
auto completion.
2013-03-16 20:18:57 +01:00