[#1000378] Bad VARCHAR and TEXT data type conversion

View Trackers | Bugs | Download .csv | Monitor

2005-08-25 14:07
Submitted by:
Bernard Henry Voynet (bhv)
Assigned to:
Nobody (None)
Standard conformance
Bad VARCHAR and TEXT data type conversion

Detailed description
Hello Shamar,

I am working on a project that uses ADO for accessing differents types of databases and now I must include PostgreSQL.

It seems that PgOleDb does not make any difference between fields declared in PostgreSQL as VARCHAR and TEXT and convert both to adLongVarWChar.

On an ADO point of view, a VARCHAR should be a adVarWChar up to 255 chars max
since a TEXT should be a adLongVarWChar up to 2 GB.

Since it alsways has to be done for yesterday, I hoppe a fast answer.

Excuse my poor english

Best regards


Date: 2008-03-03 17:20

Hello Shamar,

I'm working in C++ Builder with ADO component and any type that i concate in my SQL query (x||y) become a memo in my ADO component and my postgres Database have 'UTF8' like charmap how can i do to return me a varchar type.

I wait your message as soon as possible

sorry for my english !! THX
Date: 2006-04-14 19:45
Sender: Shachar Shemesh

You must not send a command to PG to change the charset. Upon initial connection, PgOleDb asks the database to perform all communication in UTF-8, regardless of what the actual database encoding is. If you explicitly send a command to tell PG to communicate otherwise, you will, indeed, get errors.

Date: 2006-03-13 21:22
Sender: TaRRaDeLo

hello, i have de same problem, i have investigate the source and i look this...

// ------------- File TypeInfo.cpp
int GetWidth_string( IPgSession *sess, const PGresult *res, int tup_num, int field_num )
// Assume all characters are going to turn into two
return (PQgetlength( res, tup_num, field_num )+1)*2;

void COPY_string( void *dst, size_t count, IPgSession *sess, const PGresult *res,
int tup_num, int field_num)
ATLASSERT(count>=GetWidth_string( sess, res, tup_num, field_num ));
int reslen=PQgetlength( res, tup_num, field_num );
WCHAR *dst_str=reinterpret_cast<WCHAR *>(dst);

const char *utf=PQgetvalue( res, tup_num, field_num );
int newlen=MultiByteToWideChar( CP_UTF8, 0, utf, reslen,
dst_str, count/sizeof(WCHAR) );

if( newlen!=0 || reslen==0 ) {
// Make sure we did not, in retrospect, overwrite the buffer.
ATLASSERT( GetWidth_string( sess, res, tup_num, field_num )>=(newlen+1)*2 );
// Success
} else {
// XXX What am I supposed to do if this fails??
ATLASSERT(!"UTF8 -> UTF16 conversion failed" );

size_t PGWidthString(const typeinfo *_this, const void *data, size_t length, IPgSession *sess)
// Can't guesstimate this one. Must return precise length.
int size=WideCharToMultiByte( CP_UTF8, 0, static_cast<const WCHAR *>(data), -1, NULL, 0,

return size!=0 ? size-1 : 0;

HRESULT PGC_string(const typeinfo *_this, const void *data, size_t length, void *dst,
size_t dstlen, IPgSession *sess )
auto_array<char> buffer(new char[dstlen+1]);

if( WideCharToMultiByte( CP_UTF8, 0, static_cast<const WCHAR *>(data), -1,
buffer.get(), dstlen+1, NULL, NULL )!=dstlen+1 )
return E_FAIL;

memcpy(dst, buffer.get(), dstlen);

return S_OK;

//--------------------End File TypeInfo.cpp

// ------------------- File PgCommand.cpp------
insert(value_type("DBTYPE_BSTR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_CHAR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_VARCHAR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_LONGVARCHAR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_WCHAR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_WVARCHAR", DBTYPE_WSTR ));
insert(value_type("DBTYPE_WLONGVARCHAR", DBTYPE_WSTR ));

// ------------End File PgCommand.cpp

all text data types are converted to WideString and VB does not interpret correctly


Table --> kkkk
Field --> code varchar(2)

SourceCode VB...

rs (Recordset to table kkkk)

rs!code = "aa"

returns error for incorrect conversion

i think one solution is to detect the charactet map from the
database, and if character map is UTF8 the driver funcionality is the same this, but if the character map not is UTF8, the conversion to UTF8 it does not have to become.

thanks in advance, and sorry too for my poor english :)

Date: 2005-08-26 08:10
Sender: Shachar Shemesh

Please point to the specs that show that this is, indeed, the correct behavior.


Attached Files:


Field Old Value Date By
CategoryNone2005-08-26 08:12shachar
GroupNone2005-08-26 08:12shachar
status_idError - Not Found2005-08-25 15:09bhv
ResolutionNone2005-08-25 15:09bhv
close_date2005-08-25 15:082005-08-25 15:08bhv
status_idOpen2005-08-25 15:08bhv
close_date2005-08-25 15:082005-08-25 15:08bhv
Powered By FusionForge