Commit Graph

34 Commits

Author SHA1 Message Date
Martin Kleusberg
f2c3c2b1a4 Parse and save foreign key constraints
When parsing a CREATE TABLE statement read and try to parse any foreign
key constraints and save that information.
2014-11-06 18:28:28 +01:00
Martin Kleusberg
c29702a1b9 EditTableDialog: Fix handling of default values
Fix the handling of default values in the Edit Table dialog by doing two
things: First, change the sqlb::Field class so that it doesn't put quotes
around any default values no matter what. This breaks for example NULL
default values but also causes invalid syntax if the default value is
already in quotes. Secondly, change the Edit Table dialog itself to
double check if the user should've put quotes around their default value
but hasn't. In this case add them automatically.

See issues #64 and #126.
2014-10-15 12:45:43 +02:00
Peinthor Rene
594ea38420 Fix insert on integer PK fields with not null
Moved the emptyinsertstmt into DBBrowserDB class
to be able to query the database for values.
2014-09-21 20:45:12 +02:00
Martin Kleusberg
572630197c Fix Table::emptyInsertStmt for NOT NULL fields with default value
See issue #97.
2014-09-04 20:50:15 +02:00
Martin Kleusberg
b87992c8fb Clean up the DBBrowserDB class a bit 2014-08-31 16:10:01 +02:00
Martin Kleusberg
c7de94cb77 Make it possible to add rows to a WITHOUT rowid table
This commit allows you to add new rows to a table without rowid column.
The main problem here is that SQLite won't create the next value for the
primary key column itself, so we have to do that instead.

See issue #51.
2014-08-26 18:38:04 +02:00
Martin Kleusberg
44ce30dacc Fix last commit
Fix missing rowid->_rowid_ in commit55678bb9450a0546835b2d86f5124e7efb0a1109
2014-08-23 12:11:48 +02:00
Peinthor Rene
55678bb945 sql: use _rowid_ instead of rowid
This doesn't really solve the problem, but reduces the chance
to have a nameclash with rowid, until we come up with something better
we can't fully support tables with a column name _rowid_ but that should
be very seldom
2014-08-22 23:21:44 +02:00
Peinthor Rene
9aa73915c3 sqliteparsing: add a flag to indicate if we support modifying in our dlg
This flag should indicate if we can fully handle this table definition
in our edit table dialog. if not we should do one of these things:
* disable the edit table dialog to modify the table
* display a warning message that modifying this table may remove constraints
* ??
2014-08-18 19:41:49 +02:00
Peinthor Rene
6d47c749f8 grammar: proper support the index_column rule 2014-08-18 19:16:45 +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
b754284073 Grammar: Show antlr error message where possible
When catching an exception thrown by antlr print all the information
which has been provided.
2014-08-15 12:23:51 +02:00
Peinthor Rene
f291f89a93 sqlitetypes: extract unique information of columns 2014-08-07 23:14:21 +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
8d23c77578 Grammar: Fix multiple primary keys with conflict clause
Fix handling of multiple primary keys followed by a conflict clause like
in thix table definition:
CREATE TABLE [explore_records]
(
	[system_id] INTEGER NOT NULL REFERENCES [star_systems](id),
	[player_id] INTEGER NOT NULL REFERENCES [players](id),
	PRIMARY KEY ([player_id], [system_id]) ON CONFLICT ABORT
)

This partially fixes EoD's problem in issue #63.
2014-07-26 21:41:12 +02:00
Peinthor Rene
f246ddde1e correctly extract check expression from AST 2014-06-11 22:48:51 +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
c106e82f77 grammar: forgot to update the AST treewalker too 2014-04-28 21:31:47 +02:00
Peinthor Rene
9ce88b8619 show the statement failed to parse 2014-02-12 19:17:55 +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
afc53f72c6 grammar: support string identifiers 2013-07-19 14:09:10 +02:00
Martin Kleusberg
63cf871017 SqliteTypes: Move PK flag from table to field
Store the primary key flag(s) inside the sqlb::Field objects instead of
the sqlb::Table object. Technically this doesn't make a lot of sense but
then again it makes things a lot easier for us. So this should fix quite
a few issues in the entire program, especially - again - in
renameColumn(). It also magically fixes createColumn() which had no
chance of guessing which column should be a PK prior to this.

To benefit from these changes the EditTableDialog has changes as well.
- It should now be possible to set and unset PK and AI flags and they
  are actually saved.
- Setting the AI flag automatically sets the data type to Integer
  because that's the only type SQLite can handle in an autoincrement
  field.
- Clicking on the entry in the data type combobox which is currently
  selected doesn't update the DB anymore.

This commit also makes some changes to the unit tests to reflect the API
changes made. But it also adds missing quote characters in some
verification strings.

I hope this is a worthy 500th commit - at least it's got a long commit
message...
2013-06-03 20:15:29 +02:00
Martin Kleusberg
928a957e70 SqliteTypes: Allow non-numeric default values
Fix the sqlb::Field class to support non-numeric default values by
putting them in quotes.
2013-06-02 17:16:35 +02:00
Martin Kleusberg
5b9d5cc40b Remove some debug messages. Change some error messages..
Remove some useless debug messages, e.g. because they just print an SQL
string which you can see in the SQL log window anyway.

Change some "critical" errors messages to just warning. No sense in
printing a critical error message when the program can handle the
problem by itself.
2013-05-08 22:03:04 +02:00
Peinthor Rene
ed9941ac5e proper quote field names 2013-03-29 14:50:34 +01:00
Peinthor Rene
c6d5391672 don't insert nulls into columns with a default 2013-03-25 06:41:52 +01:00
Peinthor Rene
be239d0f05 make the empty insert statement work in pk + not null situations 2013-03-24 21:53:01 +01:00
Peinthor Rene
0d601c03f1 add emptyinsertstm function to table object
creates an empty insert statement for the table fields
2013-03-24 21:20:49 +01:00
Peinthor Rene
f75b361581 add method to easily remove fields from table 2013-03-22 15:51:44 +01:00
Peinthor Rene
8b8cc32c57 remove parenthesis from check constraint 2013-03-19 17:18:52 +01:00
Peinthor Rene
1b0d5a2ff9 Fix view updating after remove field in edittable dialog
rename the FieldList typedef to FieldVector
use a object instead of a table pointer in edittable dialog
2013-03-19 17:18:52 +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
Peinthor Rene
2920697894 add setter and a datatype list 2013-03-03 22:12:16 +01:00
Peinthor Rene
9394caffa9 add classes for a new sqlite field and table objects
plus a unittest build mode
2013-02-28 17:15:03 +01:00