コード例 #1
0
        private ODBC32.RetCode AutoCommitOff()
        {
            ODBC32.RetCode retcode;

            Debug.Assert(HandleState.Connected <= _handleState, "AutoCommitOff while in wrong state?");

            // Avoid runtime injected errors in the following block.
            // must call SQLSetConnectAttrW and set _handleState
            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                retcode = UnsafeNativeMethods.SQLSetConnectAttrW(this, ODBC32.SQL_ATTR.AUTOCOMMIT, ODBC32.SQL_AUTOCOMMIT_OFF, (Int32)ODBC32.SQL_IS.UINTEGER);
                switch (retcode)
                {
                case ODBC32.RetCode.SUCCESS:
                case ODBC32.RetCode.SUCCESS_WITH_INFO:
                    _handleState = HandleState.Transacted;
                    break;
                }
            }
            ODBC.TraceODBC(3, "SQLSetConnectAttrW", retcode);
            return(retcode);
        }
コード例 #2
0
        private ODBC32.RetCode Connect(string connectionString)
        {
            Debug.Assert(HandleState.Allocated == _handleState, "SQLDriverConnect while in wrong state?");

            ODBC32.RetCode retcode;

            // Avoid runtime injected errors in the following block.
            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                short cbActualSize;
                retcode = Interop.Odbc.SQLDriverConnectW(this, ADP.PtrZero, connectionString, ODBC32.SQL_NTS, ADP.PtrZero, 0, out cbActualSize, (short)ODBC32.SQL_DRIVER.NOPROMPT);
                switch (retcode)
                {
                case ODBC32.RetCode.SUCCESS:
                case ODBC32.RetCode.SUCCESS_WITH_INFO:
                    _handleState = HandleState.Connected;
                    break;
                }
            }
            ODBC.TraceODBC(3, "SQLDriverConnectW", retcode);
            return(retcode);
        }
コード例 #3
0
ファイル: Odbc32.cs プロジェクト: mikem8361/runtime
        internal static ArgumentOutOfRangeException NotSupportedIsolationLevel(IsolationLevel value)
        {
#if DEBUG
            switch (value)
            {
            case IsolationLevel.Unspecified:
            case IsolationLevel.ReadUncommitted:
            case IsolationLevel.ReadCommitted:
            case IsolationLevel.RepeatableRead:
            case IsolationLevel.Serializable:
            case IsolationLevel.Snapshot:
                Debug.Fail("valid IsolationLevel " + value.ToString());
                break;

            case IsolationLevel.Chaos:
                break;

            default:
                Debug.Fail("invalid IsolationLevel " + value.ToString());
                break;
            }
#endif
            return(ODBC.NotSupportedEnumerationValue(typeof(IsolationLevel), (int)value));
        }
コード例 #4
0
 internal ODBC32.RetCode GetDescriptionField(int i, ODBC32.SQL_DESC attribute, CNativeBuffer buffer, out int numericAttribute)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLGetDescFieldW(this, checked ((short)i), attribute, buffer, buffer.ShortLength, out numericAttribute);
     ODBC.TraceODBC(3, "SQLGetDescFieldW", retcode);
     return(retcode);
 }
コード例 #5
0
 internal ODBC32.RetCode CloseCursor()
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLCloseCursor(this);
     ODBC.TraceODBC(3, "SQLCloseCursor", retcode);
     return(retcode);
 }
コード例 #6
0
 internal ODBC32.RetCode BindColumn2(int columnNumber, ODBC32.SQL_C targetType, HandleRef buffer, IntPtr length, IntPtr srLen_or_Ind)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLBindCol(this, checked ((ushort)columnNumber), targetType, buffer, length, srLen_or_Ind);
     ODBC.TraceODBC(3, "SQLBindCol", retcode);
     return(retcode);
 }
コード例 #7
0
 internal ODBC32.RetCode Prepare(string commandText)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLPrepareW(this, commandText, ODBC32.SQL_NTS);
     ODBC.TraceODBC(3, "SQLPrepareW", retcode);
     return(retcode);
 }
コード例 #8
0
 internal ODBC32.RetCode MoreResults()
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLMoreResults(this);
     ODBC.TraceODBC(3, "SQLMoreResults", retcode);
     return(retcode);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 internal ODBC32.RetCode GetFunctions(ODBC32.SQL_API fFunction, out short fExists)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLGetFunctions(this, fFunction, out fExists);
     ODBC.TraceODBC(3, "SQLGetFunctions", retcode);
     return(retcode);
 }
コード例 #12
0
 internal ODBC32.RetCode SpecialColumns(string quotedTable)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLSpecialColumnsW(this,
                                                                     ODBC32.SQL_SPECIALCOLS.ROWVER, null, 0, null, 0,
                                                                     quotedTable, ODBC.ShortStringLength(quotedTable),
                                                                     ODBC32.SQL_SCOPE.SESSION, ODBC32.SQL_NULLABILITY.NO_NULLS);
     ODBC.TraceODBC(3, "SQLSpecialColumnsW", retcode);
     return(retcode);
 }
コード例 #13
0
 internal ODBC32.RetCode PrimaryKeys(string catalogName, string schemaName, string tableName)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLPrimaryKeysW(this,
                                                                  catalogName, ODBC.ShortStringLength(catalogName), // CatalogName
                                                                  schemaName, ODBC.ShortStringLength(schemaName),   // SchemaName
                                                                  tableName, ODBC.ShortStringLength(tableName)      // TableName
                                                                  );
     ODBC.TraceODBC(3, "SQLPrimaryKeysW", retcode);
     return(retcode);
 }
コード例 #14
0
 internal ODBC32.RetCode Prepare(string commandText)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLPrepareW(this, commandText, ODBC32.SQL_NTS);
     ODBC.TraceODBC(3, "SQLPrepareW", retcode);
     return(retcode);
 }
コード例 #15
0
 internal ODBC32.RetCode NumberOfResultColumns(out short columnsAffected)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLNumResultCols(this, out columnsAffected);
     ODBC.TraceODBC(3, "SQLNumResultCols", retcode);
     return(retcode);
 }
コード例 #16
0
 internal ODBC32.RetCode Fetch()
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLFetch(this);
     ODBC.TraceODBC(3, "SQLFetch", retcode);
     return(retcode);
 }
コード例 #17
0
 internal ODBC32.RetCode FreeStatement(ODBC32.STMT stmt)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLFreeStmt(this, stmt);
     ODBC.TraceODBC(3, "SQLFreeStmt", retcode);
     return(retcode);
 }
コード例 #18
0
 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);
 }
コード例 #19
0
 internal ODBC32.RetCode GetTypeInfo(short fSqlType)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLGetTypeInfo(this, fSqlType);
     ODBC.TraceODBC(3, "SQLGetTypeInfo", retcode);
     return(retcode);
 }
コード例 #20
0
 internal ODBC32.RetCode GetFunctions(ODBC32.SQL_API fFunction, out Int16 fExists)
 {
     ODBC32.RetCode retcode = UnsafeNativeMethods.SQLGetFunctions(this, fFunction, out fExists);
     ODBC.TraceODBC(3, "SQLGetFunctions", retcode);
     return(retcode);
 }
コード例 #21
0
 internal ODBC32.RetCode NumberOfResultColumns(out short columnsAffected)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLNumResultCols(this, out columnsAffected);
     ODBC.TraceODBC(3, "SQLNumResultCols", retcode);
     return(retcode);
 }
コード例 #22
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);
 }
コード例 #23
0
 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);
 }
コード例 #24
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);
 }
コード例 #25
0
 internal ODBC32.RetCode BindColumn3(int columnNumber, ODBC32.SQL_C targetType, IntPtr srLen_or_Ind)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLBindCol(this, checked ((ushort)columnNumber), targetType, ADP.PtrZero, ADP.PtrZero, srLen_or_Ind);
     ODBC.TraceODBC(3, "SQLBindCol", retcode);
     return(retcode);
 }
コード例 #26
0
        internal ODBC32.RetCode BeginTransaction(ref IsolationLevel isolevel)
        {
            ODBC32.RetCode  retcode = ODBC32.RetCode.SUCCESS;
            ODBC32.SQL_ATTR isolationAttribute;
            if (IsolationLevel.Unspecified != isolevel)
            {
                ODBC32.SQL_TRANSACTION sql_iso;
                switch (isolevel)
                {
                case IsolationLevel.ReadUncommitted:
                    sql_iso            = ODBC32.SQL_TRANSACTION.READ_UNCOMMITTED;
                    isolationAttribute = ODBC32.SQL_ATTR.TXN_ISOLATION;
                    break;

                case IsolationLevel.ReadCommitted:
                    sql_iso            = ODBC32.SQL_TRANSACTION.READ_COMMITTED;
                    isolationAttribute = ODBC32.SQL_ATTR.TXN_ISOLATION;
                    break;

                case IsolationLevel.RepeatableRead:
                    sql_iso            = ODBC32.SQL_TRANSACTION.REPEATABLE_READ;
                    isolationAttribute = ODBC32.SQL_ATTR.TXN_ISOLATION;
                    break;

                case IsolationLevel.Serializable:
                    sql_iso            = ODBC32.SQL_TRANSACTION.SERIALIZABLE;
                    isolationAttribute = ODBC32.SQL_ATTR.TXN_ISOLATION;
                    break;

                case IsolationLevel.Snapshot:
                    sql_iso = ODBC32.SQL_TRANSACTION.SNAPSHOT;
                    // VSDD 414121: Snapshot isolation level must be set through SQL_COPT_SS_TXN_ISOLATION (http://msdn.microsoft.com/en-us/library/ms131709.aspx)
                    isolationAttribute = ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION;
                    break;

                case IsolationLevel.Chaos:
                    throw ODBC.NotSupportedIsolationLevel(isolevel);

                default:
                    throw ADP.InvalidIsolationLevel(isolevel);
                }

                //Set the isolation level (unless its unspecified)
                retcode = SetConnectionAttribute2(isolationAttribute, (IntPtr)sql_iso, (Int32)ODBC32.SQL_IS.INTEGER);

                //Note: The Driver can return success_with_info to indicate it "rolled" the
                //isolevel to the next higher value.  If this is the case, we need to requery
                //the value if th euser asks for it...
                //We also still propagate the info, since it could be other info as well...

                if (ODBC32.RetCode.SUCCESS_WITH_INFO == retcode)
                {
                    isolevel = IsolationLevel.Unspecified;
                }
            }

            switch (retcode)
            {
            case ODBC32.RetCode.SUCCESS:
            case ODBC32.RetCode.SUCCESS_WITH_INFO:
                //Turn off auto-commit (which basically starts the transaction)
                retcode      = AutoCommitOff();
                _handleState = HandleState.TransactionInProgress;
                break;
            }
            return(retcode);
        }
コード例 #27
0
        protected OdbcHandle(ODBC32.SQL_HANDLE handleType, OdbcHandle parentHandle) : base(IntPtr.Zero, true)
        {
            _handleType = handleType;

            bool mustRelease = false;

            ODBC32.RetCode retcode = ODBC32.RetCode.SUCCESS;

            // using ConstrainedRegions to make the native ODBC call and AddRef the parent
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // validate handleType
                switch (handleType)
                {
                case ODBC32.SQL_HANDLE.ENV:
                    Debug.Assert(null == parentHandle, "did not expect a parent handle");
                    retcode = Interop.Odbc.SQLAllocHandle(handleType, IntPtr.Zero, out base.handle);
                    break;

                case ODBC32.SQL_HANDLE.DBC:
                case ODBC32.SQL_HANDLE.STMT:
                    // must addref before calling native so it won't be released just after
                    Debug.Assert(null != parentHandle, "expected a parent handle");     // safehandle can't be null
                    parentHandle.DangerousAddRef(ref mustRelease);

                    retcode = Interop.Odbc.SQLAllocHandle(handleType, parentHandle, out base.handle);
                    break;

                //              case ODBC32.SQL_HANDLE.DESC:
                default:
                    Debug.Fail("unexpected handleType");
                    break;
                }
            }
            finally
            {
                if (mustRelease)
                {
                    switch (handleType)
                    {
                    case ODBC32.SQL_HANDLE.DBC:
                    case ODBC32.SQL_HANDLE.STMT:
                        if (IntPtr.Zero != base.handle)
                        {
                            // must assign _parentHandle 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();
                        }
                        break;
                    }
                }
            }

            if ((ADP.PtrZero == base.handle) || (ODBC32.RetCode.SUCCESS != retcode))
            {
                //
                throw ODBC.CantAllocateEnvironmentHandle(retcode);
            }
        }
コード例 #28
0
 internal ODBC32.RetCode Execute()
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLExecute(this);
     ODBC.TraceODBC(3, "SQLExecute", retcode);
     return(retcode);
 }
コード例 #29
0
 internal ODBC32.RetCode SetDescriptionField2(short ordinal, ODBC32.SQL_DESC type, HandleRef value)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLSetDescFieldW(this, ordinal, type, value, 0);
     ODBC.TraceODBC(3, "SQLSetDescFieldW", retcode);
     return(retcode);
 }
コード例 #30
0
 internal ODBC32.RetCode ExecuteDirect(string commandText)
 {
     ODBC32.RetCode retcode = Interop.Odbc.SQLExecDirectW(this, commandText, ODBC32.SQL_NTS);
     ODBC.TraceODBC(3, "SQLExecDirectW", retcode);
     return(retcode);
 }