Commit Graph

435 Commits

Author SHA1 Message Date
Vadim Zeitlin
4d29d9799c Show time taken for the query to fail in "Reconnect" unit test
This allows to confirm that tcp_user_timeout parameter works correctly
for PostgreSQL connections, as specifying different values for it
results in different elapsed time before the query fails.
2025-06-12 02:02:53 +02: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
bdc9798333 Remove checks for MSVC versions older than MSVS 2015
These compilers are not supported anyhow, so remove workarounds for
them.
2025-06-08 00:39:47 +02:00
Vadim Zeitlin
2128706be4 Avoid bogus MSVC warning about unreachable code
The compiler somehow gives a warning about the loop line in this test
being unreachable, even though it clearly is.

Restructure the code to avoid returning from the loop to avoid it.
2025-06-07 18:26:28 +02:00
Vadim Zeitlin
e3606ef196 Stop including <ciso646>
This header is removed in C++20 and we don't need it anyhow any more
since the changes of the parent commit, so don't include it.
2025-05-25 21:28:34 +02:00
Vadim Zeitlin
26475c2ca8 Merge branch 'range-loops'
Use range for loops to simplify the code.

No real changes.

See #1260.
2025-05-25 21:18:19 +02:00
Vadim Zeitlin
746228ccfc Use range-for loops over soci::rowset in the tests
This is simpler than using iterators.

No real changes.
2025-05-23 17:35:23 +02:00
Vadim Zeitlin
fcd5af3e39 Add a test checking that wide strings work with rowset API too
Verify that we can use row-based API for accessing NVARCHAR() columns.
2025-05-23 17:11:33 +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
044826b95c Stop using u8 literals in the Unicode test
This doesn't work when using C++20 as they produce values of "char8_t*"
type which is different from the expected "char*".

Just assume UTF-8 encoding is always used, we already use /utf-8 flag
for MSVC and all Unix compilers should use it too anyhow.
2025-04-25 14:44:25 +02:00
Vadim Zeitlin
93ddffb05f Add functions returning native error description to soci_error
Allow handling backend-specific errors without including
backend-specific headers.
2025-04-23 01:33:23 +02:00
Vadim Zeitlin
a77c689003 Merge branches 'sqlite-errors', 'postgresql-errors' and 'odbc-errors'
Improve error reporting for ODBC, PostgreSQL and SQLite backends, in
particular, provide, or improve, get_error_category() in the exception
classes of all these backends.

See #1235, #1236, #1237.
2025-04-22 20:06:32 +02:00
Vadim Zeitlin
fe29161c2c Add a simple pseudo-test for interactive SQL execution
This can be used to check that an SQL statement results in the expected
error.
2025-04-22 18:55:45 +02:00
Vadim Zeitlin
cf3e73ed3c Add get_error_category() test to PostgreSQL tests
Use this function in at least one of the tests to check that it's not
totally broken.
2025-04-22 17:05:29 +02:00
Vadim Zeitlin
cbb28ed046 Use CHECK_THAT() in PostgreSQL unit tests
This is simpler than manually using strncmp() or string::find().

Omit one negative test, it's not clear what was it actually testing for.
2025-04-22 17:02:01 +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
Robert Adam
caaf5627a1 Support single-quotes for parsing connection strings
Fixes #1210.
2025-03-05 00:45:23 +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
1fde2fab06 Fix CATCH URL
The old page doesn't seem to exist any longer, so just link to GitHub
project page instead.
2025-03-04 17:58:53 +01:00
Vadim Zeitlin
8fe0a20c3f Merge branch 'revamp-cmake' of https://github.com/Krzmbrzl/soci
Rewrite CMake build system to correspond to current best practices.

Fixes #208.
Fixes #394.
Fixes #456.
Fixes #644.
Fixes #843.
Fixes #929.
Fixes #1005.
Fixes #1015.
Fixes #1094.
Fixes #1111.
Fixes #1115.
Fixes #1122.
Fixes #1152.
Fixes #1159.

See #1118.
2025-03-04 17:14:45 +01:00
Robert Adam
41071bff8d Adapt test executable names 2025-02-22 17:37:10 +01:00
Vadim Zeitlin
23d79e9c5f Add C++20-like soci::ssize() helper
Use it instead of static_cast<int>(x.size()): this doesn't change
anything but is shorter and less ugly.
2025-02-05 16:19:40 +01:00
Robert Adam
2769d0b7f2 Remove last remaining bare Makefiles 2025-02-02 10:10:48 +01:00
Robert Adam
249ddbd91d Remove redundant (unused) test files 2025-02-02 09:22:53 +01:00
Vadim Zeitlin
785562114c Add bulk operation section to "Insert error" test
Check that the values of the vectors elements that resulted in the error
appear in the output too, at least for the backends that have been
already updated to do it (i.e. none yet, but some of them will be soon).
2025-01-30 20:22:38 +01:00
Vadim Zeitlin
a9f8260a33 Make "Insert error" unit test more precise
Check for the exact fragment expected and not just a single word.

Also use REQUIRE_THAT() instead of CAPTURE() + CHECK() combination, this
is simpler and provides the same information (arguably more clearly).
2025-01-30 20:22:38 +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
37535c2a8c Tighten the checks in get_affected_rows() unit tests
Check that a partial update does throw an exception instead of checking
that it may throw it and check that get_affected_rows() returns the
actual number of affected rows instead of returning something non zero.

The only remaining exclusion is the PostgreSQL ODBC driver which just
seems to be buggy, notably in its versions < 13.02 when it inserted
valid rows into the database but still returned fatal error (with later
versions it doesn't insert anything, which is inconsistent with the
other drivers and unhelpful, but not quite as bad).
2025-01-29 00:28:19 +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
Robert Adam
2cd6349220 Make common test actually be part of common-tests 2025-01-26 19:24:15 +01:00
Robert Adam
f9c540821f Merge remote-tracking branch 'upstream/master' into revamp-cmake 2025-01-26 19:03:27 +01:00
Robert Adam
6dd0afb9ce Allow to row::get blob into suitable containers
"Suitable" means that the soci::is_contiguous_resizable_container is
specialized to have true "value" member. This specialization is provided
for std::string and std::vector<T> where sizeof(T) == sizeof(char).

This restores compatibility with the existing code and allows to read
BLOB data into a string again.

Fixes #1173.

Closes #1189.
2025-01-24 16:46:52 +01:00
Vadim Zeitlin
1f681d9578 Merge branch 'oracle-clob'
Fix support for non-ASCII characters in Oracle CLOBs.

See #1184.
2025-01-24 16:45:58 +01:00
Vadim Zeitlin
798b513ef0 Merge branch 'odbc-complex-query'
Try to make some complex queries work in ODBC backend.

See #1182.
2025-01-24 16:45:26 +01:00
Vadim Zeitlin
ee72345f6e Merge branch 'wstring'
Add std::wstring support for ODBC backend.

See #1179.
2025-01-24 16:45:11 +01:00
Vadim Zeitlin
12a3942695 Merge branch 'sqlite-enable-fks'
Enable foreign keys in SQLite tests to make the behaviour more
compatible with the other databases by default.

See #1195.
2025-01-24 16:36:16 +01:00
Vadim Zeitlin
4dc06859f9 Merge branch 'mssql-tinyint'
Work around vector int8_t unit test failure with FreeTDS: due to a bug
in the current versions of FreeTDS ODBC drivers, negative TINYINT values
are stored as positive values in the database and so sorting by them
doesn't work, even if reading them back does work.

The issue (https://github.com/FreeTDS/freetds/issues/627) was fixed in
the latest FreeTDS version, but for now work around it in SOCI tests to
let them pass even with older ones.

See #1194.
2025-01-24 16:33:02 +01:00
Robert Adam
dc4815cac1 Implement session::get_last_query_with_context()
Allow retrieving the last query with the parameter values used for them.

See #678.

Closes #1027.

Closes #1164.
2025-01-24 16:24:59 +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
c7932d2a2a Work around bug in int8_t support when using SQL Server
Negative values saved to the database are stored as positive numbers in
at least some versions of the database, so even if they're converted
back to the negative ones when we read them back, ordering the result
set by them doesn't work as expected, see #1193.

Until this can be fixed, work around this by sorting the values in the
test itself instead.
2025-01-21 00:37:33 +01:00
Vadim Zeitlin
601504ce9e Improve errors in vector int8_t unit test
Output the values as integers and not characters, as was the case
before, in case of test failure.
2025-01-21 00:37:04 +01:00