Commit Graph

70 Commits

Author SHA1 Message Date
Martin Kleusberg
652637232d Add tests 2018-01-05 18:20:28 +01:00
Martin Kleusberg
8f0312487f Fix cmake build 2018-01-01 15:17:22 +01:00
Jiří Techet
18bcbf138f Fix extra spaces in type definitions with parentheses
At the moment space is inserted between all tokens from which a type
consists. This adds extra spaces to types like VARCHAR(5) which become
"VARCHAR ( 5 )" which causes problems in some applications.

This patch modifies the way tokens are concatenated for a type. It makes
sure that the extra space isn't inserted before "(" and ")" and also
after "(".
2017-09-22 20:10:09 +02:00
Martin Kleusberg
659f38ebef Increase CSV parser performance 2017-09-18 15:10:43 +02:00
Martin Kleusberg
0eb1f65798 Optimise the CSV import performance
This commit bundles a number of smaller optimisations in the CSV parser
and import code. They do add up to a noticible speed gain though (at
least on some systems and configurations).
2017-09-13 15:03:13 +02:00
Martin Kleusberg
6ed8080fdb Don't parse entire CSV file before inserting the first row
We were separating the CSV import into two steps: parsing the CSV file
and inserting the parsed data. This had the advantages that it keeps the
parsing code and the database code nicely separated and that we have
full knowledge of the CSV file when we start inserting the data into the
database. However, this made it necessary to keep the entire parser
results in RAM. For large CSV files this uses enormous amounts of
memory.

This commit changes the import to parse the first 20 lines and analyse
them. This should give us a good impression of what to expect from the
rest of the file. Based on that information we then parse the file row
by row and insert each row into the database as soon as it is parsed.
This means we only have to keep one row at a time in memory while more
or less keeping the possibility to analyse the file before inserting
data.

On my system this does seem to change the runtime for small files which
take a little longer now (<5%), though these measurements aren't
conclusive. For large files it, however, it changes memory consumption
from using all memory and starting to swap within seconds to almost no
memory consumption at all. And not having to swap speeds things up a
lot.
2017-09-12 10:37:28 +02:00
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
1becee77ee tests: Add more regex tests 2017-08-10 21:39:51 +02:00
Martin Kleusberg
715074e0c6 Revert "tests: Fix build"
This reverts commit a436901d12.
2017-05-05 15:12:33 +02:00
Martin Kleusberg
a436901d12 tests: Fix build 2017-05-04 19:26:44 +02:00
Martin Kleusberg
e72df17bc3 grammar: Support signed default values
This adds support for table definitions with a signed default value,
like this:

CREATE TABLE test(
    a int DEFAULT -1
);
2017-04-29 13:49:00 +02:00
Martin Kleusberg
6684fc2159 grammar: Simplify code
Simplify the code by storing the flag that indicates if the parsing was
successful in the parsed object itself instead of handing around pairs
of parsed objects and bools.
2017-01-20 19:57:58 +01:00
Martin Kleusberg
3abad3fe30 Fix tests
How could I even think they would work after the refactor?!
2017-01-20 18:20:30 +01:00
Martin Kleusberg
59bf2aeecc tests: Fix tests
This is an easy fix for the failing test case after commit
64fdd78105.
2017-01-14 15:13:19 +01:00
Vladyslav
4bd899c54c Update TestRegex.cpp to fix Travis build 2016-12-29 21:06:02 +02:00
Martin Kleusberg
02019e391b Fix cmake build
Also simplify the cmake file for the unit tests.
2016-11-01 20:31:43 +01:00
Martin Kleusberg
b9e4433318 Drop Qt4 support
This commit removes all code and configuration that was required for
building with Qt4. Hopefully noone really needs it anymore.

See issue #603.
2016-10-18 18:07:38 +02:00
Martin Kleusberg
1ced897793 Switch to using C++11 and Qt5 (#808)
* grammar: Simplify code thanks to C++11 being there

* Use lambdas instead verbose slots for duplicating record

* travis: Use Qt5
2016-10-18 17:31:20 +02:00
Martin Kleusberg
9c5c2f7f36 Clean up CMakeLists.txt file for the unit tests 2016-10-14 13:38:13 +02:00
Vlad
c25119ed4e Add unit test for regex parsing comments in SQL query (#826) 2016-10-14 13:23:27 +02:00
Martin Kleusberg
5c17115c03 grammar: Move primary key handling over to the new system
This adds support for named primary keys.

It also makes it easier to store extra information in the future as
needed for ordered primary keys.
2016-09-06 15:40:16 +02:00
Vladislav Tronko
2ced0ff4e9 Add Settings files to test CMakeLists.txt 2016-09-04 00:13:22 +03:00
Martin Kleusberg
5775fc5f25 tests: Fix build errors 2016-08-26 17:09:43 +02:00
Martin Kleusberg
89f7286220 tests: Stupid fix for Qt4 2016-08-20 14:22:11 +02:00
Martin Kleusberg
d98338ce89 Move all foreign key handling form the fields to the tables
Foreign keys used to be stored along with the column information even
though it's more or less a table constraint. However, as we only support
single column foreign keys it was easier to store it inside that single
column. Now with multi-column foreign keys coming, a mechanism has been
introduced to store those multi-column foreign keys in the table data.
This lead to two different storing places for foreign key information:
inside the field for one-column foreign keys and inside the table for
multi-column foreign keys. This commit deletes the foreign key storage
inside fields and changes all code to use the table storage.
2016-08-19 20:01:25 +02:00
Martin Kleusberg
beff43acfc tests: Add test case for unique table constraints 2016-08-18 20:44:12 +02:00
Martin Kleusberg
7e0adabd6a Fix primary key names not being escaped
See issue #613.
2016-05-27 22:32:53 +02:00
Martin Kleusberg
00ee9b8da4 Actually fix tests
I'm stupid.
2015-12-22 19:10:31 +01: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
Pino Toscano
ae08f772a2 cmake: use an external antlr2 if available
Look for an installed antlr v2, and if available use it instead of its
embedded copy.
2015-05-03 15:44:42 +02:00
Pino Toscano
8d07f120bf tests: remove DBBrowserDB usage from test-import
Apparently DBBrowserDB is not really used, so remove it and cleanup
test-import from the extra sources and dependencies needed by that.
2015-05-03 14:37:18 +02:00
Pino Toscano
27df9cfa4d tests: split sqlb-unittests
Instead of a single executable running different unit tests at the
same time, split the sqlobjects and import parts out of it.
While this currently duplicates the cmake boilerplate for each,
it allows to finetune each properly (like build only the sources for
it, in the future), and to call each separately.

Add the QTEST_MAIN in each test, and remove the manual QCoreApplication
handling in TestImport (handled by QTEST_MAIN).
2015-05-03 14:34:09 +02:00
Pino Toscano
57f2622e34 tests: merge build of tests within main build
Instead of a separate CMakeLists.txt for the tests, make them built
together with the rest of the main project. This behaviour is off
by default, and can be enabled using ENABLE_TESTING.

Furthermore, the testing facilities of cmake are now used, so ctest
(invoked by `make test`) knows about the sqlb-unittests. Thus, adapt
the Travis build steps, building the main sources and executing the
tests twice, one for sqlite and one for sqlcipher.
2015-05-03 14:29:00 +02:00
Pino Toscano
584f5d66bb tests: fix encoding handling in TestImport
Make sure to write the temporary CSV file in the proper encoding
(i.e. the one specified by the test data), and to use that encoding
when reading back from it.
This way the test should behave correctly, no matter the current
system charset.

Furthermore, fix and extend unicode data: the current utf8chars is
actually UTF-16 data, so rename it and change its encoding as such.
Add a proper utf8chars data with UTF-8-only characters.
2015-05-02 16:31:09 +02:00
Samir Aguiar
d4215052dd unittests: Pass a safely modifiable arg to QCoreApplication
This also silents C++11 warning about deprecated conversion.
2015-03-10 10:18:56 +01:00
Samir Aguiar
f1ac26e216 csvparser: Unit tests for old Mac line endings and empty strings 2015-03-04 21:29:03 +01:00
Pino Toscano
afaf2ca73c tests: fix QCoreApplication parameters
The argument count (first parameter) is a reference, and thus must be
kept alive for the whole lifetime of the QCoreApplication instance,
as also the Qt apidocs say.

Also properly create a "string array" for the actual args, instead
of badly casting a string to that.

This fixes sporadic crashes in this test.
2015-01-17 13:06:22 +01:00
Martin Kleusberg
a090875575 tests: Add test for grammar fix in 1ea67c33d2 2015-01-06 14:12:08 +01:00
Martin Kleusberg
4b7766a0fe tests: Add tests for foreign key parsing 2014-11-06 18:29:34 +01:00
Martin Kleusberg
19baeb2a7a grammar: Fix double quote characters as used for escaping one
SQL allows you to use two quote characters instead of just one in order
to escape them. Example: ['aa''bb'] is read as [aa'bb]. Add detection
for these doubled quote characters to our grammar parser.

See issue #128.
2014-10-15 19:29:19 +02:00
Martin Kleusberg
b841025bae tests: Add test to check escaping quotes by using two of them 2014-10-15 12:57:37 +02:00
Peinthor Rene
0031c0723f tests: fix tests to run without x server 2014-09-18 08:05:45 +02:00
Peinthor Rene
98ab683662 tests: fix tests to run without x server 2014-09-18 08:01:04 +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
Sandro Mani
27b6bef37d Fix bad test 2014-08-27 19:04:38 +02:00
Sandro Mani
6b4d079e6a Fix syntax issues 2014-08-27 19:04:35 +02:00
Martin Kleusberg
ba75bd16fe Use common format for all include guards and avoid leading underscores
Use a common format for all include guards, make sure each header file
has one and make sure it's named after the file name.

And as a random extra in this commit: Make sure the gen_version.h file
generated by cmake ends with a line break.

Closes #59.
2014-07-31 21:32:58 +02:00
Martin Kleusberg
42a2faf411 Tests: Simplify the cmake file
Now that the dependeny to the main window is removed from the
DBBrowserDB class we can get rid of all the dialogs and widget related
stuff in the cmake file used for the unit test project. Because our
Application class depends on the main window, too, the code for the CSV
tests is changed to use Qt's standard QApplication class.
2014-07-12 16:21:08 +02:00
Martin Kleusberg
e7924f3739 Tests: Add unit tests for CSV import
Add a new test class for testing the import functionality. Currently
it's only covers some test cases for the CSV import.

Since the function to test here (DBBrowserDB::decodeCSV) is part of the
DBBrowserDB class, that class has a reference to the main window and the
main window basically depends on the entire rest of the project the
makefile grew quite a bit unfortunately.
2014-07-11 21:31:34 +02:00