[Mono-bugs] [Bug 456234] ODBC utf8: incorrect OdbcDataReader.GetValue() result for VARCHAR if byte size >=255

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Feb 3 16:43:40 EST 2009


https://bugzilla.novell.com/show_bug.cgi?id=456234

User amc1999 at gmail.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=456234#c2


amc amc <amc1999 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P5 - None                   |P3 - Medium
                 CC|                            |amc1999 at gmail.com
            Version|1.9                         |SVN




--- Comment #2 from amc amc <amc1999 at gmail.com>  2009-02-03 14:43:39 MST ---
current SVN (2.4, 2.2, 2.0,...) version of OdbcDataReader.GetValue() simply not
work with utf-8 strings >=255 bytes. i am updating bug version to SVN and hope
it is possible to apply previously attached fix as soon as possible. just in
case i copy-paste fixed version of code here:

case OdbcType.Text:
case OdbcType.VarChar:
    bufsize = (col.MaxLength < 255 ? (col.MaxLength+1) : 255);
    buffer = new byte[bufsize];  // According to sqlext.h, use SQL_CHAR for
both char and varchar
    StringBuilder sb1 = new StringBuilder ();
    char[] charBuffer = new char[bufsize];
    Decoder defaultDecoder = Encoding.Default.GetDecoder();
    do { 
        ret = libodbc.SQLGetData (hstmt, ColIndex, col.SqlCType, buffer,
bufsize, ref outsize);
        if (ret == OdbcReturn.Error)
            break;
        // Fix for strance ODBC drivers (like psqlODBC)
        if (ret == OdbcReturn.Success && outsize==-1)
            ret = OdbcReturn.NoData;
        if (ret == OdbcReturn.Success || ret == OdbcReturn.SuccessWithInfo) {
            if (outsize >= bufsize || outsize ==
(int)OdbcLengthIndicator.NoTotal)
                outsize = bufsize - 1;
            int charCount = defaultDecoder.GetChars(buffer, 0, outsize,
charBuffer, 0);
            sb1.Append(charBuffer, 0, charCount);
        }
    } while (ret != OdbcReturn.NoData);
    DataValue = sb1.ToString ();
    break;

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list