Пример #1
0
        private string GetInfoStringUnhandled(ODBC32.SQL_INFO info, bool handleError)
        {
            //SQLGetInfo
            string value    = null;
            short  cbActual = 0;

            byte[] buffer = new byte[100];
            OdbcConnectionHandle connectionHandle = ConnectionHandle;

            if (null != connectionHandle)
            {
                ODBC32.RetCode retcode = connectionHandle.GetInfo2(info, buffer, out cbActual);
                if (buffer.Length < cbActual - 2)
                {
                    // 2 bytes for unicode null-termination character
                    // retry with cbActual because original buffer was too small
                    buffer  = new byte[cbActual + 2];
                    retcode = connectionHandle.GetInfo2(info, buffer, out cbActual);
                }
                if (retcode == ODBC32.RetCode.SUCCESS || retcode == ODBC32.RetCode.SUCCESS_WITH_INFO)
                {
                    value = (BitConverter.IsLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode).GetString(buffer, 0, Math.Min(cbActual, buffer.Length));
                }
                else if (handleError)
                {
                    this.HandleError(ConnectionHandle, retcode);
                }
            }
            else if (handleError)
            {
                value = "";
            }
            return(value);
        }
Пример #2
0
        private string GetInfoStringUnhandled(ODBC32.SQL_INFO info, bool handleError)
        {
            string str      = null;
            short  cbActual = 0;

            byte[] buffer = new byte[100];
            OdbcConnectionHandle connectionHandle = this.ConnectionHandle;

            if (connectionHandle != null)
            {
                ODBC32.RetCode retcode = connectionHandle.GetInfo2(info, buffer, out cbActual);
                if (buffer.Length < (cbActual - 2))
                {
                    buffer  = new byte[cbActual + 2];
                    retcode = connectionHandle.GetInfo2(info, buffer, out cbActual);
                }
                if ((retcode == ODBC32.RetCode.SUCCESS) || (retcode == ODBC32.RetCode.SUCCESS_WITH_INFO))
                {
                    return(Encoding.Unicode.GetString(buffer, 0, Math.Min(cbActual, buffer.Length)));
                }
                if (handleError)
                {
                    this.HandleError(this.ConnectionHandle, retcode);
                }
                return(str);
            }
            if (handleError)
            {
                str = "";
            }
            return(str);
        }