internal ODBC32.RetCode ProcedureColumns(string procedureCatalog, string procedureSchema, string procedureName, string columnName) { ODBC32.RetCode retcode = Interop.Odbc.SQLProcedureColumnsW(this, procedureCatalog, ODBC.ShortStringLength(procedureCatalog), procedureSchema, ODBC.ShortStringLength(procedureSchema), procedureName, ODBC.ShortStringLength(procedureName), columnName, ODBC.ShortStringLength(columnName)); ODBC.TraceODBC(3, "SQLProcedureColumnsW", retcode); return(retcode); }
internal ODBC32.RetCode GetDiagnosticRecord(short record, out string sqlState, StringBuilder message, out int nativeError, out short cchActual) { // ODBC (MSDN) documents it expects a buffer large enough to hold 4(+L'\0') unicode characters StringBuilder sb = new StringBuilder(5); ODBC32.RetCode retcode = Interop.Odbc.SQLGetDiagRecW(HandleType, this, record, sb, out nativeError, message, checked ((short)message.Capacity), out cchActual); ODBC.TraceODBC(3, "SQLGetDiagRecW", retcode); if ((retcode == ODBC32.RetCode.SUCCESS) || (retcode == ODBC32.RetCode.SUCCESS_WITH_INFO)) { sqlState = sb.ToString(); } else { sqlState = string.Empty; } return(retcode); }
internal OdbcConnectionHandle(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) : base(ODBC32.SQL_HANDLE.DBC, environmentHandle) { if (connection == null) { throw ADP.ArgumentNull("connection"); } if (constr == null) { throw ADP.ArgumentNull("constr"); } int connectionTimeout = connection.ConnectionTimeout; ODBC32.RetCode retcode = this.SetConnectionAttribute2(ODBC32.SQL_ATTR.LOGIN_TIMEOUT, (IntPtr)connectionTimeout, -5); string connectionString = constr.UsersConnectionString(false); retcode = this.Connect(connectionString); connection.HandleError(this, retcode); }
internal ODBC32.RetCode Tables(string tableCatalog, string tableSchema, string tableName, string tableType) { ODBC32.RetCode retcode = Interop.Odbc.SQLTablesW(this, tableCatalog, ODBC.ShortStringLength(tableCatalog), tableSchema, ODBC.ShortStringLength(tableSchema), tableName, ODBC.ShortStringLength(tableName), tableType, ODBC.ShortStringLength(tableType)); ODBC.TraceODBC(3, "SQLTablesW", retcode); return(retcode); }
internal ODBC32.RetCode Columns(string tableCatalog, string tableSchema, string tableName, string columnName) { ODBC32.RetCode retcode = UnsafeNativeMethods.SQLColumnsW(this, tableCatalog, ODBC.ShortStringLength(tableCatalog), tableSchema, ODBC.ShortStringLength(tableSchema), tableName, ODBC.ShortStringLength(tableName), columnName, ODBC.ShortStringLength(columnName)); ODBC.TraceODBC(3, "SQLColumnsW", retcode); return(retcode); }
internal ODBC32.RetCode CompleteTransaction(short transactionOperation) { bool mustRelease = false; try { DangerousAddRef(ref mustRelease); ODBC32.RetCode retcode = CompleteTransaction(transactionOperation, base.handle); return(retcode); } finally { if (mustRelease) { DangerousRelease(); } } }
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); }
internal ODBC32.RetCode Statistics(string tableCatalog, string tableSchema, string tableName, Int16 unique, Int16 accuracy) { ODBC32.RetCode retcode = UnsafeNativeMethods.SQLStatisticsW(this, tableCatalog, ODBC.ShortStringLength(tableCatalog), tableSchema, ODBC.ShortStringLength(tableSchema), tableName, ODBC.ShortStringLength(tableName), unique, accuracy); ODBC.TraceODBC(3, "SQLStatisticsW", retcode); return(retcode); }
internal ODBC32.RetCode Statistics(string tableCatalog, string tableSchema, string tableName, short unique, short accuracy) { ODBC32.RetCode retcode = Interop.Odbc.SQLStatisticsW(this, tableCatalog, ODBC.ShortStringLength(tableCatalog), tableSchema, ODBC.ShortStringLength(tableSchema), tableName, ODBC.ShortStringLength(tableName), unique, accuracy); ODBC.TraceODBC(3, "SQLStatisticsW", retcode); return(retcode); }
protected override void Dispose(bool disposing) { if (disposing) { OdbcConnectionHandle handle = _handle; _handle = null; if (null != handle) { try { ODBC32.RetCode retcode = handle.CompleteTransaction(ODBC32.SQL_ROLLBACK); if (retcode == ODBC32.RetCode.ERROR) { //don't throw an exception here, but trace it so it can be logged if (_connection != null) { Exception e = _connection.HandleErrorNoThrow(handle, retcode); ADP.TraceExceptionWithoutRethrow(e); } } } catch (Exception e) { // if (!ADP.IsCatchableExceptionType(e)) { throw; } } } if (_connection != null) { if (_connection.IsOpen) { _connection.LocalTransaction = null; } } _connection = null; _isolevel = IsolationLevel.Unspecified; } base.Dispose(disposing); }
internal bool SQLGetFunctions(ODBC32.SQL_API odbcFunction) { short num; OdbcConnectionHandle connectionHandle = this.ConnectionHandle; if (connectionHandle == null) { throw ADP.InvalidOperation("what is the right exception to throw here?"); } ODBC32.RetCode functions = connectionHandle.GetFunctions(odbcFunction, out num); if (functions != ODBC32.RetCode.SUCCESS) { this.HandleError(connectionHandle, functions); } if (num == 0) { return(false); } return(true); }
public override void Prepare() { OdbcConnection.ExecutePermission.Demand(); this.ValidateOpenConnection("Prepare"); if ((ConnectionState.Fetching & this._connection.InternalState) != ConnectionState.Closed) { throw ADP.OpenReaderExists(); } if (this.CommandType != System.Data.CommandType.TableDirect) { this.DisposeDeadDataReader(); this.GetStatementHandle(); OdbcStatementHandle statementHandle = this._cmdWrapper.StatementHandle; ODBC32.RetCode retcode = statementHandle.Prepare(this.CommandText); if (retcode != ODBC32.RetCode.SUCCESS) { this._connection.HandleError(statementHandle, retcode); } this._isPrepared = true; } }
internal void Open_ChangeDatabase(string value) { ExecutePermission.Demand(); this.CheckState("ChangeDatabase"); if ((value == null) || (value.Trim().Length == 0)) { throw ADP.EmptyDatabaseName(); } if (0x400 < ((value.Length * 2) + 2)) { throw ADP.DatabaseNameTooLong(); } this.RollbackDeadTransaction(); OdbcConnectionHandle connectionHandle = this.ConnectionHandle; ODBC32.RetCode retcode = connectionHandle.SetConnectionAttribute3(ODBC32.SQL_ATTR.CURRENT_CATALOG, value, value.Length * 2); if (retcode != ODBC32.RetCode.SUCCESS) { this.HandleError(connectionHandle, retcode); } }
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? } } }
public override void Rollback() { OdbcConnection connection = this._connection; if (connection == null) { throw ADP.TransactionZombied(this); } connection.CheckState("RollbackTransaction"); if (this._handle == null) { throw ODBC.NotInTransaction(); } ODBC32.RetCode retcode = this._handle.CompleteTransaction(1); if (retcode == ODBC32.RetCode.ERROR) { connection.HandleError(this._handle, retcode); } connection.LocalTransaction = null; this._connection = null; this._handle = null; }
internal void FreeStatementHandle(ODBC32.STMT stmt) { this.DisposeDescriptorHandle(); OdbcStatementHandle handle = this._stmt; if (handle != null) { try { ODBC32.RetCode retcode = handle.FreeStatement(stmt); this.StatementErrorHandler(retcode); } catch (Exception exception) { if (ADP.IsCatchableExceptionType(exception)) { this._stmt = null; handle.Dispose(); } throw; } } }
public override void Commit() { OdbcConnection.ExecutePermission.Demand(); OdbcConnection connection = this._connection; if (connection == null) { throw ADP.TransactionZombied(this); } connection.CheckState("CommitTransaction"); if (this._handle == null) { throw ODBC.NotInTransaction(); } ODBC32.RetCode retcode = this._handle.CompleteTransaction(0); if (retcode == ODBC32.RetCode.ERROR) { connection.HandleError(this._handle, retcode); } connection.LocalTransaction = null; this._connection = null; this._handle = null; }
public override void Cancel() { CMDWrapper wrapper = this._cmdWrapper; if (wrapper != null) { wrapper.Canceling = true; OdbcStatementHandle statementHandle = wrapper.StatementHandle; if (statementHandle != null) { lock (statementHandle) { ODBC32.RetCode retcode = statementHandle.Cancel(); switch (retcode) { case ODBC32.RetCode.SUCCESS: case ODBC32.RetCode.SUCCESS_WITH_INFO: return; } throw wrapper.Connection.HandleErrorNoThrow(statementHandle, retcode); } } } }
internal static void TraceODBC(int level, string method, ODBC32.RetCode retcode) { Bid.TraceSqlReturn("<odbc|API|ODBC|RET> %08X{SQLRETURN}, method=%ls\n", retcode, method); }
internal static Exception FailedToGetDescriptorHandle(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString("Odbc_FailedToGetDescriptorHandle", new object[] { ODBC32.RetcodeToString(retcode) }))); }
internal static Exception CantEnableConnectionpooling(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString("Odbc_CantEnableConnectionpooling", new object[] { ODBC32.RetcodeToString(retcode) }))); }
internal static Exception CantAllocateEnvironmentHandle(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString("Odbc_CantAllocateEnvironmentHandle", new object[] { ODBC32.RetcodeToString(retcode) }))); }
internal ODBC32.RetCode CloseCursor() { ODBC32.RetCode retcode = Interop.Odbc.SQLCloseCursor(this); ODBC.TraceODBC(3, "SQLCloseCursor", retcode); return(retcode); }
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); }
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); }