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; }
public void SetDateTime(OciHandle handle, OciErrorHandle errorHandle, short year, byte month, byte day, byte hour, byte min, byte sec, uint fsec, string timezone) { // Get size of buffer int rsize = 0; int status = OciCalls.OCIUnicodeToCharSet(handle, null, timezone, out rsize); // Fill buffer byte[] bytes = new byte[rsize]; if (status == 0 && rsize > 0) { OciCalls.OCIUnicodeToCharSet(handle, bytes, timezone, out rsize); } if (fsec > 0) { fsec = fsec * 1000000; } uint timezoneSize = (uint)bytes.Length; OciCalls.OCIDateTimeConstruct(handle, errorHandle, this.Handle, year, month, day, hour, min, sec, fsec, bytes, timezoneSize); //uint valid = 0; //int result = OciCalls.OCIDateTimeCheck (handle, // errorHandle, this.Handle, out valid); }
public void SetDateTime (OciHandle handle, OciErrorHandle errorHandle, short year, byte month, byte day, byte hour, byte min, byte sec, uint fsec, string timezone) { // Get size of buffer ulong rsize = 0; UIntPtr rsizep = new UIntPtr (rsize); int status = OciCalls.OCIUnicodeToCharSet (handle, null, timezone, ref rsizep); // Fill buffer rsize = rsizep.ToUInt64 (); byte[] bytes = new byte[rsize]; if (status == 0 && rsize > 0) OciCalls.OCIUnicodeToCharSet (handle, bytes, timezone, ref rsizep); if (fsec > 0) fsec = fsec * 1000000; uint timezoneSize = (uint) bytes.Length; OciCalls.OCIDateTimeConstruct (handle, errorHandle, this.Handle, year, month, day, hour, min, sec, fsec, bytes, timezoneSize); //uint valid = 0; //int result = OciCalls.OCIDateTimeCheck (handle, // errorHandle, this.Handle, out valid); }
public bool BeginSession(OciCredentialType credentialType, OciSessionMode mode, OciErrorHandle error) { errorHandle = error; int status; if (credentialType == OciCredentialType.RDBMS) { if (!SetCredentialAttributes(errorHandle)) { return(false); } } status = OciCalls.OCISessionBegin(Service, errorHandle, Handle, credentialType, mode); if (status != 0) { return(false); } begun = true; return(true); }
internal bool SetCredentialAttributes(OciErrorHandle error) { errorHandle = error; int status; status = OciCalls.OCIAttrSetString(this, OciHandleType.Session, username, (uint)username.Length, OciAttributeType.Username, errorHandle); if (status != 0) { return(false); } status = OciCalls.OCIAttrSetString(this, OciHandleType.Session, password, (uint)password.Length, OciAttributeType.Password, errorHandle); if (status != 0) { return(false); } return(true); }
public string GetRowId (OciErrorHandle errorHandle) { string output = String.Empty; /* int len = 10; IntPtr outputPtr = Marshal.AllocHGlobal (len); // FIXME: how big should this be? int status = 0; status = OCIRowidToChar (this, outputPtr, ref len, errorHandle); if (status != 0) { OciErrorInfo info = errorHandle.HandleError (); throw new OracleException (info.ErrorCode, info.ErrorMessage); } if (outputPtr != IntPtr.Zero && len > 0) { object str = Marshal.PtrToStringAnsi (outputPtr, len); if (str != null) output = String.Copy ((string) str); } */ output = "NOT YET SUPPORTED."; return output; }
public DateTime GetDateTime(OciHandle handle, OciErrorHandle errorHandle) { short year = 0; byte month = 0; byte day = 0; byte hour = 0; byte min = 0; byte sec = 0; uint fsec = 0; int fs = 0; OciCalls.OCIDateTimeGetDate(handle, errorHandle, this.Handle, out year, out month, out day); OciCalls.OCIDateTimeGetTime(handle, errorHandle, this.Handle, out hour, out min, out sec, out fsec); // a TIMESTAMP can have up to 9 digits of millisecond but DateTime only // can be up to 999. if (fsec > 0) { int fseci = (int)fsec; fs = fseci / 1000000; } return(new DateTime(year, month, day, hour, min, sec, fs)); }
public void Disconnect() { if (session != null) { session.EndSession(error); session.Dispose(); session = null; } if (server != null) { server.Detach(error); server.Dispose(); server = null; } if (error != null) { error.Dispose(); error = null; } if (service != null) { service.Dispose(); service = null; } if (environment != null) { environment.Dispose(); environment = null; } }
public int GetYearToMonth(OciHandle handle, OciErrorHandle errorHandle) { int years = 0; int months = 0; OciCalls.OCIIntervalGetYearMonth(handle, errorHandle, out years, out months, this.handle); return((years * 12) + months); }
public int GetYearToMonth (OciHandle handle, OciErrorHandle errorHandle) { int years = 0; int months = 0; OciCalls.OCIIntervalGetYearMonth (handle, errorHandle, out years, out months, this.handle); return ((years * 12) + months); }
public void EndSession(OciErrorHandle error) { if (!begun) { return; } OciCalls.OCISessionEnd(Service, error, this, 0); begun = false; }
public void Detach(OciErrorHandle error) { if (!attached) return; int status = OciCalls.OCIServerDetach(this, error, 0); if (status != 0) { OciErrorInfo info = errorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } attached = false; }
public bool Attach(string tnsname, OciErrorHandle error) { errorHandle = error; int status = OciCalls.OCIServerAttach(this, error, tnsname, tnsname.Length, 0); if (status != 0) { OciErrorInfo info = errorHandle.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } attached = true; return attached; }
public TimeSpan GetDayToSecond (OciHandle handle, OciErrorHandle errorHandle) { int days = 0; int hours = 0; int mins = 0; int secs = 0; int fsec = 0; int fs = 0; OciCalls.OCIIntervalGetDaySecond (handle, errorHandle, out days, out hours, out mins, out secs, out fsec, this.handle); if (fsec > 0) { int fseci = (int) fsec; fs = fseci / 1000000; } return new TimeSpan (days, hours, mins, secs, fs); }
public TimeSpan GetDayToSecond(OciHandle handle, OciErrorHandle errorHandle) { int days = 0; int hours = 0; int mins = 0; int secs = 0; int fsec = 0; int fs = 0; OciCalls.OCIIntervalGetDaySecond(handle, errorHandle, out days, out hours, out mins, out secs, out fsec, this.handle); if (fsec > 0) { int fseci = (int)fsec; fs = fseci / 1000000; } return(new TimeSpan(days, hours, mins, secs, fs)); }
internal bool ChangePassword (string new_password, OciErrorHandle error) { if (!session.SetCredentialAttributes (error)) return false; byte[] ub = UnicodeToCharSet (session.Username byte[] opb = UnicodeToCharSet (session.Password); byte[] npb = UnicodeToCharSet (new_password); int status = OciCalls.OCIPasswordChange (this, error, ub, ub.Length, opb, opb.Length, npb, npb.Length, OCI_AUTH); if (status == 0) { session.Password = new_password; return true; } return false; }
public DateTime GetDateTime (OciHandle handle, OciErrorHandle errorHandle) { short year = 0; byte month = 0; byte day = 0; byte hour = 0; byte min = 0; byte sec = 0; uint fsec = 0; int fs = 0; OciCalls.OCIDateTimeGetDate (handle, errorHandle, this.Handle, out year, out month, out day); OciCalls.OCIDateTimeGetTime (handle, errorHandle, this.Handle, out hour, out min, out sec, out fsec); // a TIMESTAMP can have up to 9 digits of millisecond but DateTime only // can be up to 999. if (fsec > 0) { int fseci = (int) fsec; fs = fseci / 1000000; } return new DateTime(year, month, day, hour, min, sec, fs); }
public void CreateConnection(OracleConnectionInfo conInfo) { environment = new OciEnvironmentHandle(OciEnvironmentMode.Threaded | OciEnvironmentMode.NoUserCallback); if (environment.Handle == IntPtr.Zero) { throw new OracleException(0, "Could not allocate the Oracle environment."); } service = (OciServiceHandle)environment.Allocate(OciHandleType.Service); if (service == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } error = (OciErrorHandle)environment.Allocate(OciHandleType.Error); if (error == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } service.ErrorHandle = error; server = (OciServerHandle)environment.Allocate(OciHandleType.Server); if (server == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } session = (OciSessionHandle)environment.Allocate(OciHandleType.Session); if (session == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } session.Username = conInfo.Username; session.Password = conInfo.Password; session.Service = service; if (!server.Attach(conInfo.Database, ErrorHandle)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.SetServer(server)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } #if ORACLE_DATA_ACCESS if (conInfo.SetNewPassword == true) { // open with new password if (!service.SetSession(session)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.ChangePassword(conInfo.NewPassword, error)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } conInfo.Password = conInfo.NewPassword; conInfo.SetNewPassword = false; conInfo.NewPassword = string.Empty; } else { #endif // open normally if (!session.BeginSession(conInfo.CredentialType, OciSessionMode.Default, ErrorHandle)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.SetSession(session)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } #if ORACLE_DATA_ACCESS } #endif connected = true; }
public OciErrorInfo HandleError() { OciErrorInfo info = OciErrorHandle.HandleError(this); return(info); }
internal static Exception OracleError(OciErrorHandle errorHandle, int rc) { return(TraceException(OracleException.CreateException(errorHandle, rc))); }