Ejemplo n.º 1
0
        internal string GetConnectAttrString(ODBC32.SQL_ATTR attribute)
        {
            string value    = "";
            int    cbActual = 0;

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

            if (null != connectionHandle)
            {
                ODBC32.RetCode retcode = connectionHandle.GetConnectionAttribute(attribute, buffer, out cbActual);
                if (buffer.Length + 2 <= cbActual)
                {
                    // 2 bytes for unicode null-termination character
                    // retry with cbActual because original buffer was too small
                    buffer  = new byte[cbActual + 2];
                    retcode = connectionHandle.GetConnectionAttribute(attribute, buffer, out cbActual);
                }
                if ((ODBC32.RetCode.SUCCESS == retcode) || (ODBC32.RetCode.SUCCESS_WITH_INFO == retcode))
                {
                    value = (BitConverter.IsLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode).GetString(buffer, 0, Math.Min(cbActual, buffer.Length));
                }
                else if (retcode == ODBC32.RetCode.ERROR)
                {
                    string sqlstate = GetDiagSqlState();
                    if (("HYC00" == sqlstate) || ("HY092" == sqlstate) || ("IM001" == sqlstate))
                    {
                        FlagUnsupportedConnectAttr(attribute);
                    }
                    // not throwing errors if not supported or other failure
                }
            }
            return(value);
        }
Ejemplo n.º 2
0
        internal string GetConnectAttrString(ODBC32.SQL_ATTR attribute)
        {
            string str2     = "";
            int    cbActual = 0;

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

            if (connectionHandle != null)
            {
                ODBC32.RetCode code = connectionHandle.GetConnectionAttribute(attribute, buffer, out cbActual);
                if ((buffer.Length + 2) <= cbActual)
                {
                    buffer = new byte[cbActual + 2];
                    code   = connectionHandle.GetConnectionAttribute(attribute, buffer, out cbActual);
                }
                if ((code == ODBC32.RetCode.SUCCESS) || (ODBC32.RetCode.SUCCESS_WITH_INFO == code))
                {
                    return(Encoding.Unicode.GetString(buffer, 0, Math.Min(cbActual, buffer.Length)));
                }
                if (code != ODBC32.RetCode.ERROR)
                {
                    return(str2);
                }
                string diagSqlState = this.GetDiagSqlState();
                if ((!("HYC00" == diagSqlState) && !("HY092" == diagSqlState)) && !("IM001" == diagSqlState))
                {
                    return(str2);
                }
                this.FlagUnsupportedConnectAttr(attribute);
            }
            return(str2);
        }
Ejemplo n.º 3
0
        internal int GetConnectAttr(ODBC32.SQL_ATTR attribute, ODBC32.HANDLER handler)
        {
            int retval   = -1;
            int cbActual = 0;

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

            if (null != connectionHandle)
            {
                ODBC32.RetCode retcode = connectionHandle.GetConnectionAttribute(attribute, buffer, out cbActual);

                if ((ODBC32.RetCode.SUCCESS == retcode) || (ODBC32.RetCode.SUCCESS_WITH_INFO == retcode))
                {
                    retval = BitConverter.ToInt32(buffer, 0);
                }
                else
                {
                    if (retcode == ODBC32.RetCode.ERROR)
                    {
                        string sqlstate = GetDiagSqlState();
                        if (("HYC00" == sqlstate) || ("HY092" == sqlstate) || ("IM001" == sqlstate))
                        {
                            FlagUnsupportedConnectAttr(attribute);
                        }
                    }
                    if (handler == ODBC32.HANDLER.THROW)
                    {
                        this.HandleError(connectionHandle, retcode);
                    }
                }
            }
            return(retval);
        }