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 » Postgres library improvements
Postgres library improvements [message #22561] Mon, 27 July 2009 10:44 Go to previous message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
1. Client code page

Functions PostgreSQLConnection::ErrorMessage and PostgreSQLSession::ErrorMessage use FromSystemCharset to convert code page. Unfortunately PQerrorMessage AFAIK does not use client's system code page but the code page that is declared in lc_messages (postgresql.conf), or the code page explicit set by the client (function PQsetClientEncoding).

So I think those functions should be modified:

String PostgreSQLConnection::ErrorMessage()
{
	// no code page conversion, leave it to postgres
	return AsString(PQerrorMessage(conn));
}

String PostgreSQLSession::ErrorMessage()
{
	// no code page conversion, leave it to postgres
	return AsString(PQerrorMessage(conn));
}


And of course postgres should be informed about the code page:

bool PostgreSQLSession::Open(const char *connect)
{
	Close();
	conn = PQconnectdb(connect);
	if(PQstatus(conn) != CONNECTION_OK)
	{
		SetError(ErrorMessage(), "Opening database");
		Close();
		return false;
	}
	level = 0;
	
	// set client's code page
	int stat = PQsetClientEncoding(conn, CharsetName(GetDefaultCharset()));
	ASSERT(stat == 0);
	LOG( String("Postgresql client encoding: ") + pg_encoding_to_char( PQclientEncoding(conn) ) );
	
	return true;
}


I made some tests with UTF-8 and WIN1250, and it appears that postgres accepts code page names from ultimate Smile


2. Re-establishing connection

It would be nice to have function that reconnects to database, when connection is lost:

bool PostgreSQLSession::ReOpen()
{
	PQreset(conn);
	if(PQstatus(conn) != CONNECTION_OK)
	{
		SetError(ErrorMessage(), "Opening database");
		return false;
	}
	level = 0;
	
	return true;	
}


 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Postgresql and bool
Next Topic: Acquiring large record
Goto Forum:
  


Current Time: Fri Apr 19 21:42:19 CEST 2024

Total time taken to generate the page: 0.05146 seconds