Well, followed your advice and installed the package:
http://wwwmaster.postgresql.org/download/mirrors-ftp?file=odbc%2Fversions%2Fsnapshots%2Fpsqlodbc-08_01_0005.zip
After which I created the Windows ODBC Source (The Unicode Driver) for my application to connect to. But I still get a buffer ovverrun
and stack corruption that I was getting originally. Here are some specs:
1) My machine Windows 2k server (Both app and DB are one the same box).
2) PostgreSQL Database Server 8.0.0-beta3-dev1 ( With a valid DB created in UNICODE).
3) My application uses ODBC through MFC's CDatabase and CRecordset (App is UNICODE built).
Upon connection I get a buffer overrun and stack corruption. Although when I compile my App in
MBCS, all seems to work Ok. As I've told you, I download the source of the Driver and had been
able to do a fix for it, and it seems to work perfectly. Here's the line where it all happens in my app:
// My application trying to connect to the Db
CDatabase synsoftDb;
synsoftDb.OpenEx(
_T("DSN=PostgreSQL;DATABASE=synsoftdb;SERVER=localhost;PORT=5432;UID=someUser;PWD=SomePassword"), CDatabase::noOdbcDialog );
It looks like when I connect in UNICODE, the psqlodbc code 'sees' a big output buffer in:
(From psqlodbc file : dlg_specific.c)
makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len)
{
char got_dsn = (ci->dsn[0] != '\0');
char encoded_conn_settings[LARGE_REGISTRY_LEN];
UWORD hlen;
/*BOOL abbrev = (len <= 400);*/
BOOL abbrev = (len < 1024); // When my app connects in MBCS len == 512,
// but in Unicode len == 1024, which causes
// extra data to be filled below
/* fundamental info */
sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
got_dsn ? "DSN" : "DRIVER",
got_dsn ? ci->dsn : ci->drivername,
ci->database,
ci->server,
ci->port,
ci->username,
ci->password);
encode(ci->conn_settings, encoded_conn_settings);
/* extra info */
hlen = strlen(connect_string);
if (!abbrev)
// This fills the buffer way more than needed, then it's converted
// into wide chars and busts, thus creating corruption
So for the time being I've replaced :
if(!abbrev)
with
if(0)
This way no extraneous data is written, and this seems to take care of the problem for now. I'm afraid this is a 'patch' that
might not hold in other cases. Since you know the code and architecture better than I do, what do you make of this? If this
isnt clear, I will try to give more detailed and structured information if needed. Your input will be greatly apprecidated.
Thanks!