Set "socketTimeout" option to QSqlDatabase connection(PostgreSQL)
Solved
General and Desktop
-
wrote on 15 Oct 2020, 16:29 last edited by
Hello,
According to PostgreSQL doc( https://jdbc.postgresql.org/documentation/head/connect.html ) there is an socketTimeout option, that I want to use. But seems like QT couldn't accept it correctly.
db = QSqlDatabase::addDatabase(db_prm.db_type, db_prm.db_name); if (!db.isValid()) return -1; } db.setDatabaseName( db_prm.db_name ); db.setHostName( db_prm.db_host ); db.setPort( db_prm.db_port ); db.setUserName( db_prm.db_user ); db.setPassword( db_prm.db_pass ); db.setConnectOptions( db_prm.options ); db.setConnectOptions("socketTimeout=10");
It returns error :
Failure to open TEST_DB database. Error: invalid connection option "socketTimeout"
It needed because QSqlDatabase::isOpen() doesn't provide correct information about current DB connection status in the cases when for example network interface go down after successful connection. Any ideas ? thx!
-
Lifetime Qt Championwrote on 15 Oct 2020, 16:58 last edited by Christian Ehrlicher
The Qt PostgreSQL driver does not use the PSQL jdbc driver but libpq: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
1/2