void DefineNumber(int position, OracleConnection connection) { fieldType = typeof(System.Decimal); value = OciCalls.AllocateClear(definedSize); ociType = OciDataType.Char; int status = 0; status = OciCalls.OCIDefineByPos(Parent, out handle, ErrorHandle, position + 1, value, definedSize, ociType, indicator, rlenp, IntPtr.Zero, 0); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }
void DefineLongVarRaw(int position, OracleConnection connection) { ociType = OciDataType.LongVarRaw; fieldType = typeof(byte[]); // TODO: get via piece-wise - a chunk at a time definedSize = LongVarRawMaxValue; value = OciCalls.AllocateClear(definedSize); int status = 0; status = OciCalls.OCIDefineByPos(Parent, out handle, ErrorHandle, position + 1, value, definedSize, ociType, indicator, rlenp, IntPtr.Zero, 0); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }
internal OciRowIdDescriptor GetAttributeRowIdDescriptor(OciErrorHandle errorHandle, OciHandle env) { OciRowIdDescriptor descriptor = null; IntPtr outputPtr = IntPtr.Zero; int outSize = 16; int status = 0; OciAttributeType attrType = OciAttributeType.RowId; outputPtr = OciCalls.AllocateClear(outSize); uint siz = (uint)outSize; status = OCIAttrGetRowIdDesc(Handle, HandleType, outputPtr, ref siz, attrType, errorHandle); if (status != 0) { OciErrorInfo info = errorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (outputPtr != IntPtr.Zero && siz > 0) { descriptor = (OciRowIdDescriptor)env.Allocate(OciHandleType.RowId); descriptor.SetHandle(outputPtr); } return(descriptor); }
void DefineChar(int position, OracleConnection connection) { fieldType = typeof(System.String); int maxByteCount = Encoding.UTF8.GetMaxByteCount(definedSize); value = OciCalls.AllocateClear(maxByteCount); ociType = OciDataType.Char; int status = 0; status = OciCalls.OCIDefineByPos(Parent, out handle, ErrorHandle, position + 1, value, maxByteCount, ociType, indicator, rlenp, IntPtr.Zero, 0); OciErrorHandle.ThrowExceptionIfError(ErrorHandle, status); }
//[MonoTODO ("Only will work with 9i and above. Get it to work for 8i as well.")] internal string GetRowIdToString(OciErrorHandle errorHandle) { string output = String.Empty; int len = 18; // Universal ROWID has a length of 18 int maxByteCount = Encoding.UTF8.GetMaxByteCount(len); IntPtr outputPtr = OciCalls.AllocateClear(maxByteCount); int status = 0; ushort u = (ushort)maxByteCount; status = OCIRowidToChar(Handle, outputPtr, ref u, errorHandle); if (status != 0) { OciErrorInfo info = errorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (outputPtr != IntPtr.Zero && maxByteCount > 0) { object str = Marshal.PtrToStringAnsi(outputPtr, len); if (str != null) { output = String.Copy((string)str); } } return(output); }
void DefineRaw(int position, OracleConnection connection) { ociType = OciDataType.Raw; fieldType = typeof(byte[]); value = OciCalls.AllocateClear(definedSize); int status = 0; status = OciCalls.OCIDefineByPos(Parent, out handle, ErrorHandle, position + 1, value, definedSize * 2, ociType, ref indicator, ref rlenp, IntPtr.Zero, 0); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }
public static OciErrorInfo HandleError(OciHandle hand) { OciErrorInfo info; info.ErrorCode = 0; info.ErrorMessage = String.Empty; ulong errbufSize = 4096; UIntPtr errbufSizep = new UIntPtr(errbufSize); IntPtr errbuf = OciCalls.AllocateClear((int)errbufSize); OciCalls.OCIErrorGet(hand, 1, IntPtr.Zero, out info.ErrorCode, errbuf, (uint)errbufSize, OciHandleType.Error); byte[] bytea = new byte[errbufSize]; Marshal.Copy(errbuf, bytea, 0, (int)errbufSize); errbufSize = 0; OciHandle h = hand.Parent; if (h == null) { h = hand; } if (h == null) { throw new Exception("Internal driver error: handle is null."); } // first call to OCICharSetToUnicode gets the size OciCalls.OCICharSetToUnicode(h, null, bytea, ref errbufSizep); errbufSize = errbufSizep.ToUInt64(); StringBuilder str = new StringBuilder((int)errbufSize); // second call to OCICharSetToUnicode gets the string OciCalls.OCICharSetToUnicode(h, str, bytea, ref errbufSizep); string errmsg = String.Empty; if (errbufSize > 0) { errmsg = str.ToString(); } else { errmsg = "Internal driver error. Could not retrieve error message."; } info.ErrorMessage = String.Copy(errmsg); Marshal.FreeHGlobal(errbuf); return(info); }
public static OciErrorInfo HandleError(OciHandle hwnd, int status) { OciErrorInfo info; info.ErrorCode = status; info.ErrorMessage = OciGlue.ReturnCodeToString(status); if (status == OciGlue.OCI_ERROR || status == OciGlue.OCI_SUCCESS_WITH_INFO) { OciHandle h = hwnd; if (h == null) { throw new Exception("Internal driver error: handle is null."); } ulong errbufSize = 4096; UIntPtr errbufSizep = new UIntPtr(errbufSize); IntPtr errbuf = OciCalls.AllocateClear((int)errbufSize); OciCalls.OCIErrorGet(hwnd, 1, IntPtr.Zero, out info.ErrorCode, errbuf, (uint)errbufSize, OciHandleType.Error); byte[] bytea = new byte[errbufSize]; Marshal.Copy(errbuf, bytea, 0, (int)errbufSize); errbufSize = 0; // first call to OCICharSetToUnicode gets the size OciCalls.OCICharSetToUnicode(h, null, bytea, ref errbufSizep); errbufSize = errbufSizep.ToUInt64(); StringBuilder str = new StringBuilder((int)errbufSize); // second call to OCICharSetToUnicode gets the string OciCalls.OCICharSetToUnicode(h, str, bytea, ref errbufSizep); string errmsg = String.Empty; if (errbufSize > 0) { errmsg = str.ToString(); info.ErrorMessage = String.Copy(errmsg); } Marshal.FreeHGlobal(errbuf); } return(info); }
internal void DefineByPosition(int position, OracleConnection connection) { OciParameterDescriptor parameter = ((OciStatementHandle)Parent).GetParameter(position); name = parameter.GetName(); definedType = parameter.GetDataType(); definedSize = parameter.GetDataSize(); //precision = parameter.GetPrecision (); scale = parameter.GetScale(); rlenp = OciCalls.AllocateClear(sizeof(short)); indicator = OciCalls.AllocateClear(sizeof(short)); Define(position, connection); parameter.Dispose(); }
void DefineLongVarChar(int position, OracleConnection connection) { fieldType = typeof(System.String); // LONG VARCHAR max length is 2 to the 31 power - 5 // the first 4 bytes of a LONG VARCHAR value contains the length // Int32.MaxValue - 5 causes out of memory in mono on win32 // because I do not have 2GB of memory available // so Int16.MaxValue - 5 is used instead. // LAMESPEC for Oracle OCI - you can not get the length of the LONG VARCHAR value // until after you get the value. This could be why Oracle deprecated LONG VARCHAR. // If you specify a definedSize less then the length of the column value, // then you will get an OCI_ERROR ORA-01406: fetched column value was truncated // TODO: get via piece-wise - a chunk at a time definedSize = LongVarCharMaxValue; value = OciCalls.AllocateClear(definedSize); ociType = OciDataType.LongVarChar; int status = 0; status = OciCalls.OCIDefineByPos(Parent, out handle, ErrorHandle, position + 1, value, definedSize, ociType, indicator, rlenp, IntPtr.Zero, 0); Size = (short)definedSize; if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }