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