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); } }
protected override bool ReleaseHandle() { IntPtr statementHandle = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != statementHandle) { ODBC32.SQL_HANDLE handleType = this.HandleType; switch (handleType) { case ODBC32.SQL_HANDLE.ENV: case ODBC32.SQL_HANDLE.DBC: case ODBC32.SQL_HANDLE.STMT: { ODBC32.RetCode code = UnsafeNativeMethods.SQLFreeHandle(handleType, statementHandle); Bid.TraceSqlReturn("<odbc.SQLFreeHandle|API|ODBC|RET> %08X{SQLRETURN}\n", code); break; } } } OdbcHandle handle = this._parentHandle; this._parentHandle = null; if (handle != null) { handle.DangerousRelease(); handle = null; } return(true); }
internal static partial ODBC32.SQLRETURN SQLGetDiagFieldW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ short RecNumber, /*SQLSMALLINT*/ short DiagIdentifier, /*SQLPOINTER*/ char[] rchState, /*SQLSMALLINT*/ short BufferLength, /*SQLSMALLINT* */ out short StringLength);
internal static extern /*SQLRETURN*/ ODBC32.SQLRETURN SQLGetDiagFieldW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ short RecNumber, /*SQLSMALLINT*/ short DiagIdentifier, /*SQLPOINTER*/ [Out] StringBuilder rchState, /*SQLSMALLINT*/ short BufferLength, /*SQLSMALLINT* */ out short StringLength);
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLGetDiagFieldW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ Int16 RecNumber, /*SQLSMALLINT*/ Int16 DiagIdentifier, /*SQLPOINTER*/ StringBuilder rchState, /*SQLSMALLINT*/ Int16 BufferLength, /*SQLSMALLINT* */ out Int16 StringLength);
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLGetDiagFieldW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ short RecNumber, /*SQLSMALLINT*/ short DiagIdentifier, [MarshalAs(UnmanagedType.LPWStr)] /*SQLPOINTER*/ StringBuilder rchState, /*SQLSMALLINT*/ short BufferLength, /*SQLSMALLINT* */ out short StringLength);
internal static partial ODBC32.SQLRETURN SQLGetDiagRecW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ short RecNumber, /*SQLCHAR* */ char[] rchState, /*SQLINTEGER* */ out int NativeError, /*SQLCHAR* */ char[] MessageText, /*SQLSMALLINT*/ short BufferLength, /*SQLSMALLINT* */ out short TextLength);
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLGetDiagRecW( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle Handle, /*SQLSMALLINT*/ short RecNumber, /*SQLCHAR* */ [Out] StringBuilder rchState, /*SQLINTEGER* */ out int NativeError, /*SQLCHAR* */ [Out] StringBuilder MessageText, /*SQLSMALLINT*/ short BufferLength, /*SQLSMALLINT* */ out short TextLength);
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 = UnsafeNativeMethods.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 = UnsafeNativeMethods.SQLAllocHandle(handleType, parentHandle, out base.handle); break; // case ODBC32.SQL_HANDLE.DESC: default: Debug.Assert(false, "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; } } } Bid.TraceSqlReturn("<odbc.SQLAllocHandle|API|ODBC|RET> %08X{SQLRETURN}\n", retcode); if((ADP.PtrZero == base.handle) || (ODBC32.RetCode.SUCCESS != retcode)) { // throw ODBC.CantAllocateEnvironmentHandle(retcode); } }
protected OdbcHandle(ODBC32.SQL_HANDLE handleType, OdbcHandle parentHandle) : base(IntPtr.Zero, true) { this._handleType = handleType; bool success = false; ODBC32.RetCode sUCCESS = ODBC32.RetCode.SUCCESS; RuntimeHelpers.PrepareConstrainedRegions(); try { switch (handleType) { case ODBC32.SQL_HANDLE.ENV: sUCCESS = UnsafeNativeMethods.SQLAllocHandle(handleType, IntPtr.Zero, out this.handle); goto Label_0099; case ODBC32.SQL_HANDLE.DBC: case ODBC32.SQL_HANDLE.STMT: parentHandle.DangerousAddRef(ref success); sUCCESS = UnsafeNativeMethods.SQLAllocHandle(handleType, parentHandle, out this.handle); goto Label_0099; } } finally { if (success) { switch (handleType) { case ODBC32.SQL_HANDLE.DBC: case ODBC32.SQL_HANDLE.STMT: if (!(IntPtr.Zero != base.handle)) { goto Label_0092; } this._parentHandle = parentHandle; break; } } goto Label_0098; Label_0092: parentHandle.DangerousRelease(); Label_0098 :; } Label_0099 : Bid.TraceSqlReturn("<odbc.SQLAllocHandle|API|ODBC|RET> %08X{SQLRETURN}\n", sUCCESS); if ((ADP.PtrZero == base.handle) || (sUCCESS != ODBC32.RetCode.SUCCESS)) { throw ODBC.CantAllocateEnvironmentHandle(sUCCESS); } }
protected OdbcHandle(ODBC32.SQL_HANDLE handleType, OdbcHandle parentHandle) : base(IntPtr.Zero, true) { this._handleType = handleType; bool success = false; ODBC32.RetCode sUCCESS = ODBC32.RetCode.SUCCESS; RuntimeHelpers.PrepareConstrainedRegions(); try { switch (handleType) { case ODBC32.SQL_HANDLE.ENV: sUCCESS = UnsafeNativeMethods.SQLAllocHandle(handleType, IntPtr.Zero, out this.handle); goto Label_0099; case ODBC32.SQL_HANDLE.DBC: case ODBC32.SQL_HANDLE.STMT: parentHandle.DangerousAddRef(ref success); sUCCESS = UnsafeNativeMethods.SQLAllocHandle(handleType, parentHandle, out this.handle); goto Label_0099; } } finally { if (success) { switch (handleType) { case ODBC32.SQL_HANDLE.DBC: case ODBC32.SQL_HANDLE.STMT: if (!(IntPtr.Zero != base.handle)) { goto Label_0092; } this._parentHandle = parentHandle; break; } } goto Label_0098; Label_0092: parentHandle.DangerousRelease(); Label_0098:; } Label_0099: Bid.TraceSqlReturn("<odbc.SQLAllocHandle|API|ODBC|RET> %08X{SQLRETURN}\n", sUCCESS); if ((ADP.PtrZero == base.handle) || (sUCCESS != ODBC32.RetCode.SUCCESS)) { throw ODBC.CantAllocateEnvironmentHandle(sUCCESS); } }
override protected bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible. IntPtr handle = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != handle) { ODBC32.SQL_HANDLE handleType = HandleType; switch (handleType) { case ODBC32.SQL_HANDLE.DBC: // Disconnect happens in OdbcConnectionHandle.ReleaseHandle case ODBC32.SQL_HANDLE.ENV: case ODBC32.SQL_HANDLE.STMT: ODBC32.RetCode retcode = UnsafeNativeMethods.SQLFreeHandle(handleType, handle); Bid.TraceSqlReturn("<odbc.SQLFreeHandle|API|ODBC|RET> %08X{SQLRETURN}\n", retcode); break; case ODBC32.SQL_HANDLE.DESC: // nothing to free on the handle break; // case 0: ThreadAbortException setting handle before HandleType default: Debug.Assert(ADP.PtrZero == handle, "unknown handle type"); break; } } // If we ended up getting released, then we have to release // our reference on our parent. OdbcHandle parentHandle = _parentHandle; _parentHandle = null; if (null != parentHandle) { parentHandle.DangerousRelease(); parentHandle = null; } return(true); }
protected override bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible. IntPtr handle = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != handle) { ODBC32.SQL_HANDLE handleType = HandleType; switch (handleType) { case ODBC32.SQL_HANDLE.DBC: // Disconnect happens in OdbcConnectionHandle.ReleaseHandle case ODBC32.SQL_HANDLE.ENV: case ODBC32.SQL_HANDLE.STMT: Interop.Odbc.SQLFreeHandle(handleType, handle); break; case ODBC32.SQL_HANDLE.DESC: // nothing to free on the handle break; // case 0: ThreadAbortException setting handle before HandleType default: Debug.Assert(ADP.PtrZero == handle, "unknown handle type"); break; } } // If we ended up getting released, then we have to release // our reference on our parent. OdbcHandle?parentHandle = _parentHandle; if (parentHandle != null) { _parentHandle = null; parentHandle.DangerousRelease(); } return(true); }
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 }
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLAllocHandle( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle InputHandle, /*SQLHANDLE* */ out IntPtr OutputHandle);
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLFreeHandle( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHSTMT*/ IntPtr StatementHandle);
internal static extern /*SQLRETURN*/ ODBC32.RetCode SQLEndTran( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ IntPtr Handle, /*SQLSMALLINT*/ short CompletionType);
internal static partial ODBC32.SQLRETURN SQLAllocHandle( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ OdbcHandle InputHandle, /*SQLHANDLE* */ out IntPtr OutputHandle);
internal static extern ODBC32.RetCode SQLGetDiagFieldW(ODBC32.SQL_HANDLE HandleType, OdbcHandle Handle, short RecNumber, short DiagIdentifier, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder rchState, short BufferLength, out short StringLength);
internal static partial ODBC32.SQLRETURN SQLFreeHandle( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHSTMT*/ IntPtr StatementHandle);
internal static partial ODBC32.SQLRETURN SQLEndTran( /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType, /*SQLHANDLE*/ IntPtr Handle, /*SQLSMALLINT*/ short CompletionType);
internal static extern ODBC32.RetCode SQLAllocHandle(ODBC32.SQL_HANDLE HandleType, IntPtr InputHandle, out IntPtr OutputHandle);
internal static extern ODBC32.RetCode SQLEndTran(ODBC32.SQL_HANDLE HandleType, IntPtr Handle, short CompletionType);
internal static extern ODBC32.RetCode SQLFreeHandle(ODBC32.SQL_HANDLE HandleType, IntPtr StatementHandle);
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); } }
internal static extern ODBC32.RetCode SQLGetDiagRecW(ODBC32.SQL_HANDLE HandleType, OdbcHandle Handle, short RecNumber, StringBuilder rchState, out int NativeError, StringBuilder MessageText, short BufferLength, out short TextLength);
protected OdbcHandle(ODBC32.SQL_HANDLE handleType, OdbcHandle parentHandle) : base(IntPtr.Zero, true) { throw new NotImplementedException(); }