Add connection methods is_connected() and ping_server() #528
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the following changes:
is_connected()method is added to the connection handles and the connection classes (both to normal and pooled connections). This method checks passively (without sending data to the server) if the connection is valid. For MySQL and SQLite3 connections it checks if the connection has been established. For PostgreSQL this method additionally callsPQstatus.ping_server()method is added to the connection handles and the connection classes (both to normal and pooled connections). This method checks actively (by sending a request to the server) if the connection is valid. For MySQL it uses the MySQL client functionmysql_ping(). For PostgreSQL and SQLite3 there are no such client library functions (actually libpq hasPGping()but that function establishes a new connection to ping the server and we want to test an existing connection). So for PostgreSQL and SQLite3 theirping_server()methods are loosely based on the PHP functionpg_ping()which sendsSELECT 1to the server and checks if the server replies with a success.sqlpp::connection_checkwhich enumerates the three types of connection check:none,passive(i.e.is_connected) andping(i.e.ping_server).connection_pool::get()is changed toconnection_pool::get(connection_check check = connection_check::passive), that is when fetching a connection from the pool, the user can choose the check type that will be applied to the connection.The PR was built and tested with
All tests passed successfully.