Commit Graph

414 Commits

Author SHA1 Message Date
Vadim Zeitlin
42c80b61ca Fix bug in cstring_to_integer() for out of range inputs
Check for ERANGE which is the only way to detect a value out of range of
long long type.
2026-04-28 00:35:05 +02:00
Vadim Zeitlin
632b822775 Remove rowset_iterator post-increment operator
It doesn't make sense for an input iterator and didn't work correctly.

Closes #1327.
2026-03-18 16:33:40 +01:00
Vadim Zeitlin
8815d157ba Merge branch 'fix-values-indicator-use' of github.com:Innokentiy-Alaytsev/soci
Fix propagation of NULL indicators in the soci::values::set() function.

See #1337.
2026-03-16 13:26:13 +01:00
Innokentiy Alaytsev
b5603b93d1 Fixed propagation of NULL indicators in the soci::values::set() function
Originally, the indicator passed by the user was copied into a stored-for-later
variable. This value could have been overwritten during conversion of the bound
parameter to its base type.

Signed-off-by: Innokentiy Alaytsev <alaitsev@gmail.com>
2026-03-16 16:19:13 +04:00
Vadim Zeitlin
e61ac187e1 Get rid of soci/fmt.h hack
Provide soci_error constructors taking a format string and an argument
instead.

This is still unsafe, because we lose the compile-time check of the
format string, but is slightly less ugly than defining format() in our
own namespace.
2026-03-16 00:38:18 +01:00
Vadim Zeitlin
b5855d1d67 Initialize soci_error::info_ in its declaration
No real changes.
2026-03-16 00:36:33 +01:00
Innokentiy Alaytsev
01b8b8d586 Fix an incorrect soci::use function overload
Previously an overload of the soci::use function accepted a value of
type T and a vector of indicators. This function worked when T was
std::vector<U>, but would fail if T was any other type. Judging by the
comment, the original intent was to have an overload for std::vector<T>.

Closes #1334.

Closes #1336.

Signed-off-by: Innokentiy Alaytsev <alaitsev@gmail.com>
2026-03-14 19:43:35 +01:00
Vadim Zeitlin
86a7263ce8 Drop not working into() overload taking buffer size
This was supposed to allow reading into char[N] but either was never
implemented or got broken a long time ago and doesn't seem really useful
compared to using std::string with into(), so simply remove this
overload.

Closes #1332.

See #1333.
2026-03-14 19:41:57 +01:00
Matheus Gabriel Werny
1d9e706303 Overload session::get_next_sequence_value() for std::int64_t too
This is similar to 66baded2 (Overload session::get_last_insert_id() for
std::int64_t too, 2026-01-24) and done for the same reasons.

Closes #1331.
2026-03-14 19:40:56 +01:00
Vadim Zeitlin
7d5ec3510f Merge branch 'postgres-fix-empty-fetch'
Fix behaviour of fetch() when there is no data to fetch for all
backends (it only worked correctly for ODBC and SQLite before).

See #1330.
2026-03-14 19:36:31 +01:00
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
c59f23412a Simplify Oracle error reporting
Instead of calling throw_oracle_soci_error(), add oracle_soci_error ctor
taking the parameters that were passed to this function and just throw
the object created using this ctor.

This is more explicit and simpler.

No real changes.
2026-02-06 02:27:12 +01:00
Vadim Zeitlin
b2e4cf3c27 Replace use of std::stringstream in Firebird backend with fmt
This also fixes compilation error due to not including <sstream> any
more after the changes of a7b02446 (Merge branch 'use-fmt', 2026-01-15).

See #1321.
2026-02-01 16:15:43 +01:00
Vadim Zeitlin
42e2ace6a8 Use fmt::format() instead of std::ostringstream
Simplify dynamic string construction code by using fmt::format().

There should be no changes in behaviour.
2026-01-14 23:40:06 +01:00
Vadim Zeitlin
a6bc44cb15 Drop MSVS 2015 support
It's not worth keeping supporting any more and this will make using fmt
library simpler.
2026-01-14 23:25:37 +01:00
Vadim Zeitlin
99bf94688b Use range-based loops when possible
Run clang-tidy with modernize-loop-convert check to convert a few loops
to a simpler and tidier form.
2026-01-14 15:47:24 +01:00
Vadim Zeitlin
f7a1a05913 Use nullptr instead of NULL or 0
Run clang-tidy modernize-use-nullptr check on all files and manually
change the remaining NULLs skipped by it to nullptr.

Also use nullptr in the documentation.
2026-01-14 14:24:39 +01:00
Vadim Zeitlin
739815ba08 Initialize statement_impl::definePositionForRow_
It was not obvious that this member variable couldn't be used without
being initialized, so do initialize it to ensure that it always has a
valid value.

Also fix a typo in a related comment.
2026-01-13 23:27:01 +01:00
Vadim Zeitlin
4445095407 Merge branch 'odbc-parent-window-option'
Add ODBC parent window option.

See #1312.
2025-11-16 17:32:12 +01:00
Vadim Zeitlin
1a98238fc2 Add odbc.parent_window option for ODBC connection dialogs
This allows to specify the window to be used as parent for the dialog
that can be shown by the ODBC driver to ask for missing information,
which can be useful to ensure that this dialog stays in front of the
application window instead of being hidden beneath it.
2025-11-16 17:31:54 +01:00
Vadim Zeitlin
6e997c9186 Merge branch 'fix-session-leaks'
Fix resource leaks which could happen if backend session object ctor
threw an exception.

See #1314,

Closes #1148.
2025-11-14 14:10:48 +01:00
Vadim Zeitlin
40424b81b1 Don't terminate the application on errors during disconnection
Make sure no exceptions can escape from session class dtor as this would
result in an immediate application termination due to throwing from a
(implicitly) noexcept function.

Let exceptions escape from the backend session classes dtors for those
of them that throw from them: as these classes are private, this
shouldn't affect any existing code and allows these exceptions to still
be reported if they happen when session::close() is called.

Also document that close() may throw and should be called by the
application if handling errors during clean up is important for it.

Closes #1313.
2025-11-13 20:37:20 +01:00
Vadim Zeitlin
5ad50504a7 Fix ODBC handle leaks in case of unsuccessful connection
SQLHENV and SQLHDBC handles stored in odbc_session_backend member
variables were never freed if the ctor threw an exception because the
dtor, freeing them, was not called in this case, resulting in memory and
resource leaks.

Fix this by wrapping these handles in a simple struct freeing them
automatically, as members dtors are always called if they had been
constructed successfully.
2025-11-13 17:47:04 +01:00
Vadim Zeitlin
136a3ae961 Fix possible trace file leak in PostgreSQL backend
If connecting to the database fails, postgresql_session_backend dtor is
not executed and traceFile_ could be leaked.

Fix this by using a unique_ptr<> with a custom deleter to store the file
pointer: this ensures that it is closed in any case.
2025-11-13 17:20:12 +01:00
Vadim Zeitlin
b0bcc218c9 Add support for storing completed ODBC connection strings
This can be used to avoid prompting the user to enter their credentials
multiple times.
2025-09-20 17:26:06 +02:00
Vadim Zeitlin
d0807f40a6 Define soci::ssize() for C arrays too
It might be better to replace arrays with std::array but for now just
make it possible to use ssize() in the existing code.
2025-09-20 17:26:06 +02:00
Vadim Zeitlin
48113873ec Reuse soci_mutex_t in connection_pool implementation too
Also use soci_scoped_lock to ensure that the mutex is always unlocked.

This simplifies the code and fixes a couple of potential bugs where the
resources were not cleaned up properly if an exception happened.
2025-09-20 16:35:52 +02:00
Vadim Zeitlin
e1b841f5bd Use unique_ptr<> for connection_pool::pimpl_
Also don't duplicate connection_pool ctor and dtor in POSIX and Windows
branches as they are exactly the same for both of them.

No real changes.
2025-09-20 16:27:43 +02:00
Vadim Zeitlin
118a519d62 Extract soci_mutex_t into its own private header
This will allow reusing it from other SOCI files.

Also renamed scoped_lock to soci_scoped_lock for consistency.

No real changes.
2025-09-20 16:12:27 +02:00
Vadim Zeitlin
64c2d2fcb9 Add connection_parameters::has_option() for convenience
Sometimes it is necessary just to check whether an option is given (e.g.
to avoid overwriting it in this case) and has_option() was inconvenient
to use in this case as it required defining a dummy string variable.

Make it possible to do this easily with has_option().
2025-09-20 16:11:44 +02:00
Derek Huang
018e532382 Consistently define SOCI_DLL and export macros in all builds
Make sure the macros are consistently defined.

Also define SOCI_SOURCE and SOCI_$BACKEND_SOURCE at CMake level to
make sure they are always defined.

Closes #1273.
2025-08-19 20:12:05 +02:00
Vadim Zeitlin
143f302bb2 Remove insignificant trailing whitespace from source files
No real changes.
2025-08-13 18:07:15 +02:00
Vadim Zeitlin
602fc4b213 Fix a typo in a comment for connection_parameters::backendRef_
No real changes.
2025-07-24 23:06:45 +02:00
Vadim Zeitlin
6728849259 Disable MSVC "unreachable code" warnings at CMake level
Not only the compiler seems to give this warning for just a simple
unconditional "throw", but it also has started giving it in a previously
warning-free code, probably due to a micro version update on GitHub CI.

Fighting against is becoming really ridiculous, so just suppress the
warning globally and remove the local suppressions for it which are not
needed any more.
2025-07-24 22:09:02 +02:00
Vadim Zeitlin
add463ba73 Don't put semicolon inside SOCI_UNUSED() macro
This was inconsistent with the other statement-like macros in SOCI
itself and globally unusual.

Add semicolons to a couple of places where they were not used (they
already were in a couple of other ones).

No real changes.
2025-06-13 17:43:02 +02:00
Vadim Zeitlin
a2f8d61242 Get rid of SOCI_INT8_T_IS_CHAR too
As we can't specialize exchange_traits<> for both int8_t and char when
they are the same type (which is the case under Solaris, see #1154),
specialize exchange_traits<> for some wrapper type in this case to avoid
compilation errors.

This is an alternative, and simpler, solution than that of #1170, so we
can now remove soci_are_types_same CMake function.
2025-06-13 01:31:08 +02:00
Vadim Zeitlin
424b3c22eb Fix remaining hardcoded types in type_conversion<>
This should have been part of the parent 185feedb (Remove
SOCI_INT64_T_IS_LONG and the test for it in CMake, 2025-06-12) which
forgot to replace the types inside type_conversion<> specializations for
soci_l_or_ll_t and its unsigned equivalent with these types.

See #1277.
2025-06-13 01:31:08 +02:00
Vadim Zeitlin
185feedba0 Remove SOCI_INT64_T_IS_LONG and the test for it in CMake
We can replace preprocessor checks for SOCI_INT64_T_IS_LONG with simpler
logic if we assume that int64_t is always either "long" or "long long",
which seems to be true in practice, so do it and remove duplicated
specializations for "long" and "long long" in several places.
2025-06-12 22:01:44 +02:00
Vadim Zeitlin
cb258f3653 Add postgresql_session_backend::deallocate_all_prepared_statements()
This allows to use set_deallocate_prepared_statements(false)
temporarily, which makes it usable even in the long-running programs
which shouldn't let the resources accumulate on the server without ever
freeing them.
2025-06-12 16:47:17 +02:00
Vadim Zeitlin
9a3846dcd3 Add possibility to skip deallocating prepared statements
This can take a surprisingly long time, so let programs that terminate
quickly skip doing this, as it will be done anyhow when session is
closed.
2025-06-12 16:47:17 +02:00
Vadim Zeitlin
3f8d4c9398 Add "tracefile" connection parameter to PostgreSQL backend
Using this parameter allows to enable tracing of all database calls,
which can be useful for diagnostic and profiling purposes.

Also add fopen() wrapper to avoid "deprecation" warnings from MSVC.
2025-06-12 16:46:46 +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
85b15d24a6 Get rid of unnecessary SOCI_ALLOW_DEPRECATED_BEGIN/END macros
They were ugly and not really necessary when we can just avoid marking
the functions as deprecated when compiling SOCI itself to allow using
them from the implementation code.

Also simply remove deprecated attributes from the functions in
blob_backend which is not supposed to be used publicly at all.
2025-06-08 02:30:38 +02:00
Vadim Zeitlin
93c5dc5717 Use C++11 [[noreturn]] attribute directly
Keep SOCI_NORETURN defined just in case somebody uses it in their own
code, but stop using it in SOCI and just use the standard C++11
attribute directly instead.
2025-06-08 00:39:47 +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
35fb25733b Remove unnecessary pragma warning around sqlite3.h inclusion
Newer versions of SQLite/MSVC don't generate any warnings, so there is
nothing to suppress.
2025-06-08 00:39:47 +02:00
Vadim Zeitlin
5d3e3acfc2 Avoid MSVC warnings about truncating "int" to "short"
Switch to using the same "ub2" type as OCI uses for charset codes to
avoid warnings about implicitly truncating "int" to "ub2" when passing
charset parameters to various OCI functions.
2025-06-08 00:39:47 +02:00
Vadim Zeitlin
7ee9beadc4 Remove unnecessary MSVC pragmas disabling C4511 and C4512
Neither of these warnings (corresponding to copy ctor and assignment
operator not being synthesized by the compiler) are generated any
longer, so there is no need to suppress them.
2025-06-08 00:39:00 +02:00
Vadim Zeitlin
f2cad0bd74 Simplify checks for "long" type size
We don't need to determine sizeof(long) at configure time when we can do
it directly during the build using std::conditional<>.

Also merge the identical specializations of various types for long in 32
and 64-bit cases.
2025-06-07 20:04:45 +02:00
Vadim Zeitlin
a7023d3363 Stop testing for never used SOCI_VISIBILITY_ATTRIBUTE_SUPPORTED
We always assume that visibility is supported under ELF platforms now,
see f90a1bf3 (Unconditionally set the visibility preset to hidden,
2025-02-06).
2025-06-07 19:56:16 +02:00