Commit Graph

3243 Commits

Author SHA1 Message Date
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
Vadim Zeitlin c5678e172b Merge branch 'doc-updates'
Minor documentation updates.

See #1181.
2024-11-19 20:02:18 +01:00
Iqbal Hassan 2316c103e5 Avoid Oracle errors for OCI_DESCRIBE_ONLY for non-SELECTs
Don't do anything in prepare_for_describe() if the statement is not a
SELECT, as it is not necessary and results in "ORA-24333: zero iteration
count" error, since there's nothing to describe.

This commit is best viewed ignoring whitespace-only changes.

Closes #1119.
2024-11-17 20:39:18 +01:00
Vadim Zeitlin 24b37bf563 Update change log with more changes since the last release 2024-11-17 17:35:12 +01:00
Vadim Zeitlin b836a368dc Add more contributors and update the maintainer
Add Robert and Lukas to the contributors page and document myself as
being the current maintainer.
2024-11-17 17:34:28 +01:00
Vadim Zeitlin 6fd701e005 Use HTTPS link to the contributors page in the docs
Avoid HTTP in 2024.
2024-11-17 17:34:08 +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
Vadim Zeitlin ee5ce98b07 Merge branches 'oracle-fixes' and 'more-ubsan-fixes'
Fixes for UB in Firebird and Oracle backends and other Oracle fixes for
non-ancient Oracle versions.

See #1177, #1178.
2024-11-10 16:11:32 +01:00
Vadim Zeitlin a339894578 Avoid allocating Oracle LOBs unnecessarily for null values
This doesn't help with the problem corrected in the previous commit but
it still seems unnecessary to allocate LOBs which should be never used
because the corresponding indicator is null.
2024-11-09 23:35:59 +01:00
Vadim Zeitlin e92e6d1dae Fix Oracle XML tests with non-ancient Oracle versions
Although the test passed with Oracle 11 used in the CI job, it fails
with both (old) Oracle 18 and latest Oracle 23 because using xmltype()
with null values doesn't work.

Avoid doing it by testing for null explicitly in the test.
2024-11-09 23:35:59 +01:00
Vadim Zeitlin 115663a2ff Ensure that we stop on error when using UBSAN
Otherwise the errors reported by it could remain unnoticed, as happened
with the UB detected in Oracle backend.
2024-11-09 23:34:59 +01:00
Vadim Zeitlin 7ad6c66486 Don't pass null pointers to memcpy() in Firebird blob code
This is similar to 96668e9a (Don't pass null pointers to memcpy() in
trivial_blob_backend code, 2024-10-16) and done for the same reason:
when there is no data to read/write, the buffer pointer may be null and
passing it to memcpy() triggers UBSAN error, so avoid doing it.
2024-11-09 23:34:08 +01:00
Vadim Zeitlin b3fac52b10 Avoid accessing uninitialized type variable in Oracle classes
oracle_standard_into_type_backend::type_ may not be initialized when
clean_up() is called, and comparing its value with x_xmltype and other
constants was triggering undefined behaviour in this case, so avoid
doing it by checking if ociData_ is non-null before doing it.

Also modify oracle_standard_use_type_backend in a similar way, even if
it doesn't suffer from this problem, for symmetry.
2024-11-09 23:33:55 +01:00
Vadim Zeitlin 1a6607bc2f Remove manual connection string parsing from PostgreSQL backend
Use connection_parameters instead for simplicity and correctness: this
fixes the equivalent of #1175 in this backend too.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin 1e084138aa Add connection_parameters::build_string_from_options()
For now this will be only used to create the connection string in libpq
format, but might be used for the other backends too in the future, so
add it to the core.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin 7739a042bd Add connection_parameters::extract_option()
This is similar to get_option() but removes the option from the
connection parameters and will be used in PostgreSQL backend, which
needs to pass the string with only the options known to libpq, but not
those specific to SOCI, when opening the database connection soon.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin ff20d620c8 Add connection_parameters::is_true_value()
Extract this function from SQLite3 backend, as it will be useful in the
other ones too, and also change it to use case-insensitive comparison.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin c5cc10eaee Extract case conversion functions to a header
Even though these functions are trivial, still collect them in a single
place instead of repeating them in several different ones.

This will also make replacing them with something less trivial, e.g.
using ICU, simpler in the future.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin ce6066e06a Remove remaining SOCI_POSTGRESQL_NOSINGLEROWMODE checks
We don't support ancient versions of PostgreSQL without single row mode
support, so don't bother checking whether it is available.

This should have been part of e3bb60e1 (Remove vestigial traces of
SOCI_POSTGRESQL_NOSINLGEROWMODE, 2024-03-27).
2024-11-09 22:37:13 +01:00
Vadim Zeitlin 9e2faf4526 Correct example of PostgreSQL connection string
Use something in valid PostgreSQL syntax, i.e. space, and not semicolon,
separated and using "dbname" instead of "database".
2024-11-09 22:37:13 +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 11173788a5 Allow options without values in connection strings
At least some backends, e.g. SQLite3, allow specifying boolean options
without parameters to enable them (e.g. just "readonly" instead of
"readonly=1") and this seems to makes sense, so do allow such syntax.

However still forbid values without names, e.g. "=1", which was silently
allowed before even though it didn't make any sense.

Also effectively inline getWordUntil() into the function calling it, as
it makes it simpler to distinguish between having a value and not.

Adjust the tests to the new behaviour.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin ae5ec3b7df Reuse cstring_to_unsigned() in Oracle backend code
Replace the use of std::istringstream with the SOCI function which is
marginally more efficient but, more importantly, more correct, as it
checks for overflow.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin 53370cc356 Reuse common connection_parameters function in Oracle backend
Replace the use of Oracle-specific get_key_value() with the common
extract_options_from_space_separated_string() to ensure consistent
behaviour across the backends and fix a bug with dereferencing an
invalid iterator (one past end) in Oracle-specific code.

Closes #1175.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin 04d7d8e5be Move parsing space-separated strings to connection_parameters
Move code present in Firebird backend, which is just one of several
different versions of the code doing the same thing, into a common core
class to allow reusing it in the other backends later.

Also add tests for this code now that it is actually testable.
2024-11-09 22:37:13 +01:00
Vadim Zeitlin bf840edf79 Remove stray debug output from Oracle unit test
Don't spam stdout with buffers values.
2024-11-09 17:51:00 +01:00
Vadim Zeitlin cdf10ab41b Merge branch 'split-tests'
Split monolithic header containing all backend-independent tests into
multiple source files to minimize rebuilds when working on tests.

See #1174.
2024-11-07 01:05:59 +01:00
Vadim Zeitlin 6e34edf882 Extract manual tests not run by default into their own file
No real changes, just move more tests in a separate file.
2024-11-06 17:39:54 +01:00
Vadim Zeitlin 2f1949acc5 Use WARN() instead of manual output to std::cout
Make this test more consistent with the other ones.
2024-11-06 17:39:24 +01:00
Vadim Zeitlin 247958d2fc Extract rowset-oriented tests in a separate file too
No real changes, just move the tests in their own file.
2024-11-06 17:35:39 +01:00
Vadim Zeitlin 74b7e9ce36 Don't use the common fixture in a test not using the database
No real changes, just a small simplification.
2024-11-06 17:31:49 +01:00
Vadim Zeitlin 1ec7ec505d Extract LOB and XML tests in their own file too
No changes, just move the tests to a separate file.
2024-11-06 17:30:55 +01:00
Vadim Zeitlin 30a9612784 Extract "dynamic" and ORM tests in their own file too
This is similar to previous commits and moves out more tests from the
common tests file.

This commit is best viewed using Git --color-moved option.
2024-11-06 15:48:26 +01:00
Vadim Zeitlin 40cb91756f Extract CHECK_EQUAL_PADDED() in its own header too
This prepares for its reuse elsewhere.

Note that ideally the checks using this macro should be rewritten to use
CATCH matchers instead, which would result in much better output in case
of a failing test, but for now don't change anything and just move the
code around.
2024-11-06 15:48:26 +01:00
Vadim Zeitlin e4bfefda1c Extract all Boost tests in their own file
No real changes, just further improve the physical tests structure.
2024-11-06 15:48:23 +01:00
Vadim Zeitlin b22ae661b4 Move other ASSERT_EQUAL_XXX macros to a header too
Prepare for reusing them from other source files.

Note that this requires using test_context from test-assert.h, which now
has to include test-context.h.
2024-11-06 15:48:04 +01:00
Vadim Zeitlin 5b4e49785a Start splitting common tests in multiple files
Extract tests using custom MyOptionalString type into a separate file.

This commit is best viewed using Git --color-moved option.
2024-11-06 15:14:28 +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 72cdda53a1 Don't use common_tests fixture in timegm unit test
This is unnecessary, this test doesn't use the database at all.
2024-10-29 21:22:36 +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 55f3988382 Remove function_creator_base
This class seems to be completely useless, it's used by function_creator
in PostgreSQL test only, so just inline it there.
2024-10-23 00:40:08 +02:00
Vadim Zeitlin 43cc67276b Move procedure_creator_base to Oracle test
This class is only used there, so don't define it in the common header.
2024-10-23 00:39:36 +02:00
Vadim Zeitlin 3cb528249e Remove unnecessary use of file(GLOB) in CMake
It doesn't seem useful to use GLOB without any widlcards, so replace it
with just set().
2024-10-23 00:34:44 +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
Vadim Zeitlin a55c80984a Define SOCI_FIREBIRD_SOURCE in all Firebird source files too
One of them was missing this definition, resulting in using inconsistent
linkage for Firebird backend symbols under Windows.
2024-10-16 18:13:29 +02:00
Vadim Zeitlin 86a7d8c137 Define SOCI_ORACLE_SOURCE in all Oracle backend source files
This definition was missing from blob.cpp and used wrong case in a few
other files, which didn't matter until recent changes exporting Oracle
backend classes, but results in link errors under Windows now.
2024-10-16 17:45:25 +02:00
Vadim Zeitlin 2ce816bc13 Merge branch 'add-ubsan'
Fix problems flagged by UBSAN and enable it for the CI builds.

See #1172.
2024-10-16 17:22:16 +02:00
Vadim Zeitlin 80128a18d1 Enable UBSAN for all non-Ubuntu 18.04 CI builds
UBSAN gives nonsensical errors for the ODBC job running under Ubuntu
18.04, e.g. it complains that

src/core/session.cpp:246:16: runtime error: member call on address
0x607000000250 which does not point to an object of type
'session_backend'
1: 0x607000000250: note: object is of type 'soci::odbc_session_backend'

which doesn't make any sense because odbc_session_backend is an object
of type session_backend. But apparently something is broken in this
compiler version, so disable UBSAN for this job for now.
2024-10-16 17:11:43 +02:00