Commit Graph

228 Commits

Author SHA1 Message Date
silverqx 039e9fcf4b drivers get rid of Drivers::SqlError 🔥🚀🥳
This is part 2 of: used TinyDrivers exceptions everywhere.
The Drivers::SqlError was dropped and renamed to DummySqlError which
does nothing and it exists only for API compatibility with QtSql module
and it also helps to avoid #ifdef-s in users/client code.

There are 3 exceptions (what is all this about) and they are SqlError,
QueryError, and SqlTransactionError. The SqlError is a general SQL
exception class that is thrown eg. during connecting to SQL server
or during all other SQL API calls that are not database queries or
transaction queries.

The second part of this commit was to modify all error handling
in TinyOrm library and adapt it to exceptions thrown from
the TinyDrivers library.
Many #ifdef-s were added because of this because QtSql module returns
bool and then you need to obtain the QSqlError and TinyDrivers library
throws exceptions.

This commit was huge, also it's very weird and this error handling
things are unpopular and everybody has different opinion on this, but
it is what it is.

There is not way I would return bool and set error state instead of
exceptions in TinyDrivers, never.
Also, there is no way I would catch Drivers::SqlError/QueryError/
SqlTransactionError in TinyOrm library and translate these TinyDrivers
exceptions to TinyOrm exceptions with the same names to throw only one
set of exceptions, no way. TinyDrivers throws its own exceptions and
TinyOrm linked against QtSql throws its own exceptions (with the same
names but in different namespace).

 - removed all setLastError() and throw exceptions instead
 - added new constants
 - optimized #include-s
 - changed the causedByLostConnection() method signature
 - enhanced the ManagesTransactions class
 - extracted code to the mysqlClose()
 - removed MySqlDriverPrivate::q_ptr (not needed anymore)
 - removed createError() and createStmtError() (not needed anymore) and
   added prepareMySqlError() and prepareStmtError() as counterparts
 - renamed method to errorMessageForStmtFetch()
 - extracted the replaceBindingsInSql() because it's used from both
   TinyOrm and TinyDrivers libraries
 - enhanced replaceBindingsInSql()
   - added support for BLOB-s
 - the SqlError, QueryError, and SqlTransactionError are excluded from
   TinyOrm library build and include path if compiled against
   the TinyDrivers library (they are not needed and used anymore)
 - added connection name to SqlResult class, it's used in exception
   messages
 - also updated auto tests

bugfix-es:

 - qmake propagate the TINYDRIVERS_MYSQL_DRIVER DEFINE (made it public),
   cmake build is OK
 - removed mysql_thread_init()
 - changed call order for the mysql_thread_end()
2024-04-07 18:12:00 +02:00
silverqx b6347ae229 drivers renamed enum types
Renamed from QSql::BeforeFirstRow/... and QSql::LowPrecisionDouble/...
to TCursorPosition and TPrecisionPolicy.
2024-04-07 18:11:36 +02:00
silverqx 28633c129e drivers renamed QSqlQuery to TSqlQuery 2024-04-07 18:11:36 +02:00
silverqx cb7dd9fdcf drivers add swappable Qt/Tiny SQL drivers
The TinyOrm library can be compiled against the QtSql or TinyDrivers.
2024-04-07 18:11:35 +02:00
silverqx 018f9d70ee drivers initial qmake build 2024-04-07 18:11:34 +02:00
silverqx 46c71e69ca tests/models fixed/suppressed Clang Tidy warnings 2024-03-20 14:42:43 +01:00
silverqx df3df312b2 tests/models fixed/suppressed Clang Tidy warnings 2024-03-20 14:42:43 +01:00
silverqx b9fd4c9503 tests added where condition override test 2024-03-18 12:44:03 +01:00
silverqx 91976f127b tests suppressed Clang Tidy warning 2024-02-25 14:39:32 +01:00
silverqx b116fb74fa tests upgraded to MariaDB v11.3.2 2024-02-22 20:15:19 +01:00
silverqx 914a784250 added a new dummy_NONEXISTENT constant
- used it everywhere (tests only currently)
2024-02-13 20:48:02 +01:00
silverqx 4e34fc4143 tests used sl() macro everywhere 2024-02-05 16:27:44 +01:00
silverqx ae2f1477b0 tests added binary (blob) tests
- added a new tst_Blobs functional test case that inserts
   binary()/text() and mediumBinary()/mediumText()
 - updated schema builder unit tests, added all supported binary types
 - updated migrations
 - added Lorem ipsum paragraphs generator
2024-02-05 16:27:41 +01:00
silverqx 1595c4c50a tests used {} instead of QString() 2023-11-10 15:17:49 +01:00
silverqx 8c0a9a870a bugfix column aliases quoting
- added unit tests
2023-10-31 15:27:31 +01:00
Alonso Schaich 2a23991ae5 Include exception headers (#17)
include exception headers (silverqx/TinyORM#16)

The querybuilders' unit tests fail to compile due to some Exception
classes being undefined if ORM compilation is disabled via cmake.

The undefined exceptions are actually being built as part of the
querybuilder. However, the unit tests deep-end on models/user.hpp to
include the header files for the exception classes they are using,
but the corresponding include directive is skipped for builds that
disable ORM.

Close #16
---------

Co-authored-by: Silver Zachara <silver.zachara@gmail.com>
2023-07-24 16:16:23 +02:00
silverqx 16a69ac4d0 used std::addressof() everywhere
Used instead of reinterpret_cast<uintptr_t>(&)
2023-07-11 19:08:00 +02:00
silverqx 6cf15e02fc used a new Progress constant everywhere 2023-07-11 18:00:06 +02:00
silverqx 49e24c0c16 added HASH_ global string constant for "hash" 2023-06-16 15:09:58 +02:00
silverqx c0ff36f0d6 updated comment 2023-05-19 11:43:29 +02:00
silverqx 98282ab66d tests used SIZE_ everywhere
To avoid collisions with Windows header files.
2023-05-07 17:44:53 +02:00
silverqx 29275a7d33 tests bugfix bad overload selected 2023-05-06 14:49:20 +02:00
silverqx 71d6e24e28 used NAME constant everywhere 2023-05-05 14:16:45 +02:00
silverqx 4c9bf9c7e9 added note constant 2023-05-05 14:14:15 +02:00
silverqx 4808d90121 tests formatting 2023-05-05 13:52:25 +02:00
silverqx 1e75726881 tests renamed method 2023-04-04 15:33:49 +02:00
silverqx c0dd5e132d added querybuilder.hpp to databasemanager.hpp
Added the #include querybuilder.hpp to the databasemanager.hpp so
everything will be ready if the user includes db.hpp.
2023-03-15 18:15:17 +01:00
silverqx d64b1adf8c tests added todo task 2023-03-15 15:13:09 +01:00
silverqx 5aa69c88b9 schema added optional column and index keywords
For the MySQL schema grammar added:

 - optional column keyword for add, change, or modify alter operations
 - optional index keyword for fulltext and unique index alter operations
2023-03-15 15:03:27 +01:00
silverqx 326ef2aff2 schema removed primary key index name for MySQL
- added tests
2023-03-15 14:10:15 +01:00
silverqx 9b6cc5d335 tests added section names 2023-03-15 13:04:02 +01:00
silverqx de620f9a5a schema bugfix timestamps precision
- added tests
2023-03-15 11:53:42 +01:00
silverqx 6f221d2030 schema added comment 2023-03-15 09:37:37 +01:00
silverqx acdb9d51f6 tests get search_path from original configuration 2023-03-14 17:30:10 +01:00
silverqx 8097037805 schema modifying columns 🔥🚀🥳
Added the change() method which allows to modify the type and attributes
of existing columns.

 - added renameTo() for MySQL which can be used with the change()
 - added tests
 - updated docs
2023-03-14 16:29:07 +01:00
silverqx b7aa3c8598 tests enhanced and unified modifier tests 2023-03-14 12:48:27 +01:00
silverqx 048ee347ee tests fixtypo 2023-03-14 12:48:26 +01:00
silverqx 8d48a88422 schema finished nullable modifier for MariaDB
MariaDB doesn't support setting a nullable modifier (NULL or NOT NULL)
on generated columns, a query fails if nullable is set. The best that
can be done is to ignore it. 🫤

 - added tests
2023-03-14 12:48:24 +01:00
silverqx 880bc91317 verified MariaDB support 🔥🚀🎉
Added the MariaDB connections and verified and passed all auto tests.
There was not too much to fix. The TLS connections are still not
enabled.

 - fixed upsert
 - fixed tests
 - enhanced upsert tests
 - refactored tst_mysql_qdatetime to be able test both, the MySQL and
   also MariaDB database connections
 - added a few new MariaDB related tests
2023-03-14 12:48:22 +01:00
silverqx 6afbd01b93 schema enhanced generated columns
- refactored PostgreSQL grammar for generated columns
 - unified nullable() on generated columns, now it behaves the same for
   all supported databases and also behaves the same as everywhere else
 - used an optional "generated always as" for all databases instead of
   only "as ()" because it better expresses what it means, "as ()" looks
   very similar like a column alias
 - temporarily disabled logic in MySQL::nullable() for MariaDB, I'm
   going to prepare and set up the MariaDB dev. env. to correctly
   support it, then I will finish it
 - added tests

Others:

 - tests for MySQL and PostgreSQL added tests to test multiple
   auto-increment starting values (startingValue() or from() alias)
2023-03-14 12:48:20 +01:00
silverqx 8ba69dad39 schema changed current_timestamp to lowercase 2023-03-14 12:48:19 +01:00
silverqx 500ab6b257 schema used modifier to set timestamp default
Used TinyORM modifiers to set a default value and for the MySQL also
"on update" value for the datetime and timestamp column types.

Previously, the SQL for a default value and for the "on update" was
generated right away, now, the ColumnDefinition instance is modified
and later in the SQL generation process will be this clauses generated.

 - updated tests, the order of the null value and default values were
   switched
2023-03-14 12:48:19 +01:00
silverqx 208b5cb5a2 tests added datetimes and softDeletesDatetime
Also tested the dropDatetimes() and dropSoftDeletesDatetime().
2023-02-21 13:39:24 +01:00
silverqx 307e899f07 renamed to Blueprint::datetime/Tz()
- also updated docs
2023-02-21 12:38:24 +01:00
silverqx 871bcffd09 allowed to pass expression to pluck()
- added unit tests
2023-02-21 09:21:54 +01:00
silverqx 362be240c6 allowed to pass QueryBuilder to whereExists
Refactored whereExists() to accept the std::shared_ptr<QueryBuilder> and
QueryBuilder &.

 - added unit and functional test
 - updated docs
 - updated all proxies
2023-02-20 16:50:48 +01:00
silverqx 7d0b7af0d7 tests removed comment 2023-02-20 14:14:32 +01:00
silverqx 9ad7b926dc schema added ability to call comment() on SQLite
Added ability to call the table and column comments related code with
the SQLite driver, it do nothing though and it can't throw exception.

 - added unit tests
2023-02-19 18:50:42 +01:00
silverqx 6007d5f3d4 schema added ability to add table comment
The table comment can be added for the MySQL and PostgreSQL databases.
The SQLite database doesn't support it.

 - added unit and functional tests
 - added docs
2023-02-19 18:27:38 +01:00
silverqx 289b688e35 suppressed clang-tidy warning 2023-02-16 16:42:10 +01:00