Commit Graph

24 Commits

Author SHA1 Message Date
Vadim Zeitlin 276a54d4d1 Add private auto_statement RAII helper
When working directly with concrete statement_backend classes, their
alloc() and clean_up() methods must be called directly, which suffers
from all the usual problems, especially in presence of exceptions.

Avoid them by using the new auto_statement class which takes care of
calling these methods in its ctor/dtor instead.

An alternative could be to make the concrete classes themselves use
RAII, but this would be more error prone (e.g. there would be a risk of
alloc() being called twice) and require many more changes, so, at least
for now, use this more lightweight solution.

No real changes.
2020-10-12 23:25:43 +02:00
William Blough b208b22456 Ignore alignment warnings/errors in Firebird backend
Suppress gcc -Wcast-align which are harmless in this context.

Closes https://github.com/SOCI/soci/pull/824
2020-10-10 23:01:43 +02:00
Vadim Zeitlin 4e3d9e99c7 Extract and extend PostgreSQL string to int conversion helpers
Generalize the use of strtoll() instead of sscanf() for the conversion
to unsigned integer types too and extend the code doing it to a couple
of new simple reusable functions that can now be used in all backends.

Keep PostgreSQL idiosyncratic conversion of "f" and "t" to integers to
avoid changing the existing behaviour, even if it's not really clear
whether this is needed for all types.
2020-04-05 00:55:38 +02:00
Ross Marwood 99a33e0f45 Changed Windows #ifdefs from _MSC_VER (VC++ specific) to _WIN32 (Windows API in general) 2020-03-22 18:43:33 +02:00
Ross Marwood 2041df3774 Changed issue 723 bugfix to use timegm(), reverted Oracle tests (which no longer need to be modified) and substituted NULL for nullptr in issue 723 test for earlier C++ compaticbility 2020-03-22 17:42:50 +02:00
Ross Marwood 0c91ff9aa0 Fix for soci issue 723 2020-03-20 15:50:36 +03:00
Vadim Zeitlin 556f5d3369 Add exchange_type_traits<> specializations for XML and CLOB
There is no reason to not have them and this allows to write slightly
shorter and safer code using exchange_type_cast<> instead of "raw"
static_cast<>.
2017-09-15 01:44:34 +02:00
Vadim Zeitlin a1e07e389c Avoid duplicate code for parsing dates in different backends
SQLite, MySQL and PostgreSQL backends used the same but slightly
different code for parsing the contents of a buffer into std::tm struct.

Replace all these different versions with a single version, copied from
the PostgreSQL variant, which seems like the most complete, in the
common code.

Update MySQL-specific test to not expect parsing a string containing
time without date to yield year 2000, this didn't make any sense at all
and PostgreSQL default of year 1900 makes at least slightly more sense.
2017-07-20 15:38:42 +02:00
ArnaudD-FR 0b1a835691 Include soci-platform.h because of snprintf 2015-07-22 14:48:05 +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
Vadim Zeitlin 388a8d3860 Use compile-time asserts to check SQLINTEGER size.
Fail to compile the code if SQLINTEGER has different size from int instead of
crashing the program during run-time.

See #300.
2015-04-21 15:55:51 +02:00
Vadim Zeitlin f5c86b70b8 Make SOCI_NORETURN public and use it in declaration.
SOCI_NORETURN had to be moved to a public header to avoid MSVC error C2381
("'function' : redefinition; __declspec(noreturn) differs") which was given if
SOCI_NORETURN was specified on the function definition only and not its
declaration.

Use SOCI_NORETURN when both declaring and defining the function now (notice
that C++11 [[noreturn]] attribute also must be used on declarations).
2015-04-16 00:31:47 +02:00
Vadim Zeitlin 62c17b279c Add mktime_from_ymdhms() helper.
No changes, just refactor the code to use this function instead of redoing all
the year/month adjustments (by 1900 and 1 respectively) in all the backends.

This is also meant to allow changing the time zone handling in a single place
in the future if we decide to do it.
2015-04-15 11:26:55 +02:00
Vadim Zeitlin 962808121b Define SOCI_NORETURN: a portable __attribute__((noreturn)) equivalent.
This macro can be used instead of just "void" return type for the functions
that never return. In addition to making it clear that they really don't
return, it also can suppress some warnings that the compiler would give
without having this information.
2015-04-01 14:40:03 +02:00
Vadim Zeitlin 0f1f295f68 Add helper exchange_type_cast<>() template function.
The new function replaces explicit static_cast<> and can be used to upcast a
void pointer to the type of the value corresponding to the exchange_type
associated with it somewhat more safely and less verbosely.

There are no real changes in this commit.
2015-04-01 01:36:15 +02:00
Vadim Zeitlin 24c05399fa Fix rounding error in Firebird NUMERIC/DECIMAL conversions.
The value was truncated instead of being rounded in to_isc() helper function,
resulting in, for example, "0.003958" being saved as "0.003957" in a
NUMERIC(7,6) column because the string "0.003958" is actually
"0.0039579999999999997129" when converted to string with 20 digits of
precision and, after multiplying by 1e6 scale, yielded 3957 in the usual
double precision.

Round the values now to prevent this from happening.
2015-03-16 17:55:25 +01:00
Vadim Zeitlin c85744b752 Define GCC_WARNING_SUPPRESS and GCC_WARNING_RESTORE macros.
Add a private header for compiler-specific things and use it to define
GCC_WARNING_{SUPPRESS.RESTORE} macros which will be used in the upcoming
commits to locally disable some of the g++ warnings.

As a side effect, also add SOCI_CONCAT and SOCI_STRINGIZE helper macros, in
their own header to facilitate their reuse in the future if needed.
2015-03-11 02:22:24 +01:00
Vadim Zeitlin 8548642dc1 Use locale-independent function for converting doubles to strings.
Similarly to the issue #238 but in the other direction, we must use
locale-independent functions to ensure that we send the strings in correct
format to the database even if the current locale doesn't use period as
decimal separator.

This fixes errors like

	invalid input syntax for type double precision: "3,1415926500000002086"

when executing the tests in e.g. French locale.
2014-04-22 15:05:05 +02:00
Vadim Zeitlin 1260d4f7d9 Reimplement cstring_to_double() without using C++ standard library.
Some implementations of C++ streams (notably libstdc++ under OS X) are buggy
and change the global locale to implement support for imbue(), which is not
thread-safe, and so could introduce subtle bugs in multi-thread programs.

Replace the old correct but not working in practice code with a new ugly
version only supporting decimal comma and period which is not totally correct
in theory but should work fine in practice (and shouldn't make things worse
even for the hypothetical locales using some other decimal separator anyhow).
2014-04-22 15:05:04 +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
Vadim Zeitlin 6f4162c0e1 Add helper cstring_to_double() and use it in PostgreSQL backend.
Replace PostgreSQL-specific and incorrect string_to_double() function with a
common (i.e. reusable) cstring_to_double() which always interprets the string
as being in "C" locale as this is what the actual strings, retrieved from the
database, use.
2014-03-24 17:01:04 +01:00
Mateusz Loskot 928174c431 Fix Firebird includes of private headers 2014-01-20 20:57:01 +00:00
Mateusz Loskot da025dfb6e Merge branch 'feature/125-new-layout' into develop
Implementation of the new source tree layout
Closes #151

Conflicts:
	.gitignore
	src/CMakeLists.txt
2013-09-11 02:06:56 +01:00
Mateusz Loskot b6d97ffa6f Implement new source tree layout #125
First set of changes incorporating new structure of source tree.
It also applies some of changes planned as part of buried headers feature #25

Work in progress, requires testing before merging into develop branch
2013-05-29 21:57:23 +01:00