Commit Graph

59 Commits

Author SHA1 Message Date
Matheus Gabriel Werny
66baded292 Overload session::get_last_insert_id() for std::int64_t too
It may be more convenient to work with this type than with "long long",
so provide an overload allowing to retrieve the ID as it too.

Closes #1232.

Closes #1325.
2026-03-14 19:33:40 +01:00
Vadim Zeitlin
c35b1b6a77 Avoid disabling MSVC CRT security warnings globally
Use "_s" versions of the standard C functions if possible/simple to do
and disable deprecation warnings explicitly in a couple of places where
this could not be done instead of disabling them globally.

Also stop using strcpy() entirely and use strncpy() instead.

See #1268.
2025-06-08 02:49:21 +02:00
Vadim Zeitlin
4ad4333fd8 Merge branch 'win32-libname-abiver'
Restore ABI version use in Windows DLL names.

See #1252.
2025-05-17 15:05:05 +02:00
Vadim Zeitlin
20325f57c9 Add unit test to check loading backends dynamically
Ensure that loading backend dynamically, i.e. using their name, works.

This required adding a way to get this name from the test context.

See #1250.
2025-05-17 00:33:31 +02:00
Vadim Zeitlin
ec00b69a71 Amendments to the parent commit, changing SQLite timeout setting
This should have been part of the parent commit but got accidentally
left out.

See #1254.
2025-05-17 00:23:00 +02:00
Vadim Zeitlin
53f5e9c340 Implement get_error_category() in sqlite3_soci_error
Try to classify all the possible SQLite result codes using SOCI
error_category enum.

In particular, this allows to detect connection and permission errors.

Update the unit test to test the error category too.
2025-04-22 16:48:44 +02:00
Vadim Zeitlin
62001b2365 Add sqlite3_soci_error::extended_result()
Allow to get the extended error code from SQLite too.

Add a unit test checking that the new function returns the expected
result.
2025-04-22 16:48:44 +02:00
Vadim Zeitlin
2a121b57c4 Rewrite SQLite unit test to use explicit try/catch
Don't use CHECK_THROWS_WITH(), it's convenient but not very flexible,
while an explicit try/catch will allow us to add more checks on the
exception object in the upcoming commits.
2025-04-22 16:48:44 +02:00
Vadim Zeitlin
c2b3b04432 Check that the error message contains the expected substring
Relax the check, there is no need to verify that the message is exactly
the same, we only want to check that the expected parts are there.
2025-04-22 13:59:49 +02:00
Vadim Zeitlin
3bc032dec4 Add sqlite3_session_backend::libversion() and libversion_number()
Use these functions instead of directly using SQLite3 ones in the test.

This makes no real difference, but allows to provide the implementation
of these functions in SOCI SQLite3 backend itself and so works even when
SQLite3 library is linked statically into this backend and is not linked
into the test.
2025-04-11 01:52:33 +02:00
Robert Adam
77c75a4e85 Make SQLite overwrite exchange type for integers
Since SQLite doesn't have a type system, we have to always be prepared
to select huge numbers, even if the "type" is e.g. int8.
To do that, we overwrite the exchange type (e.g. in row based APIs) to
always be (u)int64 for integers to avoid over-/underflows.

Update the documentation to explain this SQLite peculiarity and add a
test verifying that this behaves as expected.

Fixes #1190.

Closes #1217.
2025-03-24 00:14:00 +01:00
Vadim Zeitlin
1a634431bd Update SQLite3 test after the last commit
This should have been part of the parent commit.
2025-03-05 00:55:48 +01:00
Vadim Zeitlin
fb04446e35 Convert most HTTP links to HTTPS
No real changes, but it's not very serious to use HTTP links in 2025.
2025-03-04 18:03:53 +01:00
Vadim Zeitlin
411bb3c077 Make SetupForeignKeys ctor explicit
No real changes, just a very minor cleanup.
2025-01-30 01:11:42 +01:00
Vadim Zeitlin
6939029dd8 Disallow text in int column in SQLite get_affected_rows() test
The unit test relies on failing to insert "a" into an integer column but
SQLite is perfectly fine with doing this by default, so use an explicit
CHECK constraint to prevent this from succeeding and to make it behave
in the same way as the other databases.
2025-01-29 00:28:05 +01:00
Vadim Zeitlin
2a8abbe49f Turn foreign keys on by default for SQLite tests
This makes its behaviour more compatible with the other backends and
will make writing tests relying on FKs working simpler.
2025-01-21 01:50:56 +01:00
Vadim Zeitlin
03a716a688 Don't rely on default pragma foreign_keys value in SQLite tests
SQLite documentation states that it can change in the future and it's
simple enough to turn it off explicitly, so do it.

Also combine 2 very similar tests in a single one and use 2 sections for
them instead.

No real changes.
2025-01-21 01:49:15 +01:00
Vadim Zeitlin
ae2ca287a8 Reuse connection_parameters parsing in SQLite3 backend
Don't duplicate the code for parsing space-separated possibly quoted
words in SQLite3 backend but just use the common function for it too.

Also correct handling of some boolean parameters, where previously
specifying any value, even "0" or "false", would enable it and document
the exact values accepted for them.

Add tests checking that parsing connection string works as expected.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin
0aa2c1f27b Get rid of "soci_use_common_tests" hack
This can be avoided by using a different base test context class for the
non-empty tests.
2024-11-06 14:54:37 +01:00
Vadim Zeitlin
b0ecbca57a Extract common tests in soci_tests_common library
This allows to compile them once, instead of doing it for every backend:
while this doesn't matter for the CI builds, recompiling common-tests.h
a dozen times enormously slowed down local builds using all backends.

Now it is compiled only once, as test-common.cpp, and all the other
tests (except for the "empty" one) just link with the resulting library.

Also extract some parts of this file into separate headers, that can be
included only by the tests that actually need them.

Note that the entire test-common.cpp probably ought to be split into
multiple files, to speed up its build too, but this can be done later.
2024-10-23 13:54:01 +02:00
Vadim Zeitlin
33139741b3 Move roundtrip-tests related helpers to SQLite3 test
This is the only place where they're used so far and it doesn't make
sense to compile them many times over when building the tests for the
other backends.

If these helpers are needed in the other backends tests, we should
extract them into their own header and include it as necessary.
2024-10-22 00:41:23 +02:00
Thibault FRESNET
ce0630b2cd Improve column names to SOCI database types mapping with SQLite3
Use type-appropriate names for the columns, which are still interpreted
in the same way as just "INTEGER" by SQLite3 itself, but can be mapped
back to the suitable types when reading from the database in SOCI.

Closes #1120.
2024-04-24 16:24:40 +02:00
Robert Adam
be4677149e Address review comments 2024-01-16 20:45:30 +01:00
Robert Adam
47d9068366 Special case data type for Oracle backend 2024-01-13 17:09:31 +01:00
Robert Adam
ae75990cb2 finalize common blob test & remove backend-specific ones 2024-01-13 16:46:31 +01:00
Robert Adam
68033e037a Start implementing shared BLOB tests 2024-01-13 16:46:31 +01:00
Robert Adam
7fa93e8586 BLOB: Add default-constructed read tests 2024-01-13 16:46:31 +01:00
Robert Adam
e86da4e712 Extend SQLite BLOB tests 2024-01-13 16:46:31 +01:00
Vadim Zeitlin
07cb45e4a1 Merge branch 'master' into data_types 2024-01-03 00:43:58 +01:00
Thibault FRESNET
1c37a5fe62 Implement prepare_column_descriptions() in SQLite3 backend
Use TABLE_INFO pragma, which can also be used with SELECT, to get the
information about the table columns.

Closes #1079.
2023-10-20 01:06:41 +02:00
Lukas Zanner
88e2cb4ae5 Fix uint64 vector unit tests
Firebird and SQLite store UINT64_MAX incorrectly, leading to an incorrect
value ordering when retrieving sorted table contents.
2023-08-13 17:25:32 +02:00
Lukas Zanner
4c36213928 Remove unsigned type support checks in unit tests
Despite previously assumed and tested, most of the databases support
storing the various unsigned integer values. The checks for it in the
tests are therefore obsolete.
Only Firebird and SQLite seem to have a problem with storing UINT64_MAX.
The retrieval of it in a sorted result set with multiple other values
shows that the value is stored as a signed integer in the database.
2023-08-13 17:25:32 +02:00
Lukas Zanner
367c0c0341 Revert unnecessary changes in unit tests 2023-08-13 17:25:30 +02:00
Lukas Zanner
3d1617085c Replace stdint.h with cstdint 2023-08-13 17:25:29 +02:00
Lukas Zanner
44a4365c6e Update unit tests of SQLite3 backend for complete integer type support 2023-08-13 17:25:26 +02:00
Robert Adam
2d37f99530 BLOB: Make [read|write]_from_start the default impl
The older read(...) and write(...) function, which take backend-specific
offsets rather than uniformly taken 0-based offsets (as is the case for
the *_from_start(...) functions), are now implemented in terms of their
*_from_start counterpart.

All test cases have been adapted to now prefer using the *_from_start
functions over the old counterparts.
2022-09-22 19:57:02 +02:00
Vadim Zeitlin
04c3daf8c3 Drop SOCI_OVERRIDE and use override keyword directly
We don't need the macro any longer now that we use C++14.
2022-09-18 17:28:57 +02:00
Cosmin Cremarenco
9507d084cd Improve get_last_insert_id() for SQLite
Return the ID used for the given table instead of the last ID inserted
in any database table, which could be very different.

This relies on using internal sqlite_sequence table that is used by
AUTOINCREMENT.

Co-authored-by: Vadim Zeitlin <vz-soci@zeitlins.org>

Closes #971.
2022-06-20 19:12:57 +02:00
Cosmin Cremarenco
ae3ff29216 Add support for enforcing foreign keys in SQLite backend
Allow enabling foreign key checking, which is disabled by default in the
current SQLite versions, for the applications that need it using the
appropriate SQLite pragma if the corresponding connection string
parameter is specified.

Closes #968.
2022-05-19 23:51:24 +02:00
Cosmin Cremarenco
d46606432f Add support for XML to SQLite3 backend
SQLite doesn't have any specific XML support, but it can still be stored
in normal TEXT columns, which is better than not supporting it at all.

Closes #966.
2022-05-13 00:15:19 +02:00
Vadim Zeitlin
628ae300d9 Fix unqualified soci::session which broke macOS build
Bare "session" conflicts with a system header on that platform.
2021-04-02 16:16:45 +02:00
Vadim Zeitlin
55736428f3 Run get_last_insert_id() test for SQLite3 backend too
This doesn't cost much and allows to verify that this function works
correctly not just for ODBC backend with SQL Server.
2021-04-02 16:02:26 +02:00
Vadim Zeitlin
d28d6827a9 Fix a number of variable shadowing warnings from MSVS
Don't redefine the same variables in a couple of tests.

In other places, use artificially different names to avoid clashes with
the existing variables in outer scope.

No real changes.
2021-03-12 02:18:02 +01:00
Cavaler
9d58b4d60e Fix detection of "unsigned big int" in SQLite backend
Ignore spaces when checking for known column types. This allows to use
either "BIG INT" or "BIGINT" and also makes the previously broken
"UNSIGNED BIG INT" work too.

Closes #783, #785.
2020-02-10 18:39:57 +01:00
Dirk Vanden Boer
45778f1750 Fixed std::tm bind for sqlite backend (#770)
If C++11 was allowed, std::get_time could be used for parsing the time string
(see https://github.com/SOCI/soci/pull/770#issuecomment-557824145).
2019-11-23 21:50:11 +01:00
Mohan Sella
9d0caa13ca Use 64-bit integer for next sequence and last insert ID values (#720) 2019-06-07 15:00:07 +02:00
Mateusz Loskot
05ab0bcf6d Add SOCI_OVERRIDE macro as conditional C++11 override specifier
MSVC++ 1900+ always compile with C++11 mode enabled, so it should be
safe to selectively enable 'override'specifier for internal use.

It does not enable all C++11 features for SOCI and we still compile
with C++11 compilation mode SOCI_CXX_C11=OFF by default.

Refactoring performed with clang-tidy-4.0:

 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSOCI_CXX_C11=ON ..
 run-clang-tidy.py -clang-tidy-binary -header-filter='.*' \
                   -checks='-*,modernize-use-modernize' -fix
2017-09-24 23:05:06 +02:00
Vadim Zeitlin
63bcc89440 Add workaround for empty strings being null in Oracle
Oracle historically treats empty VARCHAR[2] column values as nulls, so
we need to adjust the string length unit test to provide indicators when
retrieving the value of a possibly null string and use nvl() to compute
its length to make this test pass when using this backend.
2017-09-14 15:03:45 +02:00
Vadim Zeitlin
c6aef12b1e Add test checking string length when using bulk insert
This used to be broken, so add a test to check that it works after the
changes of the last commit and to avoid breaking it again.
2017-07-22 01:18:03 +02:00
Maciej Sobczak
e7194837e5 Added empty_blob() and nvl() to portable utilities. 2016-10-17 22:12:37 +02:00