Commit Graph

65 Commits

Author SHA1 Message Date
Justin Clift
ff9242021a Removed an un-needed apostrophe from a user visible string 2016-08-15 00:07:12 +01:00
Justin Clift
b835ae800b Reimplement data loading and handling for the Edit Cell
This uses a somewhat different approach to the previous
one.  It now selectively stores the data into either
the text *or* hex widget buffer, and only copies the
data between them when the edit mode is changed.

Additionally, unneeded copy operations are minimised
where possible to reduce overall slowdown.:
2016-08-09 13:04:32 +01:00
Iulian Onofrei
58fb726ebf Add default field type preference
- resolves sqlitebrowser/sqlitebrowser#650
2016-07-15 01:09:38 +03:00
Vladislav Tronko
f39dc20f63 Update buttons in removal message boxes 2016-06-08 00:41:27 +03:00
Martin Kleusberg
b04d52b99c EditTableDialog: Don't allow two columns with the same name
Don't allow the user to type in a field name that is already used in
the edited table. Show a warning and reset the name if he tries do so
anyway.

Also fix the warning for the foreign key check. Here a warning was shown
and the renaming cancelled but the field name wasn't reset to the old
value.
2015-12-24 13:48:35 +01:00
Martin Kleusberg
5af384f0a2 EditTableDialog: Don't suggest field name that already exists
See issue #460.
2015-12-24 13:42:18 +01:00
GeorgijK
9d7efcacfa Fixed bug issue #390 ("crash then correct table").
Some functions renamed for better readability.

See pull request #401.
2015-10-14 22:22:07 +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
0387999403 EditTableDialog: Print error when trying to edit a column referenced in a FK
In the EditTableDialog, when trying to edit a column which is referenced
in a foreign key of some other column (and thus cannot be changed
without errors ocurring during the rename process) print an error
message instead of just going on.

See issue #362.
2015-06-21 22:18:48 +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
Bernardo Sulzbach
abc432fcd6 Fixed a few typos. 2015-05-20 10:17:52 -03:00
Martin Kleusberg
55780562d5 EditTableDialog: Add '=' in fron of functions in default value
When editing an existing table with a function used inside a default
value of a field add a '=' character before the default expression
string to match our own input format for these kind of default values.

See issue #166.
2015-05-18 18:42:24 +02:00
Martin Kleusberg
cde2393539 Use QScintilla instead of own implementation of a code editor
This is a first rough implementation of QScintilla support as SQL text
editor.

It should work mostly and build fine with qmake as well as cmake. The
new code supports all the features of the old one plus adding a few
subtle improvements. The main point of this, however, is reducing the
code we have to maintain and making it easier to add new features to the
editor.
2015-04-23 19:51:54 +02:00
Peinthor Rene
cecf681620 edittabledialg: table without rowid don't have to be integer pk columns 2015-04-10 08:55:56 +02:00
Martin Kleusberg
4fa0576853 Support tables with empty table names
Apparently SQLite supports empty table names for whatever reason. This
commit patches SQLiteBrowser to support databases with a table with an
empty name. I haven't removed the check for an empty table name in the
Create/Edit table dialog though because you probably really shouldn't
create such a table.

See issue #194.
2015-02-06 13:30:30 +01:00
Martin Kleusberg
5991a144a1 EditTableDialog: Don't quote function in default value when marked '=()'
When entering a default value like "=(strftime('%s','now'))", don't
quote it but remove the '=' character and use the following expression
as default value.

See issue #166.
2014-11-29 17:36:54 +01:00
Martin Kleusberg
3277849121 Add column to EditTableDialog to allow setting foreign key constraints
Add a new column to the fiel table in the Edit Table Dialog to allow the
user to add and edit foreign key constraints.
2014-11-06 18:33:19 +01:00
Peinthor Rene
9304b4013f edittabledlg: missed to remove another textchangeevent 2014-10-17 13:54:18 +02:00
Martin Kleusberg
05c8a153ba EditTableDialog: Make it possible again to delete default value
Commit c29702a1b9 fixed the handling of
default values and added a check to enforce quote characters when they
are needed. This check wasn't prepare for empty default values (i.e. no
default value) and would add quote characters in this case, too. This is
fixed by this commit.

See issue #133.
2014-10-16 16:38:10 +02: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
017715510f edittabledlg: don't react on textchanged
On every text change in the type combobox a renamecolumn was triggered
2014-10-10 18:47:04 +02:00
Peinthor Rene
5713bc9a07 edittabledlg: allow custom types to be entered
also changed the default key shortcut to CTRL+ENTER
2014-09-27 09:51:20 +02:00
Martin Kleusberg
ba9931ac7f EditTableDialog: Add without rowid checkbox
Add a checkbox for setting the 'WITHOUT rowid' flag in the
EditTableDialog. All functionality concerning the checkbox is
implemented by this commit with one exception: Setting/unsetting the
flag on an existing table won't perform any changes yet.

See issue #51.
2014-08-27 18:50:55 +02:00
Martin Kleusberg
e37df8658c Improve support for 'WITHOUT rowid' tables
This adds support for editing and deleting rows from tables without
rowid. It also fixes a check in the EditTableDialog when activating the
not null constraint as well as making some progress when it comes to
adding new rows.

Also see issue #51.
2014-08-26 17:58:33 +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
Martin Kleusberg
abe622ebf4 EditTableDialog: Reload the current DB schema when cancelling
All the editing in the EditTableDialog, that is the DBBrowserDB class to
be specific, messes up the current representation of the DB schema. This
is fine when the changes are actually committed by clicking the OK
button but causes confusion when the dialog is cancelled. None of the
changes are actually written to the database but the UI looks like they
are.

This closes issue #74.
2014-08-15 22:54:36 +02:00
Peinthor Rene
58867aa181 edittable: update comment 2014-08-07 23:17:42 +02:00
Peinthor Rene
ff50a94eef edittable: add ability to set the unique constraint on a table 2014-08-07 23:15:38 +02:00
mafagafogigante
262612928d some comments were corrected 2014-07-31 08:56:24 +01:00
Martin Kleusberg
a209e840b8 EditTableDialog: Also update the SQL when type is automatically changed
Also update the internal table representation and thus the SQL string at
the bottom of the window when the type of a column is changed
automatically, e.g. when the AI checkbox is clicked.

Closes #24.
2014-05-27 20:13:18 +02:00
Martin Kleusberg
0ae6f1895e Allow space characters in table and index names, disallow ` chars
Spaces in table, index and field names are actually allowed by SQLite,
so no need to check for them.
However, "`" characters cause problems when appearing in SQL statements
so disallow them instead.
2014-01-16 19:56:58 +01:00
Peinthor Rene
94819f22e2 for loop pre-increment optimization's and a slight syntax style change 2013-09-20 14:49:07 +02:00
Peinthor Rene
1bac11348f include cleanup 2013-09-19 22:55:35 +02:00
Martin Kleusberg
7167129464 EditTableDialog: Add buttons to move a field up and down
Add two buttons to move the currently selected field up or down to allow
changing the field order of a table.

Extend the DBBrowserDB::renameColumn() method to support changing the
position of a field.
2013-06-13 20:37:19 +02:00
Martin Kleusberg
bd169e034f DBBrowserDB: Remove getTableSQL() function
Delete the getTableSQL() method in DBBrowserDB. Because we reload and
store the SQL statements for tables after every change to the DB layout
we can just use these strings instead of having an extra function doing
an extra DB query. This simplifies the code a bit and also reduces the
number of SQL statements executed by the application.
2013-06-13 18:11:18 +02:00
Martin Kleusberg
324bb23193 DBBrowserDB: Merge renameColumn() and dropColumn()
Merge the renameColumn() and dropColumn() methods. They are just way too
long and complicated but also very similar that it makes no sense to
keep them separated.
This also simplifies the code of renameColumn() a bit while fixing the
trigger/view/index problem in dropColumn().
2013-06-04 17:36:14 +02:00
Martin Kleusberg
eb560e2a62 EditTableDialog: Warn when trying to set AI flag on non-integer column
Show a warning and abort the action when trying to set the auto increment
flag on a column with non-integer values in it because SQLite doesn't
allow setting the flag on these columns.
2013-06-04 16:58:54 +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
26faa9c0fb EditTableDialog: Check before setting NN when editing existing table
When setting the Not Null flag of a column in an existing table check if
there are rows with NULL values in this column before making any
changes. This avoids an error in renameColumn() caused by the INSERT
INTO ... SELECT ... statement failing. In a next step we could check if
a default value for this column has been specified and use this in these
kind of situations.
2013-06-02 21:50:25 +02:00
Martin Kleusberg
ebadc180ce EditTableDialog: Remove unused function 2013-06-01 12:50:19 +02:00
Martin Kleusberg
c0b3506ede EditTableDialog: Fix bug when renaming column
Store the old column name to be able to address it by its current name
when renameColumn is called.
2013-06-01 12:42:36 +02:00
Martin Kleusberg
b9afbe2aea EditTableDialog: Allow some more changes to existing tables
Allow setting the default value, the check values and under some
circumstances the not null flag when editing existing tables.

This required some changes to DBBrowserDB::renameColumn() which is now
using some more features of sqlitetypes.cpp but could still be improved.
2013-05-31 16:13:58 +02:00
Martin Kleusberg
82d78384e0 EditTableDialog: Some minor code clean up 2013-05-31 14:29:45 +02:00
Martin Kleusberg
7e319bd80f EditTableDialog: Fix adding new fields to table
Fix the function to add new columns to an existing table to work
properly with the recent changes.
2013-05-31 14:21:11 +02:00
Martin Kleusberg
b1333c90c7 EditTableDialog: Make it possible to change the type of existing columns
Restore the possibility to change the data type of a column of an
existing table - a feature we lost some time ago.

Also change the updateTypes() method to not actually update the types of
all columns when only one can be changed at a time.
2013-05-31 14:14:30 +02:00
Martin Kleusberg
8063502def EditTableDialog: Allow renaming columns of existing tables
Make it possible to rename the columns of already existing tables using
the EditTableDialog. This is a feature we lost somewhere around commit
b36800ea02.
2013-05-30 15:35:25 +02:00
Martin Kleusberg
8c86a01faf EditTableDialog: Don't change the cursor when renaming the table
Renaming a table doesn't take a lot of time hence no need to change the
cursor.
2013-05-25 17:22:20 +02:00
Martin Kleusberg
f3ae25572d DBBrowserDB: Remove the dirty flag
Remove the dirty flag as it is no longer needed. Because we track the
savepoints currently held open we can just use that list to see wether
there are changes to be committed. So there is no need to track this in
a separate variable.
2013-05-23 18:16:58 +02:00
Martin Kleusberg
a1b72c5eef Extend the entire savepoint logic to allow multiple active savepoints
Allow multiple savepoints in DBBrowserDB, i.e. setRestorePoint() doesn't
simply return if the DB is already set to dirty but creates an
additional savepoint.

Track the names of all savepoints which have not been either saved or
reverted yet.

Finally, and that's the whole point of this commit, change the savepoint
logic of the EditTableDialog. We used to have a transaction started when
opening a database which was only committed when the file was closed
again. This way the EditFileDialog could savely create a savepoint when
being opened and just release it when OK was clicked or revert to it
when cancel was clicked. Getting rid of the transaction broke this
logic. The dialog still worked but as the savepoint was released when
the changes were applied all changes made via the dialog were
immediately committed to the database. So clicking the revert button had
no effect on those changes. This is at best an unexpected behaviour but
could also be a problem when some changes are reverted while others
aren't. So, having the option now of keeping multiple savepoints opened
this problem can be fixed by just creating a new savepoint every time
the dialog is opened, reverting to it when it is cancelled and _not_
releasing it when OK is clicked.

I hope this works!
2013-05-23 17:41:16 +02:00