Connecting to a postgreSQL database with windows CE over wi-fi; failing gracefully

From: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Connecting to a postgreSQL database with windows CE over wi-fi; failing gracefully
Date: 2009-04-29 14:52:52
Message-ID: db471ace0904290752t5b24e31hc24a069abf5e1073@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I'm developing a PostgreSQL application for Windows CE 5 on a PDT/ PDA
in C++/Qt, using Hiroshi Saito's libpq port for that platform. Since
the connection is established over wi-fi, and wi-fi connectivity is
often flaky, I feel that I have to "fail gracefully" to as great an
extent as possible. The following utility function,
VerifyDbConnection(), is called before every piece of database work:

void MainInterface::VerifyDbConnection()
{
if (PQstatus(conn) != CONNECTION_OK)
{
for(;;)
{
PQreset(conn);
if(PQstatus(conn) == CONNECTION_OK)
return;

QMessageBox msgbox_connection_lost;
msgbox_connection_lost.setText("Connection to the database is lost,
and cannot be re-established. "
"This may be due to the fact that you're too far away from the
Wi-fi access point, or because "
"the backoffice computer is turned off, or it may be a low level
connectivity problem." );
QPushButton* retry_button =
msgbox_connection_lost.addButton(tr("Reconnect"),
QMessageBox::ActionRole);
QPushButton* exit_button =
msgbox_connection_lost.addButton(tr("Exit"), QMessageBox::ActionRole);
msgbox_connection_lost.setWindowTitle("Connection lost");
msgbox_connection_lost.exec();

if(msgbox_connection_lost.clickedButton() == retry_button)
{
continue;
}
else if(msgbox_connection_lost.clickedButton() == exit_button)
{
exit(0);
return;
}
}
}

}

This seemed to work fine initially; I'd abruptly stop the database
server, and I would see a messagebox informing me of a connectivity
problem. Then, I'd start the server, click the retry button, and have
connectivity restored. However, when I walk out of range of the wi-fi
access point, which is the probable cause of losing connectivity in
the real world, my program crashes without displaying an error message
(I would expect to see a visual C++ runtime error message).

Can someone suggest a reason for this, or a workaround?

Regards,
Peter Geoghegan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message DaNieL 2009-04-29 14:54:20 ERROR: syntax error at or near "IF"... why?
Previous Message Marcin Krol 2009-04-29 12:30:14 retrieving primary key for row with MIN function