Commit Graph

55 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
c3ee37fa8b Add soci::icast() helper
This is done mostly to avoid MSVC warnings about implicit __int64 to int
conversions, it should make no difference in practice as all sizes will
always be smaller than INT_MAX anyhow.
2025-06-06 17:26:53 +02:00
Robert Adam
77c75a4e85 Make SQLite overwrite exchange type for integers
Since SQLite doesn't have a type system, we have to always be prepared
to select huge numbers, even if the "type" is e.g. int8.
To do that, we overwrite the exchange type (e.g. in row based APIs) to
always be (u)int64 for integers to avoid over-/underflows.

Update the documentation to explain this SQLite peculiarity and add a
test verifying that this behaves as expected.

Fixes #1190.

Closes #1217.
2025-03-24 00:14:00 +01:00
Vadim Zeitlin
fb04446e35 Convert most HTTP links to HTTPS
No real changes, but it's not very serious to use HTTP links in 2025.
2025-03-04 18:03:53 +01:00
Vadim Zeitlin
23d79e9c5f Add C++20-like soci::ssize() helper
Use it instead of static_cast<int>(x.size()): this doesn't change
anything but is shorter and less ugly.
2025-02-05 16:19:40 +01:00
Vadim Zeitlin
5aba154d04 Add possibility to show vector row values in error messages
This requires backend cooperation, but it is now possible for a backend
to override get_row_to_dump() function to return the row whose values
would appear in the error message.

This commit is best viewed using Git --color-moved option.
2025-01-30 20:22:38 +01:00
Vadim Zeitlin
07f9af4d88 Move has[Vector]{Into,Use}Elements_ to statement_backend itself
Make sure all backends have access to these flags if they need them, it
doesn't really cost anything to store them in the base class.

No real changes.
2025-01-30 17:07:58 +01:00
Vadim Zeitlin
798b513ef0 Merge branch 'odbc-complex-query'
Try to make some complex queries work in ODBC backend.

See #1182.
2025-01-24 16:45:26 +01:00
Vadim Zeitlin
ee72345f6e Merge branch 'wstring'
Add std::wstring support for ODBC backend.

See #1179.
2025-01-24 16:45:11 +01:00
Robert Adam
dc4815cac1 Implement session::get_last_query_with_context()
Allow retrieving the last query with the parameter values used for them.

See #678.

Closes #1027.

Closes #1164.
2025-01-24 16:24:59 +01:00
Vadim Zeitlin
c899bc6842 Remove statement::define_for_row() and call it from describe()
It looks like this function must always be called after a (successful)
call to describe() and it is not called from anywhere else, so it seems
wrong to both require and allow calling it independently -- just call it
from describe() itself.

No real changes, this function has never been part of public API, so
hopefully nobody was using it.
2024-11-17 19:52:21 +01:00
joshua-15639
48a5a6c91e Try to make some complex queries work in ODBC backend
Describe the statement once again after calling execute() if we had
failed to describe it before because SQLNumResultCols() returned 0, as
it may happen with some complex queries and SQL Server used via ODBC
backend.

Closes #1151.

See #1182.

Co-Authored-By: Vadim Zeitlin <vz-soci@zeitlins.org>
2024-11-17 19:42:51 +01:00
Benjamin Oldenburg
982434f170 Add std::wstring support for ODBC backend
Handle wide-strings similarly to how normal strings are already handled.

For now support for them is only available in the ODBC backend.

Also add conversion functions between UTF-{8,16,32} and wchar_t and the
tests for them. Note that some of these functions are not used yet, but
provide the complete set as they probably will be in the future.

Co-Authored-By: Vadim Zeitlin <vz-soci@zeitlins.org>
2024-11-17 16:49:25 +01:00
Robert Adam
552f321c05 Bind blobs to actual blob objects
This ensures that when binding blobs dynamically (e.g. in a row), they
are properly represented as a soci::blob object and not by a
std::string.
2024-01-13 17:09:30 +01:00
Vadim Zeitlin
a9b3508880 Make db_type to data_type conversion backend-dependent
It wasn't quite the same for all of them, notably MySQL and ODBC
disagreed about the mapping of db_uint32 and ODBC backend also mapped
db_uint64 to signed dt_long_long and not dt_unsigned_long_long as the
other backends, so make it possible to preserve its existing behaviour
by overriding to_data_type() in it.

There is still a minor incompatibility in MySQL backend: the type of
unsigned INT24 fields is now dt_long_long and not dt_integer as before,
but we can hopefully live with this.
2024-01-03 01:34:10 +01:00
Vadim Zeitlin
fdfcc12e8d Remove data_type argument from describe_column() backend function
This is unnecessary as it can be recovered from db_type: even if this is
not lossless, we don't really care about it if all we need is data_type,
so simplify the API and the implementation by only having one "type"
parameter instead of two.

No real changes.
2024-01-03 00:36:54 +01:00
Lukas Zanner
826fa7753a Expose new db_type for dynamic type mapping 2023-08-13 17:26:15 +02:00
Lukas Zanner
3d1617085c Replace stdint.h with cstdint 2023-08-13 17:25:29 +02:00
Lukas Zanner
764424040a Update core code for complete integer type support 2023-08-13 17:25:22 +02:00
Carsten Stiborg
924d990f8f Fix memory leak due to unbounded indicators vector growth
Clear the `statement_impl::indicators_` vector instead of just appending
more and more elements to it when using values-based API.

Closes #1058.

See #1061.
2023-07-17 16:23:44 +02:00
Vadim Zeitlin
721bb1aa9d Remove trailing whitespace from all files
No real changes.
2021-04-07 19:32:41 +02:00
Cavaler
b4f7ce8031 Allow using data of type dt_blob and dt_xml with rowset
There doesn't seem to be any good reason not to allow this.

Closes #786.
2020-02-10 18:44:01 +01:00
Vadim Zeitlin
d081e1248d Include the parameter number in the errors from post_fetch()
This makes errors such as e.g. "Null value fetched and no indicator
defined." much more useful, as the error message now says which
parameter exactly was null.

Closes #631.
2018-07-02 15:24:16 +02:00
Maciej Sobczak
138b29e431 Lazy initialization of the temporary LOB objects for Oracle. 2017-07-20 00:47:59 +02:00
Mateusz Łoskot
b78c8ef824 Merge pull request #358 from ArnaudD-FR/bind_clean_up
Split Statement::clean_up into bind_clean_up and clean_up
2015-07-24 11:26:18 +02:00
ArnaudD-FR
403b8de263 Fix bind_clean_up when using 'row' 2015-07-16 14:56:03 +02:00
Miha Ravselj
7623f76fe1 More and better MSVC warnings fixes.
Fix warnings by changing the code whenever possible, in particular remove
firebird_rowid_backend class and src/backends/firebird/row-id.cpp file in
which it was defined entirely as it only resulted in "unreachable code"
warnings but was otherwise unused.

Also avoid implicit conversions by either using the correct types or by making
the casts explicit using static_cast<> in places where the casts are really
needed.

Add helpful SOCI_NOT_COPYABLE, SOCI_NOT_ASSIGNABLE and SOCI_UNUSED macros and
use them to suppress the corresponding warnings.

Finally, combine soci-config.h and soci-platform.h in a single file, always
include the latter as the first header and keep the former as a wrapper for
the latter just for compatibility.

Remove the MSVC "#pragma warning(disable: *)" as they are not needed any more.

Closes #355.
2015-07-15 03:37:25 +02:00
ArnaudD-FR
a6b351449c Split Statement::clean_up into bind_clean_up and clean_up 2015-07-09 16:52:03 +02:00
Vadim Zeitlin
7e80c68341 Use parameter names from the query, if given, in error messages.
Improve the error messages by using the parameter names used in the query
itself, if any, when the query parameters were bound by position and not by
name.

This means that errors for a query like

            sql << "insert into soci_test(name, age) values (:name, :age)",
                   use(name), use(age));

will now contain "with :name=... :age=..." even though the parameter names
were not passed to use().
2015-04-16 17:01:38 +02:00
Mateusz Łoskot
e4376edaec Merge branch 'master' into develop-3.2.3
wip: Merging SOCI 3.2.3 changes (current master) into develop.

Conflicts:
	.gitignore
	.travis.yml
	AUTHORS
	CHANGES
	cmake/SociBackend.cmake
	cmake/modules/FindODBC.cmake
	docs/installation.html
	include/soci/boost-fusion.h
	include/soci/boost-tuple.h
	include/soci/odbc/soci-odbc.h
	include/soci/prepare-temp-type.h
	include/soci/ref-counted-prepare-info.h
	include/soci/soci-platform.h
	include/soci/statement.h
	include/soci/use.h
	include/soci/version.h
	src/CMakeLists.txt
	src/backends/postgresql/test/test-postgresql.cpp
	src/backends/sqlite3/blob.cpp
	src/backends/sqlite3/test/test-sqlite3.cpp
	src/core/CMakeLists.txt
	src/core/test/common-tests.h
	tests/mysql/test-mysql.cpp
	www/index.html
2015-04-09 23:43:22 +02:00
Adesmier
c799e4f6ed Append each member of tuple/fusion instead of adding tuple/fusion
* Warning: break compatibility with boost 1.35 released in 2008!
 * when calling use() or into() with tuple or fusion objects, it stores
   reference to each member of object instead of storing object reference
   thanks to boost::fusion::foreach.
 * Job is done by new use_type_vector and into_type_vector classes
2015-04-08 22:06:46 +02:00
Vadim Zeitlin
8bb66107a2 Provide context of the error in soci_error when possible.
Add soci_error::add_context() and use it in statement class to record the
information about the query which resulted in the exception and, if
applicable, this query parameters.

This results in much better end user experience as the error messages now
contain information allowing to diagnose which query exactly has failed
instead of just unhelpfully saying that an error occurred.
2015-04-01 15:24:12 +02:00
Vadim Zeitlin
e8e5978138 No real changes, just remove trailing whitespace.
Insignificant trailing whitespace was annoying as it resulted in extra noise
in the diffs, just get rid of it everywhere at once.
2015-04-01 14:52:39 +02:00
Vadim Zeitlin
417ef5cc4d Include all public headers using "soci/" prefix inside SOCI itself.
Harmonize the inclusion style of the headers from inside and outside the
library and always use the "soci/foo.h" form.
2014-03-25 15:53:32 +01:00
Ricardo Andrade
901f33bb15 Fixes false negatives in case of a partial placeholder matching. 2013-05-31 10:32:48 -03:00
Ricardo Andrade
92c2e8b21a Untabfy 2013-05-02 10:10:07 -03:00
Ricardo Andrade
087b24a087 soci::values placeholder search logic now looks for the following alphanumerical char to discard a match. 2013-05-02 09:32:15 -03:00
Ricardo Andrade
5d7df8ff91 Fixes the use of PostgreSQL-style casts with ORM (soci::values) 2013-05-02 09:31:25 -03:00
Mateusz Loskot
1e693d366d Untabify 2013-03-03 15:06:13 +00:00
Mateusz Loskot
d279c11e9b Fix memory leak of statement backend (issue #67)
The leak has been confirmed usign memory debugger. Applied fix suggested
by Evgeny Barabanov to perform allocated statement clean up if exception
is thrown from prepare() method.
2013-02-16 22:19:35 +00:00
Mateusz Loskot
5f0dd71377 Fix for #44 - Placeholder at the last position of statement causing crash
Patch received from Daniel Beaudoin (Optel Vision) on 23/07/2012)
2013-02-03 15:19:48 +00:00
Vadim Zeitlin
4f8bc05242 Remove dt_unsigned_long and x_unsigned_long type constants.
There is no need for a separate type for "unsigned long" as we don't have
special types neither for "unsigned int" nor for "long" and this type was not
handled correctly in the ODBC backend that mapped "unsigned int" to
SQL_BIGINT, even though the former is almost always 32 bits and the latter is
always 64 bits.

Simply remove these types to avoid the problem and simplify the code.

Signed-off-by: Vadim Zeitlin <vz-soci@zeitlins.org>
2012-07-10 22:36:04 +02:00
Mateusz Loskot
1070898f95 Use C++ cast operators. 2012-02-20 23:41:35 +00:00