Commit Graph

3732 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
8f5245bbcd Stop using ostringstream for errors in SQLite3 backend code
Use fmt::format() to build them directly instead, this is much simpler.

Also get rid of useless and trivial check_sqlite_err() function to
simplify the code a bit more.
2026-04-28 00:15:28 +02:00
Vadim Zeitlin
37f9aa7e20 Use std::ostringstream for a write-only stream
Just small clean up: don't use stringstream when we really need just an
ostringstream.
2026-04-27 23:59:39 +02:00
Vadim Zeitlin
9ff0998296 Improve parsing of "timeout" parameter in SQLite backend
Use SOCI cstring_to_integer() instead of std::istringstream and throw an
exception if an invalid value is specified for this parameter.
2026-04-27 23:59:39 +02:00
Vadim Zeitlin
4131025e8b Stop using std::istringstream for parsing numbers in MySQL backend
Use SOCI cstring_to_xxx() functions for consistency with the other
backends and because they should also be more slightly more efficient.
2026-04-27 23:51:06 +02:00
Robert Adam
897dac8f9c Allow multiple find_package(SOCI) calls in application using SOCI
We now only define our targets if they don't exist yet to avoid errors
due to redefining them if find_package(SOCI) is done more than once.

Note that multiple calls to find_package(SOCI) that specify different
components will cause all call-sides to use the superset of all
requested components as targets are global (and hence also their link
dependencies).

Fixes #1344.

See #1346.
2026-03-19 16:41:35 +01:00
Robert Adam
a414380ed2 Use new SQLite target name for newer CMake versions
Use SQLite3::SQLite3 instead of SQLite::SQLite3 with CMake >= 4.3 to
avoid warnings about using deprecated name.

Fixes #1343.

See #1345.
2026-03-19 16:41:18 +01: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
1bf4734cda Update actions/checkout version to 5 in GitHub CI workflows
v4 will stop working soon (on 2026-06-02) as it's based on Node 20.
2026-03-16 21:47:58 +01:00
Vadim Zeitlin
2bce85b797 Always use bundled fmt as header-only library
Using header-only library for static build and building shared library
for shared build was inconsistent and the rationale given for avoiding
creating a separate library for the static build also applies in the
latter case too, so just always use header-only fmt variant to avoid
imposing extra linking requirements on SOCI users.
2026-03-16 21:39:38 +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
Vadim Zeitlin
1f86b60156 Merge branch 'cxx20'
Fix C++20 build and test it in the CI.

See #1340.
2026-03-16 13:25:02 +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
Innokentiy Alaytsev
56311049a2 Added tests for indicator processing by soci::values
The tests are expected to fail, because the value of an indicator, passed to the
soci::values::set() function is replaced with the value returned from the
type_conversion::to_base() function. Since it is possible that a valid value was
passed alongside the i_null indicator, e.g., for setting an integer field to
NULL, the type_conversion::to_base() function might return i_ok, as the default
implementation of the function does.

The problematic behaviour is not detected by the existing tests.

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
Vadim Zeitlin
f1ece53e60 Use C++20 for one of the CI builds
Use Valgrind build for testing this.
2026-03-16 00:31:50 +01:00
Vadim Zeitlin
d20057cdbb Fix compilation of soci::format() with C++20
Non literal strings can't be used with fmt::format() when using C++20,
so use fmt::vformat() instead.

This is ugly and unsafe, upcoming commits will provide a better fix, but
for now at least make the library compile in C++20 again.
2026-03-16 00:27:35 +01:00
Vadim Zeitlin
2d1dfa4107 Use existing fmt::fmt target if it's already defined
This can happen when the library is used as a sub-project by a
super-project also using fmt and we don't need to do anything in this
case (and doing anything would be actively harmful as we could either
not find fmt at all or find a wrong version of it).
2026-03-15 23:57:08 +01:00
Vadim Zeitlin
8c20fa3321 Add SOCI_INSTALL to allow disabling install-related stuff in CMake
This is not necessary when using the library as a sub-project and may
result in problems, so allow turning it off completely.
2026-03-15 23:57:08 +01:00
Vadim Zeitlin
5cf279a955 Merge branch 'cmake-superproject-fixes'
Fixes for using library from a super-project

See #1338.
2026-03-14 19:51:09 +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
7d652b8f2a Skip searching for dependencies if their targets already exist
This is useful when the library is used as a sub-project by a
super-project which has already defined targets for various dependencies
(e.g. typically because it bundles them together with SOCI too).

This is more than just an optimization as searching for the dependency
could (and typically would, when they're bundled as mentioned above)
fail, while skipping it allows the configuration and build to succeed.
2026-03-14 17:22:39 +01:00
Vadim Zeitlin
d4807763cc Optimize CMake look by breaking from it immediately
This change is done mostly not for run-time optimizations purposes but
to show that we don't need to continue iterating after missing at least
one missing target dependency.
2026-03-14 17:22:39 +01:00
Vadim Zeitlin
348957245d Don't make SOCI compiler interface part of its public interface
The options in soci_compiler_interface enabling (or even disabling)
various warnings shouldn't be used for compiling the application code.
2026-03-14 17:22:39 +01:00
Vadim Zeitlin
9b037080e7 Further simplify Oracle error handling code
Remove ugly get_error_details() function taking multiple output
parameters and just create oracle_soci_error objects directly.

As error.h has now become useless, remove it too.
2026-02-06 02:33:05 +01:00
Vadim Zeitlin
535f91a110 Avoid throwing an error when fetching 0 rows with Oracle
Check for the error apparently triggered by trying to execute a
statement without any results and do not turn it into exception.
2026-02-06 02:27:17 +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
862cac05b2 Fix behaviour of fetch() without any data for Firebird
Ensure we don't try doing anything in fetch() if there is no data to
retrieve.
2026-02-06 00:49:07 +01:00
Vadim Zeitlin
06992c2bd0 Fix behaviour of fetch() without any data for MySQL too
Same fix is required for MySQL as for PostgreSQL, see the previous
commit message for explanation.
2026-02-06 00:48:22 +01:00
Vadim Zeitlin
da49415352 Fix behaviour of fetch() without any data with PostgreSQL
If execute() didn't bring any data from the server, all statement member
variables remained uninitialized, resulting in problems (UB, infinite
loops, ...) if fetch() is called later.

Fix this by initializing numberOfRows_ and checking for it in fetch()
and simply not doing anything there if it is 0.

Closes #1328.
2026-02-06 00:19:41 +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
e509e1b0a0 Improve wording and clarity of the docs landing page
Notable explicitly mention that "using namespace soci" is assumed and
that "sql" is an object of "soci::session" type.
2026-01-15 15:21:36 +01:00
Vadim Zeitlin
82ab3b3245 Demonstrate use() in the examples on the landing page
While using ints is safe from the point of view of SQL injection, it's
still not a great example, so use parameters instead of building the SQL
query by simple string concatenation.
2026-01-15 15:20:37 +01:00
Vadim Zeitlin
dc6afb6f65 Use "std::" consistently in the docs landing page examples
It was used in a couple of places, but not everywhere. Removing it would
make the example using std::copy less clear, so add the missing
occurrences of "std::".
2026-01-15 15:19:45 +01:00
Vadim Zeitlin
a7b024465c Merge branch 'use-fmt'
Use fmt library for dynamic string construction instead of
std::ostringstream.

See #1321.
2026-01-15 12:55:18 +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
f5879b3c61 Use system fmt library if available
Use bundled fmt as fallback by default, but also add SOCI_FMT_BUILTIN
option to force or, on the contrary, forbid using it.

Note that we need to use header-only version of the library when
building SOCI statically because otherwise we'd have to install fmt
library too and we don't want to do this. It's fine to link with the
static fmt when using shared SOCI, however.
2026-01-14 23:40:06 +01:00
Vadim Zeitlin
547a62eec1 Add fmt library as submodule and use it in the tests
Replace existing use of std::cout and std::cerr with fmt::print[ln]():
this is simpler and more convenient and also faster to compile.

Also configure all CI jobs to clone submodules, as fmt submodule is
required now.
2026-01-14 23:40:06 +01:00
Vadim Zeitlin
9c21322c01 Rerun apt-get if it failed
We often get errors due to repositories being updated, so retry running
apt when this happens to see if it helps.
2026-01-14 23:37:40 +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
23c71341f3 Fix typo in context used in define_and_bind()
The recent 335b8e53 (Give context in error message when
define_and_bind() fails, 2026-01-14) accidentally used "context" string
instead of context variable, as intended.
2026-01-14 00:30:29 +01:00
Vadim Zeitlin
be6d02c893 Merge branch 'odbc-fix-reconnect'
Make reconnect() work with connection strings without full
authentication information in the ODBC backend.

See #1318.
2026-01-14 00:20:44 +01:00
Vadim Zeitlin
335b8e5392 Give context in error message when define_and_bind() fails
Include the query being run into the exception message thrown if
define_and_bind() fails.
2026-01-14 00:20:29 +01:00