Commit Graph

151 Commits

Author SHA1 Message Date
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 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 21ee1f2703 Allow updating views
This adds a new context menu option that allows unlocking views for
updating. This requires appropriate triggers to be in place and the user
to type in a column name that can be used as a 'primary key' for the
view. By default views are still locked from editing.

Inserting into and deleting from views isn't supported yet.

See issue #141.
2017-05-12 18:17:50 +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 665837ff25 Improve error handling in execution of SQL commands
This improves the error handling when executing multiple SQL commands at
once in a couple of ways.

We didn't detect any sort of possible error. For example syntax error
were reported and execution stopped but constraint errors were just
silently ignored. This is fixed now so that no silent errors should
occur.

Also we would execute the statements one after another until hitting an
error and then just stop, even if a savepoint was created before. With
this commit we're now reverting back to this savepoint and telling the
user about this. This should bring the database back to a consistent
state.

We have to remove any transaction statements from the SQL statements
because we're always already in a transactions and they can't be nested.
However, when removing a BEGIN TRANSACTION statement this would happen
silently and not in all cases a savepoint would be created instead. This
is fixed as well by making sure a savepoint is always created by this
function when a transaction was in the original list of commands.

See issues #955 and #957.
2017-01-31 19:13:49 +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 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 cc4084fd83 Simplify code 2017-01-20 22:01:14 +01:00
Martin Kleusberg 5455fd8cb7 Mark some more methods as const 2017-01-20 19:10:07 +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 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 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 50ef6cd7c3 Allow opening databases in read only mode
See issue #325.
2017-01-15 20:22:01 +01:00
Martin Kleusberg 11ca36ef9d Fix editing table name and table columns at once
Renaming a table always happens *after* editing all table columns (at
least that's the order we're doing it currently). So for all
renameColumn() names we'll need to use the table name as it is in the
database, *not* as it is in the table name widget because that might
have been changed in the meantime.
2017-01-13 17:08:29 +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
Oleg Prutz 17369b66a6 Fix hanging when deleting large number of records (#856) (#870) 2016-11-25 09:44:47 +00:00
Martin Kleusberg e7b12332f7 Fix bug introduced in 684958b29c
This would stop the db schema from being reloaded when it actually
should be.

Also simplify code.
2016-08-30 20:01:51 +02:00
Martin Kleusberg 684958b29c Only reload DB schema when necessary
We used to reload the database schema whenever it might have been
changed and the latest version was required. For example: when the user
switches to the Structure tab we need the current schema; so we just
reloaded it to be safe - it might have been changed in the Execute SQL
tab or wherever.

With this commit we don't reload the database schema anymore when an
up-to-date version is needed but instead when it was changed by the
application. So in the example above it's not reloaded at all anymore.
Only if and when the user would execute some structure changing SQL it
would be reloaded.

Benefits:
- Better performance
- State of the structure tree view isn't lost as frequently
- Structure tree view gets updated when changing the structure in the
  Execute SQL tab

Downsides:
- Less error proof (testing!)
- No 'automatic' updates when the db is changed by an external
  application.

Any suggestions welcome!
2016-08-30 00:29:50 +02:00
Martin Kleusberg c8f020331a export: Allow exporting only the data in an SQL export
In the SQL Export dialog and process, allow the user to export the data
only, i.e. not the schema.

See issue #556.
2016-04-23 20:32:08 +02:00
Martin Kleusberg 1a7aad0ff0 Make current filename a private class member 2016-01-27 23:08:48 +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 90bb4891b9 Support read only opening of database files
When opening a read only database file show a 'Read only' note in the
status bar of the main window and disable all editing buttons in the UI.

See issue #402.
2015-08-25 19:28:40 +02:00
Martin Kleusberg 282c439228 Try to fix a compiler warning on MacOS X
See issue #386.
2015-08-06 15:14:43 +02:00
Martin Kleusberg 743bdf9941 Fix a few warnings 2015-07-06 22:48:18 +02:00
Bernardo Sulzbach abc432fcd6 Fixed a few typos. 2015-05-20 10:17:52 -03:00
Martin Kleusberg 6d196c004a Support non-integer primary keys
Add support for non-integer primary keys, especially on table without
rowid column. The previous code often assumed that the rowid column or
its equivalent was a 64bit integer but SQLite allows any data, including
text, to be stored in there.

See issue #240.
2015-04-25 14:22:54 +02:00
Martin Kleusberg 9b2529bdf4 Remove DBBrowserDB::tableColumns() method
Remove the DBBrowserDB::tableColumns() method which queries the database
for the column names of a given table and which is used for the SQL
export only. This function isn't needed at all because it generates a
whole bunch of queries for data which is already hold in memory...
2015-04-23 22:39:05 +02:00
schdub c340bb4668 exportsql: allow export schema only 2015-04-17 15:39:38 +03:00
schdub e23b0112d4 fix: type of imported BLOB data #239 2015-04-13 20:49:15 +03:00
Justin Clift 608f56eb3c Merge pull request #251 from schdub/master
exportsql: issue #242
2015-04-12 22:48:40 +01:00
Peinthor Rene 3ae9808289 use qt int64 type to fix build 2015-04-12 20:11:51 +02:00
Peinthor Rene 8cbc13a106 cmake: support for msvc2013 builds and installers 2015-04-12 19:59:04 +02:00
jsbot 073cf64a9d exportsql: issue #242 2015-04-11 23:54:05 +03:00
Martin Kleusberg 03b4ef9d1f Further improve 408fbcf8b4 2015-02-06 14:36:53 +01:00
Martin Kleusberg 408fbcf8b4 Use same data type as SQLite for primary keys
This improves commit c20c58595a to
definitely make sure the primary key values are stored and handled
correctly by simply using the same data type as SQLite itself does.
2015-02-06 14:08:59 +01:00
Martin Kleusberg c20c58595a Support 64bit primary keys
Primary keys in SQLite are 64bit in size. We, however, used the int
datatype which often is 32bit only. Also the conversion from QString and
other Qt datatypes to numbers was done by the toInt() method which fails
on these large numbers. These issues are fixed by this commit, adding
support for databases with big primary key values.

See issue #172.
2015-02-04 17:55:43 +01:00
Martin Kleusberg f63b11925d cipher: Fix attaching unencrypted DB if main is encrypted and vice-versa
When attaching another database, SQLCipher assumes that it shares
passphrase and salt with the main database. Usually this isn't the case,
though. With this commit SQLiteBrowser tries to open the database to attach
before actually attaching it and asks for encryption details if needed.

This allows the user to attach unencrypted databases to an encrypted
master database and vice-versa. Note though, that attaching an encrypted
database with a non-default (i.e. <> 1024) cipher page size doesn't seem
to work - this however, is apparently a SQLCipher limitation.

See issue #174.
2015-02-04 17:16:13 +01:00
Martin Kleusberg 8fb9176f99 cipher: Show encryption status in the main window statusbar
Add a note to the status bar of the main window when an encrpyted
database is opened.

Also make some methods in the CipherDialog class const.
2014-11-02 18:15:13 +01: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
Peinthor Rene 97e2025cc9 cvsparser: Newly implemented CSV Parser
Moved parser into it's own class
This parser now proper supports new lines in quoted text
and returns a QVector<QStringList> result.
2014-09-02 18:05:04 +02:00
Martin Kleusberg b87992c8fb Clean up the DBBrowserDB class a bit 2014-08-31 16:10:01 +02:00
Martin Kleusberg 03879d93f0 ImportCsvDialog: Allow other file encoding than UTF-8
Add a combobox and a text field for choosing a different encoding of the
input file than the default UTF-8.
2014-08-31 13:10:25 +02:00
Martin Kleusberg 7d4248ecb4 Keep field information in sqlb::Table object rather than DBBrowserObject
Keep all the table and field information in a sqlb::Table object (which
itself is stored in DBBrowserObject) rather than storing field
information in DBBrowserObject and sqlb::Table objects at the same time.
2014-08-26 17:52:15 +02:00
Martin Kleusberg 17cf2018ca Remove dependency to main window from DBBrowserDB class
Get rid of the dependency to the MainWindow class in the DBBrowserDB
class. It was only used for calling the log SQL and set database state
functions anyway. The same result can be achieved emitting Qt slots.
2014-07-12 16:13:32 +02:00
Peinthor Rene 00ae461dff add a getRow function to retrieve rowdata by rowid 2014-07-10 00:31:45 +02:00
Martin Kleusberg dca664270f MainWindow: Make it possible to cancel closing of database file
When closing the database, either by using the menu item or by closing
the window, the user is asked whether the changes he made shall be
saved or not. Add a third button to this message box which makes it
possible to cancel the action.
2014-06-20 13:03:23 +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