Esempio 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);
        }
        internal OdbcHandle(OdbcStatementHandle parentHandle, ODBC32.SQL_ATTR attribute) : base(IntPtr.Zero, true)
        {
            ODBC32.RetCode code;
            this._handleType = ODBC32.SQL_HANDLE.DESC;
            bool success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                int num;
                parentHandle.DangerousAddRef(ref success);
                code = parentHandle.GetStatementAttribute(attribute, out this.handle, out num);
            }
            finally
            {
                if (success)
                {
                    if (IntPtr.Zero != base.handle)
                    {
                        this._parentHandle = parentHandle;
                    }
                    else
                    {
                        parentHandle.DangerousRelease();
                    }
                }
            }
            if (ADP.PtrZero == base.handle)
            {
                throw ODBC.FailedToGetDescriptorHandle(code);
            }
        }
Esempio 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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        // Get the Descriptor Handle for the current statement
        //
        internal OdbcDescriptorHandle GetDescriptorHandle(ODBC32.SQL_ATTR attribute)
        {
            OdbcDescriptorHandle hdesc = _hdesc;

            if (null == _hdesc)
            {
                _hdesc = hdesc = new OdbcDescriptorHandle(_stmt, attribute);
            }
            return(hdesc);
        }
Esempio n. 6
0
        internal OdbcDescriptorHandle GetDescriptorHandle(ODBC32.SQL_ATTR attribute)
        {
            OdbcDescriptorHandle handle = this._hdesc;

            if (this._hdesc == null)
            {
                this._hdesc = handle = new OdbcDescriptorHandle(this._stmt, attribute);
            }
            return(handle);
        }
 private void TrySetStatementAttribute(OdbcStatementHandle stmt, ODBC32.SQL_ATTR stmtAttribute, IntPtr value)
 {
     if (stmt.SetStatementAttribute(stmtAttribute, value, ODBC32.SQL_IS.UINTEGER) == ODBC32.RetCode.ERROR)
     {
         string str;
         stmt.GetDiagnosticField(out str);
         switch (str)
         {
         case "HYC00":
         case "HY092":
             this.Connection.FlagUnsupportedStmtAttr(stmtAttribute);
             break;
         }
     }
 }
Esempio n. 8
0
        internal void FlagUnsupportedStmtAttr(ODBC32.SQL_ATTR Attribute)
        {
            switch (Attribute)
            {
            case ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION:
                this.ProviderInfo.NoSqlSoptSSHiddenColumns = true;
                return;

            case ((ODBC32.SQL_ATTR) 0x4cc):
                this.ProviderInfo.NoSqlSoptSSNoBrowseTable = true;
                return;

            case ODBC32.SQL_ATTR.QUERY_TIMEOUT:
                this.ProviderInfo.NoQueryTimeout = true;
                return;
            }
        }
Esempio n. 9
0
        internal void FlagUnsupportedConnectAttr(ODBC32.SQL_ATTR Attribute)
        {
            switch (Attribute)
            {
            case ODBC32.SQL_ATTR.CURRENT_CATALOG:
                ProviderInfo.NoCurrentCatalog = true;
                break;

            case ODBC32.SQL_ATTR.CONNECTION_DEAD:
                ProviderInfo.NoConnectionDead = true;
                break;

            default:
                Debug.Fail("Can't flag unknown Attribute");
                break;
            }
        }
Esempio n. 10
0
 internal void FlagUnsupportedConnectAttr(ODBC32.SQL_ATTR Attribute)
 {
     ODBC32.SQL_ATTR sql_attr = Attribute;
     if (sql_attr != ODBC32.SQL_ATTR.CURRENT_CATALOG)
     {
         if (sql_attr != ODBC32.SQL_ATTR.CONNECTION_DEAD)
         {
             return;
         }
     }
     else
     {
         this.ProviderInfo.NoCurrentCatalog = true;
         return;
     }
     this.ProviderInfo.NoConnectionDead = true;
 }
Esempio n. 11
0
        internal OdbcHandle(OdbcStatementHandle parentHandle, ODBC32.SQL_ATTR attribute) : base(IntPtr.Zero, true)
        {
            Debug.Assert((ODBC32.SQL_ATTR.APP_PARAM_DESC == attribute) || (ODBC32.SQL_ATTR.APP_ROW_DESC == attribute), "invalid attribute");
            _handleType = ODBC32.SQL_HANDLE.DESC;

            int cbActual;

            ODBC32.RetCode retcode;
            bool           mustRelease = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // must addref before calling native so it won't be released just after
                parentHandle.DangerousAddRef(ref mustRelease);

                retcode = parentHandle.GetStatementAttribute(attribute, out base.handle, out cbActual);
            }
            finally
            {
                if (mustRelease)
                {
                    if (IntPtr.Zero != base.handle)
                    {
                        // must call DangerousAddRef after a handle is actually created
                        // since ReleaseHandle will only call DangerousRelease if a handle exists
                        _parentHandle = parentHandle;
                    }
                    else
                    {
                        // without a handle, ReleaseHandle may not be called
                        parentHandle.DangerousRelease();
                    }
                }
            }
            if (ADP.PtrZero == base.handle)
            {
                throw ODBC.FailedToGetDescriptorHandle(retcode);
            }
            // no info-message handle on getting a descriptor handle
        }
Esempio n. 12
0
        internal void FlagUnsupportedStmtAttr(ODBC32.SQL_ATTR Attribute)
        {
            switch (Attribute)
            {
            case ODBC32.SQL_ATTR.QUERY_TIMEOUT:
                ProviderInfo.NoQueryTimeout = true;
                break;

            case (ODBC32.SQL_ATTR)ODBC32.SQL_SOPT_SS.NOBROWSETABLE:
                ProviderInfo.NoSqlSoptSSNoBrowseTable = true;
                break;

            case (ODBC32.SQL_ATTR)ODBC32.SQL_SOPT_SS.HIDDEN_COLUMNS:
                ProviderInfo.NoSqlSoptSSHiddenColumns = true;
                break;

            default:
                Debug.Fail("Can't flag unknown Attribute");
                break;
            }
        }
Esempio n. 13
0
        private void TrySetStatementAttribute(OdbcStatementHandle stmt, ODBC32.SQL_ATTR stmtAttribute, IntPtr value)
        {
            ODBC32.RetCode retcode = stmt.SetStatementAttribute(
                stmtAttribute,
                value,
                ODBC32.SQL_IS.UINTEGER);

            if (retcode == ODBC32.RetCode.ERROR)
            {
                string sqlState;
                stmt.GetDiagnosticField(out sqlState);

                if ((sqlState == "HYC00") || (sqlState == "HY092"))
                {
                    Connection.FlagUnsupportedStmtAttr(stmtAttribute);
                }
                else
                {
                    // now what? Should we throw?
                }
            }
        }
 internal ODBC32.RetCode GetConnectionAttribute(ODBC32.SQL_ATTR attribute, byte[] buffer, out int cbActual)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLGetConnectAttrW(this, attribute, buffer, buffer.Length, out cbActual);
     return(retcode);
 }
 internal ODBC32.RetCode SetStatementAttribute(ODBC32.SQL_ATTR attribute, IntPtr value, ODBC32.SQL_IS stringLength)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLSetStmtAttrW(this, (int)attribute, value, (int)stringLength);
     ODBC.TraceODBC(3, "SQLSetStmtAttrW", retcode);
     return(retcode);
 }
Esempio n. 16
0
 internal ODBC32.RetCode GetConnectionAttribute(ODBC32.SQL_ATTR attribute, byte[] buffer, out int cbActual)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLGetConnectAttrW(this, attribute, buffer, buffer.Length, out cbActual);
     Bid.Trace("<odbc.SQLGetConnectAttr|ODBC> SQLRETURN=%d, Attribute=%d, BufferLength=%d, StringLength=%d\n", (int)retcode, (int)attribute, buffer.Length, (int)cbActual);
     return(retcode);
 }
Esempio n. 17
0
 internal OdbcDescriptorHandle GetDescriptorHandle(ODBC32.SQL_ATTR attribute)
 {
     return(_cmdWrapper !.GetDescriptorHandle(attribute));
 }
Esempio n. 18
0
 // user can set SQL_ATTR_CONNECTION_POOLING attribute with envHandle = null, this attribute is process-level attribute
 internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLSetEnvAttr(
     /*SQLHENV*/ OdbcEnvironmentHandle EnvironmentHandle,
     /*SQLINTEGER*/ ODBC32.SQL_ATTR Attribute,
     /*SQLPOINTER*/ IntPtr Value,
     /*SQLINTEGER*/ ODBC32.SQL_IS StringLength);
Esempio n. 19
0
 internal OdbcDescriptorHandle(OdbcStatementHandle statementHandle, ODBC32.SQL_ATTR attribute) : base(statementHandle, attribute)
 {
 }
Esempio n. 20
0
 internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLSetConnectAttrW(
     /*SQLHBDC*/ OdbcConnectionHandle ConnectionHandle,
     /*SQLINTEGER*/ ODBC32.SQL_ATTR Attribute,
     /*SQLPOINTER*/ IntPtr Value,
     /*SQLINTEGER*/ int StringLength);
Esempio n. 21
0
 internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLSetConnectAttrW( // used only for AutoCommitOn
                                                                         /*SQLHBDC*/ IntPtr ConnectionHandle,
     /*SQLINTEGER*/ ODBC32.SQL_ATTR Attribute,
     /*SQLPOINTER*/ IntPtr Value,
     /*SQLINTEGER*/ int StringLength);
 internal ODBC32.RetCode SetConnectionAttribute4(ODBC32.SQL_ATTR attribute, System.Transactions.IDtcTransaction transaction, int length)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLSetConnectAttrW(this, attribute, transaction, length);
     ODBC.TraceODBC(3, "SQLSetConnectAttrW", retcode);
     return(retcode);
 }
Esempio n. 23
0
 internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLGetStmtAttrW(
     /*SQLHSTMT*/ OdbcStatementHandle StatementHandle,
     /*SQLINTEGER*/ ODBC32.SQL_ATTR Attribute,
     /*SQLPOINTER*/ out IntPtr Value,
     /*SQLINTEGER*/ int BufferLength,
     /*SQLINTEGER*/ out int StringLength);
Esempio n. 24
0
 internal ODBC32.RetCode SetConnectionAttribute2(ODBC32.SQL_ATTR attribute, IntPtr value, Int32 length)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLSetConnectAttrW(this, attribute, value, length);
     ODBC.TraceODBC(3, "SQLSetConnectAttrW", retcode);
     return(retcode);
 }
 internal ODBC32.RetCode GetStatementAttribute(ODBC32.SQL_ATTR attribute, out IntPtr value, out int stringLength)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLGetStmtAttrW(this, attribute, out value, ADP.PtrSize, out stringLength);
     ODBC.TraceODBC(3, "SQLGetStmtAttrW", retcode);
     return(retcode);
 }
 internal ODBC32.RetCode SetConnectionAttribute2(ODBC32.SQL_ATTR attribute, IntPtr value, int length)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLSetConnectAttrW(this, attribute, value, length);
     ODBC.TraceODBC(3, "SQLSetConnectAttrW", retcode);
     return(retcode);
 }
Esempio n. 27
0
 internal ODBC32.RetCode SetConnectionAttribute3(ODBC32.SQL_ATTR attribute, string buffer, Int32 length)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLSetConnectAttrW(this, attribute, buffer, length);
     Bid.Trace("<odbc.SQLSetConnectAttr|ODBC> SQLRETURN=%d, Attribute=%d, BufferLength=%d\n", (int)retcode, (int)attribute, buffer.Length);
     return(retcode);
 }
Esempio n. 28
0
 internal ODBC32.RetCode SetConnectionAttribute4(ODBC32.SQL_ATTR attribute, System.Transactions.IDtcTransaction transaction, Int32 length)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLSetConnectAttrW(this, attribute, transaction, length);
     ODBC.TraceODBC(3, "SQLSetConnectAttrW", retcode);
     return(retcode);
 }
Esempio n. 29
0
 internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLGetConnectAttrW(
     /*SQLHBDC*/ OdbcConnectionHandle ConnectionHandle,
     /*SQLINTEGER*/ ODBC32.SQL_ATTR Attribute,
     /*SQLPOINTER*/ byte[] Value,
     /*SQLINTEGER*/ int BufferLength,
     /*SQLINTEGER* */ out int StringLength);
 internal ODBC32.RetCode SetConnectionAttribute3(ODBC32.SQL_ATTR attribute, string buffer, int length)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLSetConnectAttrW(this, attribute, buffer, length);
     return(retcode);
 }