internal static extern OdbcReturn SQLGetDiagRec( OdbcHandleType HandleType, IntPtr Handle, ushort RecordNumber, byte [] Sqlstate, ref int NativeError, byte [] MessageText, short BufferLength, ref short TextLength);
internal OdbcException CreateOdbcException(OdbcHandleType HandleType, IntPtr Handle) { short buflen = 256; short txtlen = 0; int nativeerror = 0; OdbcReturn ret = OdbcReturn.Success; OdbcErrorCollection errors = new OdbcErrorCollection(); while (true) { byte [] buf_MsgText = new byte [buflen * 2]; byte [] buf_SqlState = new byte [buflen * 2]; switch (HandleType) { case OdbcHandleType.Dbc: ret = libodbc.SQLError(IntPtr.Zero, Handle, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret = libodbc.SQLError(IntPtr.Zero, IntPtr.Zero, Handle, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret = libodbc.SQLError(Handle, IntPtr.Zero, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; } if (ret != OdbcReturn.Success) { break; } string state = RemoveTrailingNullChar(Encoding.Unicode.GetString(buf_SqlState)); string message = Encoding.Unicode.GetString(buf_MsgText, 0, txtlen * 2); errors.Add(new OdbcError(message, state, nativeerror)); } string source = SafeDriver; foreach (OdbcError error in errors) { error.SetSource(source); } return(new OdbcException(errors)); }
internal OdbcError(string Source, OdbcHandleType HandleType, IntPtr Handle) { short buflen = 256, txtlen = 0; OdbcReturn ret = OdbcReturn.Success; byte [] buf_MsgText = new byte [buflen]; byte [] buf_SqlState = new byte [buflen]; bool NeedsDecode = true; _source = Source; switch (HandleType) { case OdbcHandleType.Dbc: ret = libodbc.SQLError(IntPtr.Zero, Handle, IntPtr.Zero, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret = libodbc.SQLError(IntPtr.Zero, IntPtr.Zero, Handle, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret = libodbc.SQLError(Handle, IntPtr.Zero, IntPtr.Zero, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; default: _nativeerror = 1; _source = Source; _message = "Error in " + _source; _state = ""; NeedsDecode = false; break; } if (NeedsDecode) { if (ret != OdbcReturn.Success) { _nativeerror = 1; _source = Source; _message = "Unable to retrieve error information from ODBC driver manager"; _state = ""; } else { _state = System.Text.Encoding.Default.GetString(buf_SqlState).Replace((char)0, ' ').Trim(); _message = System.Text.Encoding.Default.GetString(buf_MsgText).Replace((char)0, ' ').Trim(); } } }
internal OdbcError(string Source, OdbcHandleType HandleType, IntPtr Handle) { short buflen=256,txtlen=0; OdbcReturn ret=OdbcReturn.Success; byte[] buf_MsgText=new byte[buflen]; byte[] buf_SqlState=new byte[buflen]; bool NeedsDecode=true; _source = Source; switch (HandleType) { case OdbcHandleType.Dbc: ret=libodbc.SQLError(IntPtr.Zero,Handle,IntPtr.Zero, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret=libodbc.SQLError(IntPtr.Zero,IntPtr.Zero,Handle, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret=libodbc.SQLError(Handle,IntPtr.Zero,IntPtr.Zero, buf_SqlState, ref _nativeerror, buf_MsgText, buflen, ref txtlen); break; default: _nativeerror = 1; _source = Source; _message = "Error in " + _source; _state = ""; NeedsDecode=false; break; } if (NeedsDecode) { if (ret!=OdbcReturn.Success) { _nativeerror = 1; _source = Source; _message = "Unable to retreive error information from ODBC driver manager"; _state = ""; } else { _state = System.Text.Encoding.Default.GetString (buf_SqlState).Replace ((char) 0, ' ').Trim (); _message = System.Text.Encoding.Default.GetString (buf_MsgText).Replace ((char) 0, ' ').Trim (); } } }
internal static extern OdbcReturn SQLGetDiagRec ( OdbcHandleType HandleType, IntPtr Handle, ushort RecordNumber, byte [] Sqlstate, ref int NativeError, byte [] MessageText, short BufferLength, ref short TextLength);
internal static extern OdbcReturn SQLAllocHandle ( OdbcHandleType HandleType, IntPtr InputHandle, ref IntPtr OutputHandlePtr);
internal static extern OdbcReturn SQLAllocHandle( OdbcHandleType HandleType, IntPtr InputHandle, ref IntPtr OutputHandlePtr);
internal static extern OdbcReturnCode SQLGetDiagRecW(OdbcHandleType handleType, OdbcHandle handle, short recordNumber, StringBuilder stateBuffer, out int nativeError, StringBuilder messageBuffer, short bufferLength, out short bufferLengthNeeded);
internal static extern OdbcReturnCode SQLFreeHandle(OdbcHandleType handleType, IntPtr handle);
internal static extern OdbcReturnCode SQLAllocHandle(OdbcHandleType handleType, OdbcConnectionHandle inputHandle, out IntPtr outputHandle);
internal static extern OdbcReturnCode SQLAllocHandle(OdbcHandleType handleType, OdbcEnvironmentHandle inputHandle, out IntPtr outputHandle);
internal static extern OdbcReturnCode SQLAllocHandle(OdbcHandleType handleType, IntPtr inputHandle, out IntPtr outputHandle);
internal static bool ReleaseHandle(OdbcHandleType handleType, IntPtr handle) { return (NativeMethods.SQLFreeHandle(handleType, handle) == OdbcReturnCode.Success); }
internal OdbcException CreateOdbcException (OdbcHandleType HandleType, IntPtr Handle) { short buflen = 256; short txtlen = 0; int nativeerror = 0; OdbcReturn ret = OdbcReturn.Success; OdbcErrorCollection errors = new OdbcErrorCollection (); while (true) { byte [] buf_MsgText = new byte [buflen * 2]; byte [] buf_SqlState = new byte [buflen * 2]; switch (HandleType) { case OdbcHandleType.Dbc: ret = libodbc.SQLError (IntPtr.Zero, Handle, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret = libodbc.SQLError (IntPtr.Zero, IntPtr.Zero, Handle, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret = libodbc.SQLError (Handle, IntPtr.Zero, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; } if (ret != OdbcReturn.Success) break; string state = RemoveTrailingNullChar (Encoding.Unicode.GetString (buf_SqlState)); string message = Encoding.Unicode.GetString (buf_MsgText, 0, txtlen * 2); errors.Add (new OdbcError (SafeDriver, message, state, nativeerror)); } string source = SafeDriver; foreach (OdbcError error in errors) error.SetSource (source); return new OdbcException (errors); }