Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Patch: Reconnecting PostgreSQL Automatically on Unstable Networks
Patch: Reconnecting PostgreSQL Automatically on Unstable Networks [message #26366] Tue, 27 April 2010 19:21 Go to previous message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
After a network connection problem or coming back from suspend, it is convenient for your users to reconnect your app to the server automatically.

I did not want to write a lot of code dealing with this problem, so I patched PostgreSQL classes.

Using this patch PostgreSQL classes reconnect to the server on connection problems. They try to reconnect only once and not within transactions.

In void PostgreSQLSession::ExecTrans(const char * statement) change the row
result = PQexec(conn, statement);


to
	for(int i=0; i<2; i++){
		result = PQexec(conn, statement);
		if(level==0 && !ConnectionOK())
			if(!ReOpen()) return;
			else continue;
		break;
	}


and in bool PostgreSQLConnection::Execute() change the row
result = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);

to
	for(int i=0; i<2; i++){
		result = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);
		if(session.level==0 && !session.ConnectionOK())
			if(!session.ReOpen()) return false;
			else continue;
		break;
	}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Any way to generate sch from database?
Next Topic: SQLITE3: Bind parameter by name
Goto Forum:
  


Current Time: Sun Apr 28 05:52:32 CEST 2024

Total time taken to generate the page: 0.05253 seconds