3677 Commits

Author SHA1 Message Date
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
53146495f6 Fix leak of SQLite3 connection handle in case of failure
If an error happened in sqlite3_session_backend ctor, the connection
variable was leaked, as sqlite3_session_backend dtor normally freeing it
was not called in this case.

Fix this by ensuring that we call sqlite3_close() if ctor exits
prematurely. Note that this implies removing call to sqlite3_close()
from check_sqlite_err(), as calling sqlite3_close() twice is invalid.
2025-11-13 18:31:44 +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
800cb397dd Replace extract_driver_complete_option() with extract_soci_option()
Change the function to be more general, by allowing to use it for any
option name and not just odbc_option_driver_complete, and rename it
accordingly.

No real changes.
2025-11-10 16:55:00 +01:00
Vadim Zeitlin
d56932c4e6 Fix exception with multiple batch operations in SQLite3 backend
Don't leave current_row_ with an invalid value after finishing a batch
operation, it could be reused, resulting in an exception due to the
index being invalid, when the statement is executed again.

Note that this was already done for the other backends using
current_row_ in their overridden get_row_to_dump() in a similar way
(Firebird and PostgreSQL), so they were not affected by this bug.

Closes #1308.
2025-10-28 15:24:35 +01:00
Vadim Zeitlin
a599a8569b Define SOCI_ABI_VERSION when compiling SOCI core
Somehow this definition was lost, meaning that the dynamic backend
loader code didn't use ABI_VERSION any longer and tried to load
libsoci_backend.so instead of libsoci_backend.so.SOVERSION as intended
under Unix.
2025-10-28 14:19:39 +01:00
Vadim Zeitlin
088a991e5e Merge branch 'odbc-remember-completed'
Allow remembering completed ODBC connection strings.

See #1304.
2025-09-20 18:08:37 +02: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
0c764fdff1 Increase the buffer size for the completed ODBC connection string
It seems plausible that a completed DSN could be longer than 1KiB as it
may contain more keys than were specified in it originally, so try to
ensure we don't truncate it by increasing the buffer size for it.
2025-09-20 17:13:38 +02:00
Vadim Zeitlin
f69b251885 Fix possible access to uninitialized memory in ODBC backend
If the connection string is truncated, do not read beyond the end of the
buffer, as would happen in this case as the returned string length would
be bigger than the buffer size we passed to SQLDriverConnect().

As we can rely on the string being NUL-terminated, just assign it to
connection_string_ directly.
2025-09-20 17:13:38 +02:00
Vadim Zeitlin
89635b775e Merge branch 'mutex'
Reuse soci_mutex_t and clean up connection_pool implementation.

See #1303.
2025-09-20 17:12:47 +02:00
Vadim Zeitlin
9b5b43a789 Move connection_pool_base_impl to global namespace
gcc 13 (but not 14) gives -Wsubobject-linkage warnings when inheriting
from a base class in an anonymous namespace, so avoid them by moving
this class out from the namespace.
2025-09-20 16:44:26 +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
5b3da80db4 Use std::unique_ptr<> instead of raw session pointers
Simplify connection_pool_base_impl by using std::unique_ptr<> which
ensures that the pointers are deleted, without having to do it
explicitly.
2025-09-20 16:29:02 +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
430a508702 Refactor connection_pool_impl to use more RAII-like approach
Perform resources initialization in the constructor and clean them up in
destructor instead of doing it manually outside of the class containing
the resources.

Also factor out connection_pool_base_impl to avoid duplicating exactly
the same code in POSIX and Windows branches.

No real changes.

This commit is best viewed with Git --color-moved option.
2025-09-20 16:23:57 +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
Vadim Zeitlin
e55d36310a Fix spelling mistakes and typos in the documentation
Pass all the Markdown files through aspell.
2025-09-19 15:21:44 +02:00
Robert Adam
f2414e7509 Rename target SOCI::soci to SOCI::SOCI
We still keep a SOCI::soci target around, which we explicitly mark as
deprecated. This way, code that is already using it will remain
functional but they will be informed that they are supposed to use
SOCI::SOCI instead.

Closes #1297.
2025-08-29 14:33:19 +02:00
Robert Adam
9982e0c37f Turn SOCI::soci into an IMPORTED target
Turning it into an imported interface target makes it disappear from the
command line when linking (which doesn't do anything anyway).

Furthermore, this is beneficial for detecting missing find_package calls
at configuration time rather than at link time.

Closes #1296.
2025-08-29 14:29:07 +02:00
Robert Adam
a4c57625f3 Make multiple find_package calls possible
In cases in which find_package(SOCI) was performed multiple times in a
single configure run (e.g. because two independent dependencies both
depend on SOCI), CMake would error due to the attempted re-definition of
the soci_interface (and SOCI::soci) targets created in SOCI's config
file.

This commit adds a check for the existence of these targets and only
creates them if they don't exist yet. Hence, multiple find_package calls
no longer lead to errors.

Closes #1293.
2025-08-29 14:29:07 +02:00
Vadim Zeitlin
64b1dbdb24 Merge branch 'cmake-windows-fixes' of github.com:phetdam/soci
CMake config Windows fixes.

See #1302.
2025-08-26 18:48:38 +02:00
Derek Huang
f9496daf4d CMakeLists.txt: ensure CMAKE_BUILD_TYPE defaults to non-empty if unset 2025-08-23 05:18:40 -04:00
Derek Huang
533f7abb17 src/CMakeLists.txt: fix typo in comment 2025-08-23 04:09:04 -04:00
Derek Huang
abbbc24606 src/CMakeLists.txt: update comment for clarity 2025-08-23 04:08:16 -04:00
Derek Huang
b5c9ea9a7b CMakeLists.txt: ensure build types are displayed for multi-config generators correctly 2025-08-23 03:48:58 -04:00
Derek Huang
f02cdc95d2 src/CMakeLists.txt: avoid unnecessary rebuilds/update to soci-config.h on Windows
modified:   src/CMakeLists.txt
    Use file(GENERATE) to enforce LF line endings are used consistently, which
    allows us to avoid needless re-writing of soci-config.h on Windows due to
    file(WRITE) using CRLF instead of the LF as expected
2025-08-23 03:34:26 -04:00
Vadim Zeitlin
3907e70b88 Look for backend DLLs dependencies in their own directory first
Use LoadLibraryEx(LOAD_WITH_ALTERED_SEARCH_PATH) to load backend
dependencies from the directory containing the backend DLL itself first,
while still looking in the standard search path if the dependency is not
found there.

This is important to prevent the DLLs found in the application
directory, which is searched before the directory containing the DLL in
the standard search path, from being loaded instead and breaking SOCI
backend.

The motivating example is using SOCI from Microsoft Excel add-in, which
would load OpenSSL libcrypto-3-x64.dll from EXCEL.EXE directory, which
contains an old version of this DLL incompatible with recent libpq.dll
versions and so preventing PostgreSQL DLL, and hence SOCI Postgres
plugin, from being loaded.

See #1301.
2025-08-21 22:20:51 +02:00
Vadim Zeitlin
5262939016 Allow specifying odbc_option_driver_complete as part of the DSN
It is convenient to allow specifying this option as part of the
connection string itself rather than requiring setting it using
set_option(), e.g. like this it can be used in the connection string
used by the CI service without requiring any changes in the code, so
support giving it in this way.

See #1300.
2025-08-21 22:19:15 +02:00
Vadim Zeitlin
ad749aff03 Merge branch 'build-summary'
Minor CMake build summary improvements.

See #1299.
2025-08-21 22:18:25 +02:00
Vadim Zeitlin
fd8147e21d Don't show SQLite3 message about using built-in version repeatedly
Just as with the global summary, only show the message once or if it
changes later, otherwise it's displayed every time CMake is rerun, even
if there have been no changes.
2025-08-20 19:13:30 +02:00
Vadim Zeitlin
abce5acd55 Add custom target to show SOCI build configuration
This can be useful to check how the library was configured later.
2025-08-20 19:13:27 +02:00
Vadim Zeitlin
6fa9eb88ae Remove unnecessary use of $CACHE{} when showing CMake summary
This is just not needed, the variable value is the same as its cached
value (if any) at this point anyhow.
2025-08-20 19:09: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
mkkang
e61bb364d9 Fix truncating wide strings when using NVARCHAR in ODBC backend
ODBC SQLDescribeCol() returns column size in characters, but
SQLBindCol() expects the buffer size in bytes. The existing code failed
to multiply by sizeof(SQLWCHAR), which could result in buffer
truncation, corrupted reads, or subtle bugs when binding to wide
character types such as NVARCHAR.

Fix this by using the size in bytes.

Also update an existing unit test to show the problem: by simply
reducing the buffer size, it could be made to fail without the changes
in this commit.

Closes #1290.

Closes #1292.
2025-08-13 18:21:10 +02:00
Vadim Zeitlin
143f302bb2 Remove insignificant trailing whitespace from source files
No real changes.
2025-08-13 18:07:15 +02:00
Robert Adam
0aa36e3372 Warn against incorrect find_package(SOCI) usage
It can happen that users specify e.g. SOCI_MYSQL CMake variables to
select SOCI backends when using find_package, just as they would when
using add_subdirectory. However, this has no effect which will be very
confusing.

Therefore, we add a check for this in case no explicit components are
given in the find_package call and if we detect any of the SOCI_*
variables corresponding to backends are defined, we emit a warning
referring to the use of find_package(SOCI COMPONENTS …) instead.

Closes #1294.
2025-08-13 17:52:48 +02:00
Robert Adam
09f0cebc95 Fix linking error due to __ImageBase when using MSYS2
__ImageBase should be declared outside of any (even anonymous)
namespaces, otherwise its name is getting mangled even in spite of it
being extern "C".

Closes #1266.
2025-08-13 17:49:34 +02:00
Derek Huang
ce348126e7 Make not finding built-in SQLite3 a fatal error
Use FATAL_ERROR if SQLite3 is not found at all (usually means
--recurse-submodules wasn't used).

See #1273.
2025-08-01 19:44:16 +02:00
Vadim Zeitlin
9347d233a2 Add possibility to specify "builtin" SQLite3 source file path
This can be useful if a superproject wants to force the use of its own
SQLite3 version.

Just prefix the existing variables with "SOCI_" and make them cache
variables to allow pre-setting them before calling add_subdirectory()
from the superproject.
2025-08-01 19:35:44 +02:00
Vadim Zeitlin
4982b0e37b Merge branch 'cmake-affixes'
Add SOCI_NAME_PREFIX and SOCI_NAME_SUFFIX build options to allow using
custom prefix and/or suffix to distinguish custom SOCI builds.

See #1288.
2025-07-27 01:15:39 +02:00
Vadim Zeitlin
c6abf4ab83 Allow customizing SOCI shared libraries names
Add SOCI_NAME_PREFIX and SOCI_NAME_SUFFIX build options to allow using
custom prefix and/or suffix to distinguish custom SOCI builds.
2025-07-24 23:47:43 +02:00
Vadim Zeitlin
0d51b5067f Don't pip with sudo in Circle CI Python image
pip is installed for the normal user only and doesn't work (nor needs)
sudo.
2025-07-24 23:23:52 +02:00
Vadim Zeitlin
121c77a767 Use Circle CI Ruby image with Node
Node is required for this step (it's actually not clear if Ruby is).
2025-07-24 23:16:29 +02:00