[unixODBC-support] Buffer Lengths in Chars or Bytes?

Nick Gorham nick at lurcher.org
Thu Jul 18 19:55:49 BST 2013

On 18/07/13 19:13, Frank A. U. wrote:
> Hello,
> How are string lengths communicated in ODBC?
> If an ODBC function wants to pass a string to the application I assume
> that the application has to allocate a buffer and pass it and the length
> of that buffer as input to the ODBC function.
> For specifying the length of the input buffer there are generally two
> possibilities: number of chars or number of bytes.
> I do not have much experience with ODBC and just starting to read the MS
> reference.  For example it says SQLGetDiagRec() expects the buffer
> length to be the number of chars which works fine for any fixed length
> char encoding (e.g. ISO-8859-1 or UCS-16).  However it leaves out the
> case of UTF-8 where the char byte length varies.  The only working
> solution that comes to my mind is to pass the buffer length in bytes in
> this case.
> Are my assumptions correct?
> Thanks,
> Frank

Yep, ODBC and UTF-8 is not well defined. Any buffer length should be 
regarded as bytes.


More information about the unixODBC-support mailing list