internal IntPtr GetAttributeIntPtr(OciAttributeType attrType, OciErrorHandle errorHandle) { int status = 0; IntPtr output = IntPtr.Zero; status = OciCalls.OCIAttrGetIntPtr(Handle, HandleType, out output, IntPtr.Zero, attrType, errorHandle); if (status != 0) { OciErrorInfo info = errorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } return(output); }
public void Commit() { int status = 0; AttachToServiceContext(); try { status = OciCalls.OCITransCommit(Service, ErrorHandle, 0); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } } finally { DetachFromServiceContext(); } }
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); } }
protected override void FreeHandle() { // Parameter handles are disposed implicitely if (HandleType >= OciHandleType.LobLocator) { switch (HandleType) { case OciHandleType.Parameter: case OciHandleType.TimeStamp: break; default: if (Handle != IntPtr.Zero) { OciCalls.OCIDescriptorFree(this, HandleType); SetHandle(IntPtr.Zero); } break; } } }
public void Prepare(string commandText) { int status = 0; if (this.disposed) { throw new InvalidOperationException("StatementHandle is already disposed."); } ulong rsize = 0; byte [] buffer; UIntPtr rsizep = new UIntPtr(rsize); // Get size of buffer OciCalls.OCIUnicodeToCharSet(Parent, null, commandText, ref rsizep); rsize = rsizep.ToUInt64(); //rsize = Encoding.UTF8.GetMaxByteCount (commandText.Length+1); // Fill buffer buffer = new byte[rsize]; OciCalls.OCIUnicodeToCharSet(Parent, buffer, commandText, ref rsizep); // Execute statement status = OciCalls.OCIStmtPrepare(this, ErrorHandle, buffer, buffer.Length, OciStatementLanguage.NTV, OciStatementMode.Default); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }
public long GetLength(bool binary) { int status = 0; uint output; status = OciCalls.OCILobGetLength(Service, ErrorHandle, this, out output); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!binary) { output *= 2; } return((long)output); }
public OciParameterDescriptor GetParameter(int position) { IntPtr handle = IntPtr.Zero; int status = 0; status = OciCalls.OCIParamGet(this, OciHandleType.Statement, ErrorHandle, out handle, position + 1); if (status != 0) { OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } OciParameterDescriptor output = new OciParameterDescriptor(this, handle); output.ErrorHandle = ErrorHandle; return(output); }
void DefineTimeStamp(int position, OracleConnection connection) { definedSize = -1; ociType = OciDataType.TimeStamp; fieldType = typeof(System.DateTime); dateTimeDesc = (OciDateTimeDescriptor)connection.Environment.Allocate(OciHandleType.TimeStamp); if (dateTimeDesc == null) { OciErrorInfo info = connection.ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } value = dateTimeDesc.Handle; dateTimeDesc.ErrorHandle = ErrorHandle; int status = 0; status = OciCalls.OCIDefineByPosPtr(Parent, out handle, ErrorHandle, position + 1, ref value, definedSize, ociType, indicator, rlenp, IntPtr.Zero, 0); definedSize = 11; if (status != 0) { OciErrorInfo info = connection.ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } }
public bool Fetch() { int status = 0; if (this.disposed) { throw new InvalidOperationException("StatementHandle is already disposed."); } status = OciCalls.OCIStmtFetch(Handle, ErrorHandle.Handle, 1, 2, 0); switch (status) { case OciGlue.OCI_NO_DATA: moreResults = false; break; case OciGlue.OCI_DEFAULT: moreResults = true; break; case OciGlue.OCI_SUCCESS_WITH_INFO: //OciErrorInfo ei = ErrorHandle.HandleError (); //command.Connection.CreateInfoMessage (ei); moreResults = true; break; default: OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } return(moreResults); }
internal object GetValue(IFormatProvider formatProvider, OracleConnection conn) { object tmp; byte [] buffer = null; switch (DataType) { case OciDataType.VarChar2: case OciDataType.String: case OciDataType.VarChar: case OciDataType.Char: case OciDataType.CharZ: case OciDataType.OciString: case OciDataType.RowIdDescriptor: buffer = new byte [Size]; Marshal.Copy(Value, buffer, 0, Size); // Get length of returned string int rsize = 0; //IntPtr env = Parent.Parent; // Parent is statement, grandparent is environment IntPtr env = conn.Environment; int status = OciCalls.OCICharSetToUnicode(env, null, buffer, out rsize); OciErrorHandle.ThrowExceptionIfError(ErrorHandle, status); // Get string StringBuilder ret = new StringBuilder(rsize); status = OciCalls.OCICharSetToUnicode(env, ret, buffer, out rsize); OciErrorHandle.ThrowExceptionIfError(ErrorHandle, status); return(ret.ToString(0, rsize)); case OciDataType.LongVarChar: case OciDataType.Long: buffer = new byte [LongVarCharMaxValue]; Marshal.Copy(Value, buffer, 0, buffer.Length); int longSize = 0; if (BitConverter.IsLittleEndian) { longSize = BitConverter.ToInt32(new byte[] { buffer[0], buffer[1], buffer[2], buffer[3] }, 0); } else { longSize = BitConverter.ToInt32(new byte[] { buffer[3], buffer[2], buffer[1], buffer[0] }, 0); } ASCIIEncoding encoding = new ASCIIEncoding(); string e = encoding.GetString(buffer, 4, longSize); return(e); case OciDataType.Integer: case OciDataType.Number: case OciDataType.Float: case OciDataType.VarNum: case OciDataType.UnsignedInt: tmp = Marshal.PtrToStringAnsi(Value, Size); if (tmp != null) { return(Decimal.Parse(String.Copy((string)tmp), formatProvider)); } break; case OciDataType.TimeStamp: return(dateTimeDesc.GetDateTime(conn.Environment, dateTimeDesc.ErrorHandle)); case OciDataType.Date: return(UnpackDate()); case OciDataType.Raw: case OciDataType.VarRaw: byte [] raw_buffer = new byte [Size]; Marshal.Copy(Value, raw_buffer, 0, Size); return(raw_buffer); case OciDataType.LongRaw: case OciDataType.LongVarRaw: buffer = new byte [LongVarRawMaxValue]; Marshal.Copy(Value, buffer, 0, buffer.Length); int longrawSize = 0; if (BitConverter.IsLittleEndian) { longrawSize = BitConverter.ToInt32(new byte[] { buffer[0], buffer[1], buffer[2], buffer[3] }, 0); } else { longrawSize = BitConverter.ToInt32(new byte[] { buffer[3], buffer[2], buffer[1], buffer[0] }, 0); } byte[] longraw_buffer = new byte [longrawSize]; Array.ConstrainedCopy(buffer, 4, longraw_buffer, 0, longrawSize); return(longraw_buffer); case OciDataType.Blob: case OciDataType.Clob: return(GetOracleLob()); case OciDataType.IntervalDayToSecond: return(new OracleTimeSpan(intervalDesc.GetDayToSecond(conn.Environment, intervalDesc.ErrorHandle))); case OciDataType.IntervalYearToMonth: return(new OracleMonthSpan(intervalDesc.GetYearToMonth(conn.Environment, intervalDesc.ErrorHandle))); default: throw new Exception("OciDataType not implemented: " + DataType.ToString()); } return(DBNull.Value); }
internal OciHandle Allocate(OciHandleType type) { int status = 0; IntPtr newHandle = IntPtr.Zero; if (type < OciHandleType.LobLocator) { status = OciCalls.OCIHandleAlloc(this, out newHandle, type, 0, IntPtr.Zero); } else { status = OciCalls.OCIDescriptorAlloc(this, out newHandle, type, 0, IntPtr.Zero); } if (status != 0 && status != 1) { throw new Exception(String.Format("Could not allocate new OCI Handle of type {0}", type)); } switch (type) { case OciHandleType.Service: return(new OciServiceHandle(this, newHandle)); case OciHandleType.Error: return(new OciErrorHandle(this, newHandle)); case OciHandleType.Server: return(new OciServerHandle(this, newHandle)); case OciHandleType.Session: return(new OciSessionHandle(this, newHandle)); case OciHandleType.Statement: return(new OciStatementHandle(this, newHandle)); case OciHandleType.Transaction: return(new OciTransactionHandle(this, newHandle)); case OciHandleType.LobLocator: return(new OciLobLocator(this, newHandle)); case OciHandleType.RowId: return(new OciRowIdDescriptor(this, newHandle)); case OciHandleType.TimeStamp: return(new OciDateTimeDescriptor(this, newHandle)); case OciHandleType.IntervalDayToSecond: case OciHandleType.IntervalYearToMonth: return(new OciIntervalDescriptor(this, type, newHandle)); } return(null); }
public bool Execute(bool nonQuery, bool useAutoCommit, bool schemaOnly) { int status = 0; columnCount = 0; moreResults = false; int executeMode; if (useAutoCommit) { executeMode = (int)OciExecuteMode.CommitOnSuccess; } else { if (schemaOnly) { executeMode = (int)OciExecuteMode.DescribeOnly; } else { executeMode = (int)OciExecuteMode.Default; } } if (this.disposed) { throw new InvalidOperationException("StatementHandle is already disposed."); } status = OciCalls.OCIStmtExecute(Service, Handle, ErrorHandle, nonQuery, 0, IntPtr.Zero, IntPtr.Zero, (OciExecuteMode)executeMode); switch (status) { case OciGlue.OCI_DEFAULT: if (!nonQuery) { GetColumnCount(); Define(); moreResults = true; } break; case OciGlue.OCI_NO_DATA: break; case OciGlue.OCI_INVALID_HANDLE: throw new OracleException(0, "Invalid handle."); default: OciErrorInfo info = ErrorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } return(true); }