Commit Graph

113 Commits

Author SHA1 Message Date
Iulian Onofrei
3cdc65a63f Add automatic crypted databases open via dotenvs (#1404)
* Rename confusing variables

* Fix some project warnings

* Fix code style

* Add constant for the default page size

* Move KeyFormats enum to CipherSettings

* Fix code style

* Fix memory leak

* Stop relying on CipherDialog for encryption settings management

* Fix code style

* Add .env format for QSettings

* Add automatic crypted databases open via dotenvs

This adds support for `.env` files next to the crypted databases that
are to be opened that contains the needed cipher settings.

The only required one is the plain-text password as a value for the key
with the name of the database like this:

    myCryptedDatabase.sqlite = MyPassword

This way, databases with a different extension are supported too:

    myCryptedDatabase.db = MyPassword

You can also specify a custom page size adding a different line
(anywhere in the file) like this:

    myCryptedDatabase.db_pageSize = 2048

If not specified, `1024` is used.

You can also specify the format of the specified key using the
associated integer id:

    anotherCryptedDatabase.sqlite = 0xCAFEBABE
    anotherCryptedDatabase.sqlite_keyFormat = 1

where `1` means a Raw key. If not specified, `0` is used, which means a
simple text Passphrase.

Dotenv files (`.env`) are already used on other platforms and by
different tools to manage environment variables, and it's recommended
to be ignored from version control systems, so they won't leak.

* Add new files to CMakeLists

* Move DotenvFormat include to the implementation

* Fix build error

* Remove superfluous method

(related to ac51c23)

* Remove superfluous checks

* Fix memory leaks

(introduced by 94bbb46)

* Fix code style

* Make dotenv related variable and comment clearer

* Remove duplicated code

* Remove unused forward declaration

(introduced by e5a0293)
2018-07-10 20:46:17 +02:00
Martin Kleusberg
3da520cdd1 Clean up multi threading patch, fix build and some bugs
Make strings translatable, remove some more debug code, fix tests,
reduce size of patch slightly, remove weird tooltip, don't crash when
closing database, simplify code, fix filters, don't link agains pthread
on Windows.
2018-06-08 22:46:47 +02:00
Martin Kleusberg
51dbe72e23 Multi-threading patch
This was done by Michael Krause.
https://lists.sqlitebrowser.org/pipermail/db4s-dev/2018-February/000305.html

In this commit I only fixed two compiler warnings, some whitespace
issues and removed some debug messages.
2018-06-08 22:46:47 +02:00
Martin Kleusberg
f51b44d8d7 Add support for deleting rows in views which are unlocked for editing
If a view has been unlocked for editing by specifiying a pseudo primary
key, with this commit you can now delete records from the view if an
appropriate trigger exists.

See issue #141.
2018-06-07 16:08:08 +02:00
Martin Kleusberg
b6c05609dc Change order of statements in exported SQL file
When exporting a database to an SQL file we used to export it like this:
- Table 1 schema
- Table 1 data
- Table 2 schema
- Table 2 data
With this commit that is changed like this:
- Table 1 schema
- Table 2 schema
- Table 1 data
- Table 2 data

This makes the resulting SQL file more robust for import because it
avoids any foreign key errors as long as foreign keys are deferred.
2018-05-16 18:18:56 +02:00
Martin Kleusberg
2b68afb664 Rename function
Rename the DBBrowserDB::renameColumn() function to alterTable() because
it can do a lot more than just renaming a column.
2017-11-18 11:24:05 +01:00
Martin Kleusberg
87c0476d1c Introduce helper function for generating unique temporary table names 2017-10-31 13:06:27 +01:00
Martin Kleusberg
5a14e47419 Mark some more constructors as explicit 2017-10-31 12:11:03 +01:00
Martin Kleusberg
ee32b3e4e1 Use nullptr where possible 2017-10-30 21:20:02 +01:00
Martin Kleusberg
4ae601dafd Fix default collation for UTF16 strings
Fix our default collation which we install when an unknown collation is
requested to (more or less) support UTF16 strings as well. Before this
UTF16 strings wouldn't compare correctly because they might contain null
bytes which would lead to only the first (few) byte(s) getting compared.

See issue #1172.
2017-10-19 14:54:30 +02:00
Martin Kleusberg
32da4de94d Fix collate warning after addition of multi-threaded loading
The no collate function warning is triggered in a thread which is used
for loading data. However, the warning is a message box and GUI elements
can only be drawn in the main thread. So the old code would crash. This
is fixed here by jumping to the main thread for showing the message box.
2017-10-16 21:58:30 +02:00
Martin Kleusberg
6029e25bcc Store row columns in a vector instead of a list
This should speed things marginally up.
2017-10-08 20:06:49 +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
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