Commit Graph

2612 Commits

Author SHA1 Message Date
Vadim Zeitlin 072baaf345 Remove hard TAB in a Travis CI script
No real changes.
2020-11-29 15:16:57 +01:00
Vadim Zeitlin ce6f74c906 Only install Valgrind on Travis for the build which needs it
It seems useless to always download and install Valgrind for all builds
when we only need it for a single one of them.
2020-11-29 15:16:57 +01:00
Vadim Zeitlin d4d50d6500 Don't show interactive ODBC dialogs when reconnecting
Such dialogs can be unexpected and confusing, as reconnection can happen
automatically, and not in a response to a user action.

Implement this by adding a new "reconnect" option and add is_option_on()
helper to connection_parameters to facilitate using it.
2020-11-04 01:30:05 +01:00
Vadim Zeitlin 96c7ec18b4 Don't force CR LF normalization in .gitattributes
Nowadays all systems can deal with LF-only files (perhaps with some rare
exceptions, not affecting SOCI) and there is no need to force
normalization in the repository itself -- people who need it can always
enable it in their global Git config.
2020-11-04 01:27:52 +01:00
Vadim Zeitlin fc29f3b504 Fix version of Markdown linter used on Circle CI
The latest version seems to have problems and reports

/usr/local/lib/node_modules/markdownlint-cli/markdownlint.js:52
    } catch {
            ^
SyntaxError: Unexpected token {

when installing it, so revert to the last known working one.

Co-authored-by: Mateusz Loskot <mateusz@loskot.net>
2020-11-01 01:27:46 +01:00
Noah Shutty 88e7249f4c Fix PostgreSQL tests build under macOS
Use fully qualified "soci::session" type name to avoid conflicts with
"session" struct declared in sys/proc.h under macOS.

This is a recurrent problem (see #605 for a previous example of it)
which should probably be solved by removing "using namespace soci" from
the test to prevent it from happening again.

Closes #832.
2020-10-31 13:36:53 +01:00
Vadim Zeitlin 988493ac76 Use v4.0.1 tag in the README badges instead of 4.0.0 v4.0.1 2020-10-19 16:58:52 +02:00
Vadim Zeitlin 17238d86c1 Add change log for v4.0.1 release 2020-10-19 16:08:42 +02:00
Vadim Zeitlin 1a02665e21 Update version to 4.0.1
Prepare for v4.0.1 release.
2020-10-19 16:08:28 +02:00
Vadim Zeitlin c6aa3306c6 Add contributors since 4.0.0 to the AUTHORS file
Also add a "maintainer" section.
2020-10-19 16:04:36 +02:00
Vadim Zeitlin 0ccbd9224c Add myself (Vadim Zeitlin) as maintainer to the README 2020-10-19 15:58:18 +02:00
Vadim Zeitlin ef5e1227e1 Always initialize leave postgresql_session_backend::conn_
This wasn't done before in case of connection failure in connect(), so
PQfinish() could be called with a dangling pointer from clean_up(),
called from the dtor, later.

Just initialize conn_ in ctor to fix this.

Closes #822.
2020-10-19 15:33:01 +02:00
Vadim Zeitlin 81c7a391e2 Merge branch 'conn-keep-alive'
Make it easier to implement trivial connection keep alive mechanism.

See #828.
2020-10-19 15:23:46 +02:00
XiaoGuang Zeng 8f6e56bc58 Define search_paths() in dynamic_backends namespace
The function search_paths() was accidentally defined in the global
namespace instead of "dynamic_backends" one, as it was supposed to,
meaning that dynamic_backends::search_paths() was not defined at all and
attempts to use it resulted in link errors.

Closes #829.
2020-10-13 13:27:27 +02:00
Vadim Zeitlin 0d6ab166a1 Skip category check for unknown ODBC errors in "Reconnect" test
At least PostgreSQL ODBC driver just returns "HY000", i.e. "General
error" in case of connection loss, which clearly can't be always mapped
to soci_error::connection_error, so we need to take into account that
get_error_category() doesn't always return the expected value, at least
with the ODBC backend.
2020-10-13 01:45:24 +02:00
Vadim Zeitlin 0d014a9e7b Recognize some well-known SQLSTATE values in ODBC error class
Try to return something meaningful from get_error_category() for a few
SQLSTATE values that seem to be reasonable standard and map well to the
existing error_category enum values.

This is far from being exhaustive, but is still better than nothing and
allows "Reconnect" unit test to pass when using MS SQL ODBC driver.
2020-10-13 01:39:13 +02:00
Vadim Zeitlin 43c133be13 Add session::is_connected() function
This function can be used to check if the connection to the server is
still available (and then, perhaps, call reconnect(), if it isn't).

Implement it for all backends using native API (except for SQLite for
which it always returns true).
2020-10-13 01:05:51 +02:00
Vadim Zeitlin 515a6505c0 Recognize more Oracle errors as corresponding to connection loss
Set error category to connection_error for ORA-03113 which occurs if the
server is not running any longer, ORA-03114 which happens in case of a
network problem and also for ORA-12541 which seems similar to ORA-12162,
which was already mapped to connection_error.

This allow the manual "Reconnect" test to pass with Oracle backend.
2020-10-13 01:02:30 +02:00
Vadim Zeitlin 498bcedfa5 Add test for using failover callback
This test is disabled by default, but can be run explicitly to check
that we can automatically recover from connection loss when using a
backend supporting this (currently only Oracle and PostgreSQL, and only
tested with the latter).
2020-10-12 23:26:39 +02:00
Vadim Zeitlin 605db30f6c Reuse correct connection parameters for PostgreSQL failover
If the failover callback doesn't provide the connection string to use,
default to the originally used one instead of using empty connection
string which is almost certainly not what we want.

Note that this requires storing the original connection parameters in
postgresql_session_backend, as we don't have access to the ones stored
in the session object and it seems wrong to add backlinks from the
backend to the session object.

Closes #793.
2020-10-12 23:26:39 +02:00
Vadim Zeitlin 339a5a3a1d Add test of manually reconnecting after connection loss
This can't be tested automatically, as we don't really have any way to
break the connection programmatically, but we can still have a test for
this relying on breaking (and then restoring) the connection manually.
2020-10-12 23:26:39 +02:00
Vadim Zeitlin a6259e917b Return more precise error on connection loss with PostgreSQL
Use SQL state which is mapped to "connection_error" category when the
connection is lost.
2020-10-12 23:26:39 +02:00
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
Vadim Zeitlin 63bb4f5a6f Define SOCI_NOEXCEPT and use it instead of deprecated "throw()"
Add another C++11-like macro (similar to SOCI_OVERRIDE) which can also
be used in C++98 code.

The main advantage is that new code can now use SOCI_NOEXCEPT instead of
the old "throw()" and it will be possible to simply replace it with
"noexcept" after dropping C++98 support.
2020-10-12 22:03:56 +02:00
Vadim Zeitlin 2b1aea601e Merge branch 'disable-werror-by-default'
Don't use -Werror when building SOCI by default (but still use it in the
CI builds).

See #825.
2020-10-11 01:03:51 +02:00
Vadim Zeitlin 372e919a45 Debug expect script used for Firebird configuration
Try to understand why setting the SYSDBA password suddenly doesn't work
any longer.
2020-10-11 00:44:12 +02:00
Vadim Zeitlin 53a1a18ccc Enable -Werror for Travis CI builds too
This needs to be done explicitly now, since the changes of c6ed5f70
(Don't use -Werror unconditionally when building SOCI, 2020-06-05).
2020-10-10 23:36:44 +02:00
Vadim Zeitlin 84fed32d0b Refactor Travis CI build scripts to reuse common options
Define SOCI_DEFAULT_CMAKE_OPTIONS once and use it in almost all builds
instead of repeating the same options many times everywhere.

For the remaining build (Valgrind) still reuse a couple of options which
it has in common with the other ones.
2020-10-10 23:36:40 +02:00
Vadim Zeitlin f14c97fecf Enable -Werror for AppVeyor builds
This needs to be done explicit since the changes of c6ed5f70 (Don't use
-Werror unconditionally when building SOCI, 2020-06-05).
2020-10-10 23:25:07 +02:00
Denis Arnaud c6ed5f7093 Don't use -Werror unconditionally when building SOCI
This is not always a good idea, as it can result in errors when building
with a newer compiler or on a new platform, even if the warning reported
are not really harmful, so don't do this by default.
2020-10-10 23:21:23 +02:00
Ross Marwood 8f6327638f Fix memory leak in Oracle backend when using XML or long strings
Add call to OCIDescriptorFree() to free LOB Locator and fix memory leak.

Closes #808, #810.
2020-10-10 23:14:18 +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 81305a3318 Use wildcard for MySQL client library in Valgrind suppression
This allows the suppression to still apply even if the exact library
name changes, as it recently happened in Travis CI Ubuntu Xenial build
environment (where it is 20.3.17 now instead of 20.3.12 as before).
2020-10-10 22:58:47 +02:00
Xuewen Wang ea0c968a29 Fix ODBC type when the string size is exactly ODBC_MAX_COL_SIZE
Since a null character is added, we must use SQL_LONGVARCHAR in this
case as the effective length is too big for SQL_VARCHAR.

Close https://github.com/SOCI/soci/pull/819
2020-08-05 00:33:15 +02:00
Vadim Zeitlin 68d4a8aea8 Merge branch 'master' of https://github.com/jeannotlapin/soci
Add support for "vfs" flag in SQLite3 backend connection parameters.

See #816.
2020-06-18 03:05:29 +02:00
Johan Pascal c158d2c67b Support "vfs" flag in SQLite3 backend connection parameters
Allow passing a pre-registered sqlite3 vfs string identifier to the
database open function
2020-06-17 23:54:01 +02:00
Vadim Zeitlin fd7a5090e4 Fix all the other -Wcast-align occurrences in the ODBC backend
This completes the changes of 60fe9f3c (Suppress -Wcast-align in ODBC
backend code under ARM, 2020-06-04), which fixed only the first
occurrence of a warning, which happened in several other places as well.

See #812.
4.0.1-alpha2
2020-06-05 00:34:52 +02:00
Matt Budish 9514405dd0 Initialize dataBuf pointer
Initializing this pointer eliminates a compilation warning in g++ 8.3.
2020-06-04 15:37:23 -05:00
Vadim Zeitlin 60fe9f3cde Suppress -Wcast-align in ODBC backend code under ARM
This warning should be harmless, so just suppress it to allow building
SOCI under ARMv7hl architecture (all warnings are fatal due to the use
of -Werror).

Closes #812.
4.0.1-alpha1
2020-06-04 11:27:18 +02:00
Vadim Zeitlin f670b06e69 Fall back on SQL_DRIVER_NOPROMPT when pooling ODBC connections
The application may enable (sometimes even inadvertently, simply due to
its use of another ODBC library which does it, e.g. pyODBC does this by
default) the use of pooled ODBC connections before trying to open a SOCI
session.

In this case, only the use of SQL_DRIVER_NOPROMPT is allowed by ODBC
driver manager and attempts to connect with any other "completion"
parameter value result in ODBC error "HY110". As the code using SOCI
may be completely oblivious to the use of pooled connections (e.g. SOCI
is used by another library in the same application and has no knowledge
whatsoever about the first library), it makes sense to try to do our
best in this situation and automatically try to fall back on connecting
with SQL_DRIVER_NOPROMPT in this case.

This commit implements this solution by adding a special check for this
case.

Note that these changes are best viewed ignoring whitespace.
2020-04-20 23:25:25 +02:00
William Blough 78b0d51d4c Fix error message wording: s/catched/caught/ in Firebird backend
Closes https://github.com/SOCI/soci/pull/804
2020-04-06 14:23:32 +02:00
Vadim Zeitlin 2513a5dea0 Merge branch 'use-strtoll-not-sscanf'
Switch to using std::stro[u]ll() instead of sscanf() for string to
number conversions.

See https://github.com/SOCI/soci/pull/803
2020-04-05 02:34:36 +02:00
Vadim Zeitlin 4d1b30586d Use cstring_to_integer() in other backends too
Replace all the other uses of sscanf("%lld") and "%llu" with the calls
to cstring_to_integer() and cstring_to_unsigned() respectively, which
should be faster and provide better error checking.

There should be no change in behaviour.
2020-04-05 01:03:39 +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
Theo van Klaveren 14705a73c2 For performance reasons, use strtoll() instead of sscanf()
Should be functionally identical.
2020-04-04 23:50:55 +02:00
Vadim Zeitlin 478671a813 Fix spelling of "overridden" in indicators documentation 2020-04-04 23:32:20 +02:00
Alexander Kulikov b32d480e0a Fix using const std::vector<boost::optional<>> as query arguments
Remove apparently unused conversion_use_type::convert_from_base() which
prevents this class from being used with const references.

Closes https://github.com/SOCI/soci/pull/797
2020-04-04 23:23:14 +02:00
Vadim Zeitlin 5b37645c1a Merge branch 'travis-xenial'
Switch to using Ubuntu Xenial for Travis CI builds.

See https://github.com/SOCI/soci/pull/791
2020-04-04 23:17:22 +02:00
Vadim Zeitlin 457ec97eec Suppress reports about memory leaks in PostgreSQL ODBC test
Unfortunately we don't get any information about these leaks, the entire
report looks like this:

==6706==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:

    #0 0x7f6473f80602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f646f89ba82  (/usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so+0x1ba82)

Indirect leak of 25 byte(s) in 1 object(s) allocated from:

    #0 0x7f6473f80602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f646f89ba9a  (/usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so+0x1ba9a)

SUMMARY: AddressSanitizer: 49 byte(s) leaked in 2 allocation(s).

So we have no choice but to suppress all leaks from psqlodbca.so to let
the tests to pass on Travis CI.
2020-03-29 16:00:18 +02:00
Vadim Zeitlin f032c2a695 Disable even more leaks in DB/2 tests on Travis CI
Unfortunately we don't get any real information about these leaks, the
entire report is

==10667==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 176 byte(s) in 1 object(s) allocated from:
    #0 0x7ff24b649602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7ff23f0ef551  (<unknown module>)

Indirect leak of 744 byte(s) in 3 object(s) allocated from:
    #0 0x7ff24b649602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7ff23f0ef551  (<unknown module>)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7ff24b649602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7ff23f456d89  (<unknown module>)

So we can only disable leaks coming from libasan.so to suppress them
which, of course, risks hiding any other leaks too. The only way to
check for them is to check that the count of suppressions in libasan.so
doesn't increase beyond 5.
2020-03-29 16:00:18 +02:00