Commit Graph

425 Commits

Author SHA1 Message Date
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
Robert Adam
5bd4138287 Centralized backend list; AsAvailable->AUTO 2025-01-09 18:57:18 +01:00
Robert Adam
c2d0d152b8 Don't include test-main.cpp in unity builds 2025-01-03 16:13:50 +01:00
Robert Adam
c88da3b62c Merge remote-tracking branch 'upstream/master' into revamp-cmake 2025-01-03 16:05:52 +01:00
Vadim Zeitlin
5e9f200001 Read entire Oracle CLOB and not just its length in characters
We need to read the entire contents of the CLOB in Oracle backend and
not just the number of bytes corresponding to its length in characters
as returned by OCILobGetLength() because this may (and will) be strictly
less than its full size in bytes for any encoding using multiple bytes
per character, such as the de facto standard UTF-8.

Also make reading CLOBs more efficient by doing what Oracle
documentation suggests and using the LOB chunk size for reading.

Finally, add a unit test checking that using non-ASCII strings in UTF-8
(which had to be enabled for the CI) with CLOBs does work.

This commit is best viewed ignoring whitespace-only changes.
2024-11-20 00:35:15 +01:00
Vadim Zeitlin
2b9afba3f5 Make procedure_creator_base helper more flexible and rename it
This will allow to use it for creating functions as well as procedures
(and also procedures with a name other than "soci_test" if this is ever
needed).
2024-11-19 23:29:46 +01:00
Vadim Zeitlin
d089386a18 Move table creator helpers to the start of Oracle test
No real changes, just make it possible to use these helpers in the unit
test to be added.

This commit is best viewed using Git --color-moved option.
2024-11-19 23:28:40 +01:00
joshua-15639
48a5a6c91e Try to make some complex queries work in ODBC backend
Describe the statement once again after calling execute() if we had
failed to describe it before because SQLNumResultCols() returned 0, as
it may happen with some complex queries and SQL Server used via ODBC
backend.

Closes #1151.

See #1182.

Co-Authored-By: Vadim Zeitlin <vz-soci@zeitlins.org>
2024-11-17 19:42:51 +01:00
Benjamin Oldenburg
982434f170 Add std::wstring support for ODBC backend
Handle wide-strings similarly to how normal strings are already handled.

For now support for them is only available in the ODBC backend.

Also add conversion functions between UTF-{8,16,32} and wchar_t and the
tests for them. Note that some of these functions are not used yet, but
provide the complete set as they probably will be in the future.

Co-Authored-By: Vadim Zeitlin <vz-soci@zeitlins.org>
2024-11-17 16:49:25 +01:00
Vadim Zeitlin
55a98cfff2 Ensure that MSVS handles non-ASCII characters correctly
Unlike all the other contemporary compilers, it needs a special compiler
option (/utf-8) to interpret normal input files, without BOM, in UTF-8.
2024-11-17 02:55:46 +01:00
Vadim Zeitlin
7fb2e519ef Merge branch 'conn-params-improve'
Improvements to connection string handling: don't duplicate parsing code
in Firebird, Oracle, PostgreSQL and SQLite backends.

Also allow using connection_parameters::set_option() to set some option
instead of having to specify it in the connection string itself.

See #1176.
2024-11-10 16:12:08 +01:00