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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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().
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
__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.
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.