Commit Graph

48 Commits

Author SHA1 Message Date
Martin Kleusberg
b7a00d301a Don't track column count when parsing CSV files
When parsing a CSV file we used to check the column count for each row
and track the highest number of columns that we found. This information
then could be used to create an INSERT statement large enough for all
the data.

This column number tracking code is removed by this commit. Instead it
analyses the first 20 rows only. It does that while generating the field
list.

Performance-wise this should take a (very) little longer but makes it
easier to improve the performance in other ways later which should more
than compensate this commit.

Feature-wise this should fix some (technically invalid) corner-case CSV
files with fewer fields in the title row than in the other rows. It
should also break some other (technically invalid) corner-case CSV files
if they are imported into an existing table and have less columns than
the existing table in their first 20 rows but later on the exact same
number. Both cases, I think, don't matter too much.
2017-09-10 11:07:02 +02:00
Martin Kleusberg
8c47c6d668 Add very basic performance measurement to the Import CSV dialog 2017-09-07 22:26:32 +02:00
Martin Kleusberg
6432517805 Use a prepared statement for all records during the CSV import
Don't build a separate SQL statement per row to insert during CSV import
but use a single prepared statement which can be reused for each row.
This should speed up the CSV import noticeably.
2017-09-06 20:38:24 +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
abd7d4e689 When importing CSV data into existing tables, don't insert empty strings
When importing a CSV file into an existing table (i.e. a table where we
have a table schema), check the data type of a field before inserting
empty values. If it is an integer field, don't insert empty string like
we did before but 0 or NULL depending on the NOT NULL flag.

See issue #195.

Please note that this isn't perfect. The preview in the dialog doesn't
reflect these changes yet, it just show you the contents of the file as
is. It's a little tricky to change this and I somehow think it's better
the way it is now anyway. Also the import doesn't check for other
constraints like UNIQUE or CHECK which might cause trouble. But then
again it didn't do that before either.
2017-06-29 22:22:57 +02:00
Martin Kleusberg
a92a32157a Fix two problems in the CSV import
When importing a CSV file and using the first row as the field names,
the row would be imported as the first data row again. It's now skipped
when the checkbox is set.

When importing a single CSV file the checkbox asking whether to import
into a single table or separate tables is hidden. However, the last set
values are loaded anyway when the dialog is opened. This means the
checkbox could be set, even though it's invisible. If it's set, however,
and we're importing a single CSV file this would mean that it's
impossible to manually set the table name to import into. This is fixed,
too.

Also this simplifies the code a bit and removed a large loop from the
import dialog code.
2017-06-29 00:19:08 +02:00
iKlsR
357faeed04 Allow specifying unique table names for separate imports 2017-06-16 17:35:36 +02:00
iKlsR
97b4261190 Cleanup logic, code reuse, faster header picking 2017-06-16 17:35:36 +02:00
iKlsR
b5a2411eb6 Append Separate Tables state to import settings 2017-06-16 17:35:36 +02:00
iKlsR
225eb5ab5f Allow matching similar csv files for batch import 2017-06-16 17:35:36 +02:00
iKlsR
b0eb9acae2 Allow for interactive CSV file import
- Tweak input checker
- Preserve old file import as not to cause any unforeseen breaks
- Allow ignoring file name when importing multiple files to tables
- Mass toggle several files for import
2017-06-16 17:35:36 +02:00
Martin Kleusberg
c68303478a Unify and (hopefully) simplify generation of savepoint names
This shouldn't change anything for the user.
2017-01-31 19:35:35 +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
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
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
85934dee77 Simplify code
This simplifies some of the super long iterator declarations by using
the auto keyword from C++11.
2016-10-18 20:07:48 +02: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
743bdf9941 Fix a few warnings 2015-07-06 22:48:18 +02:00
Martin Kleusberg
b08cead7c8 csvimport: Set filename as default table name
See issue #376.
2015-07-03 21:42:46 +02:00
Samir Aguiar
ca38995013 csvparser: Add support for old Mac OS line endings
In order to detect the CR characters, the file
must be opened in binary mode, otherwise QFile just
removes them all.

See issue #212.
2015-03-04 21:28:38 +01:00
Martin Kleusberg
3c243978e7 importcsv: Improve error messages a bit
Slightly improve the error messages shown when there is a problem during
the CSV import.

See issue #213.
2015-03-03 14:23:34 +01:00
Martin Kleusberg
d9da5dcd7f csvimport: Make default settings in code a little easier to understand 2014-11-08 12:17:56 +01:00
Martin Kleusberg
9ba36d02b2 Add initial SQLCipher support
Add some basic initial support for SQLCipher. Note that this is more of
a POC than a final implementation.

This commit adds an option called 'sqlcipher' to the cmake and qmake
projects which - when enabled - replaces the default SQLite3 include and
library files by their SQLCipher counter-parts. Especially on MacOS X
there might be some more work required in finding the correct include
paths. The SQLCipher library supports unencrypted databases, too, so
even if the option is enabled the program behaves like before. You can
see the difference, though, in the About Dialog where the SQLite version
string will say 'SQLCipher version xy'.

When the sqlcipher option is enabled and you try to open a file which is
neither a project file nor a normal SQLite3 database it is assumed now
that the file is an encypted database. There is no way to tell between
an invalid file and an encypted file, so in both cases a password dialog
pops up. When the correct password and page size are entered the file is
opened and can be edited like any other database before.

Creating encrypted databases isn't supported yet. So for testing you
need to fall back to the sqlcipher command line tool.

See issue #12.
2014-11-01 12:56:53 +01:00
Peinthor Rene
be01724da8 importcsv: fix compile on clang 2014-09-05 19:59:14 +02:00
Martin Kleusberg
942b73aab0 csv: Make import a little faster
No need to update the progress window after each row. It's only really
visible for large files anyway where a single row doesn't matter that
much in terms of progress.

Also fix a compiler warning.
2014-09-05 15:00:52 +02:00
Peinthor Rene
12a85f42e1 importcsv: auto add null fields if they don't have the correct column count
Also improve the error message on import errors
2014-09-05 13:50:43 +02:00
Peinthor Rene
dc3ca09e12 fix clang warnings 2014-09-04 19:07:12 +02:00
Peinthor Rene
9bef8a8f58 importcsv: Save last used settings and add a trim fields option 2014-09-03 08:28:30 +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
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
55435e2703 ImportCsvDialog: Add options to define custom quote/separator chars
Make it possible to use other quote and separator characters than those
predefined in the respective combo boxes when importing a CSV file.

See issue #23.
2014-05-30 17:54:13 +02:00
Peinthor Rene
202b6c915e qt5: toAscii() -> toLatin1() 2014-02-13 23:52:03 +01: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
fa2589c829 DBBrowserDB: Use sqlb::Field for createTable()
When creating a new table specify the table structure using the
sqlb::Field type instead of just a plain string list.
2013-06-01 12:43:43 +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
7f03e01a86 ImportCsvDialog: Also use the new savepoint logic in this dialog
Do just the same in the ImportCsvDialog as before in the
EditTableDialog, i.e. using a unique savepoint name which is not
released when the import was successfull.
2013-05-23 18:04:27 +02:00
Peinthor Rene
c5399932e2 no need to set the db into dirty state
we have rollbacked/committed anyway
2013-03-28 18:52:07 +01:00
Peinthor Rene
e46d3401df remove the *brrr* goto 2013-03-28 18:47:38 +01:00
Martin Kleusberg
a1e4f154dd Allow CSV import into existing tables
Allow the import of CSV files into already existing tables if the number
of columns match.
2013-03-20 22:38:22 +01:00
Peinthor Rene
c5dafe9617 avoid useless string copies and fix a bug with logSQL because of that 2013-01-26 10:23:04 +01:00
Peinthor Rene
9c6bb1daed remove duplicate setDirty 2013-01-25 14:27:54 +01:00
Martin Kleusberg
d05e90e495 Improve translatability of the application
Head towards a translatable application by loading translation files for
the current locale and using tr() where ever it's needed.
2013-01-18 18:11:07 +01:00
Martin Kleusberg
8115727e75 Rewrite the Import CSV Dialog using Qt Creator
Rewrite the dialog to import CSV files using a Qt Creator form file.

Simplify the CSV import a little bit.

A bit unrelated, but needed for this anyway:
Create the restorepoint right after opening a database file instead of
just doing so after the first change.
2013-01-18 14:45:22 +01:00