Skip to content

Conversation

@MeanSquaredError
Copy link
Contributor

This PR makes the following changes:

  1. 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 calls PQstatus.
  2. 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 function mysql_ping(). For PostgreSQL and SQLite3 there are no such client library functions (actually libpq has PGping() but that function establishes a new connection to ping the server and we want to test an existing connection). So for PostgreSQL and SQLite3 their ping_server() methods are loosely based on the PHP function pg_ping() which sends SELECT 1 to the server and checks if the server replies with a success.
  3. There is a new enum sqlpp::connection_check which enumerates the three types of connection check: none, passive (i.e. is_connected) and ping (i.e. ping_server).
  4. connection_pool::get() is changed to connection_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

cmake -B build -DBUILD_POSTGRESQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON -DBUILD_MYSQL_CONNECTOR=ON -DBUILD_TESTING=ON -DUSE_SYSTEM_DATE=ON -DDEPENDENCY_CHECK=ON -DSQLPP11_TESTS_CXX_STD=11

All tests passed successfully.

@rbock
Copy link
Owner

rbock commented Sep 19, 2023

I think this is ready to merge. Agreed?

@MeanSquaredError
Copy link
Contributor Author

I think this is ready to merge. Agreed?

I agree that it is ready to merge.

@rbock rbock merged commit 623b515 into rbock:main Sep 20, 2023
@rbock
Copy link
Owner

rbock commented Sep 20, 2023

Thanks!

@MeanSquaredError MeanSquaredError deleted the conn_check_ping branch September 20, 2023 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants