Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception using ErrorHandler when iterating through a result set. #593

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,19 +1650,37 @@ public string ExecuteDataSet()
}
catch(GxADODataException e)
{
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.ExecuteDataSet Error ");
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
return "";
}

internal bool ProcessException(GxADODataException e, ref bool retry, int retryCount, string method)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, method, ref pe, ref retry);
if (!pe)
{
try
{
Close();
con.Close();
}
catch (Exception ex)
{
GXLogging.Warn(log, ex, "GxCommand.Close Error on ProcessException");
}
}
return pe;
}

public IDataReader ExecuteReader()
{
try
Expand Down Expand Up @@ -1730,22 +1748,12 @@ public void FetchData(out IDataReader dr)
catch (GxADODataException e)
{
status=0;
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "FETCH");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "FETCH", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchData Error ");
try
{
Close();
con.Close();
}
catch(Exception ex)
{
GXLogging.Error(log, ex, "GxCommand.FetchData-Close Error ");
}
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand All @@ -1767,13 +1775,12 @@ public void FetchDataRPC(out IDataReader dr)
catch (GxADODataException e)
{
status=0;
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "FETCH");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "FETCH", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchDataRPC Error ");
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand Down Expand Up @@ -1890,13 +1897,12 @@ public void ExecuteBatch()
}
catch (GxADODataException e)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand All @@ -1919,14 +1925,13 @@ private void execStmt()
status = 0;
}
catch (GxADODataException e)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
{
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand Down
34 changes: 20 additions & 14 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,24 @@ private void execute(int cursor, Object[] parms, bool batch)

public void readNext(int cursor)
{
ICursor oCur = getCursor(cursor);
oCur.readNext();
_dataStoreHelper.getResults(cursor, oCur.getFieldGetter(), results[cursor]);
dataStoreRequestCount++;
Cursor oCur = getCursor(cursor) as Cursor;
try
{
oCur.readNext();
_dataStoreHelper.getResults(cursor, oCur.getFieldGetter(), results[cursor]);
dataStoreRequestCount++;
}
catch (GxADODataException e)
{
bool retry = false;
int retryCount = 0;
bool pe = oCur.Command.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "readNext Error", e);
if (!pe)
{
throw;
}
}

}
public int getStatus(int cursorIdx)
Expand Down Expand Up @@ -538,19 +552,15 @@ private void commitDataStore(IGxDataStore ds, String auditObjectName)
catch (Exception dbEx)
{
//If commit fails it should not retry, it makes no sense because it will no longer be possible. just close the existing connection.
int status = 0;
GxADODataException e = new GxADODataException(dbEx);
bool retry = false;
int retryCount = 0;
bool pe = ds.Connection.DataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, cmd.ErrorMask, ds.Connection, ref status, ref retry, retryCount);
GXLogging.Error(log, "Commit Transaction Error", e);
retryCount++;
cmd.processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, cmd.ErrorMask, "FETCH", ref pe, ref retry);
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
if (!pe)
{
try
{
ds.Connection.Close();
if (retry)
ds.Connection.Open();
}
Expand All @@ -574,19 +584,15 @@ private void rollbackDataStore(IGxDataStore ds, String auditObjectName)
}
catch (Exception dbEx)
{
int status = 0;
GxADODataException e = new GxADODataException(dbEx);
bool retry = false;
int retryCount = 0;
bool pe = ds.Connection.DataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, cmd.ErrorMask, ds.Connection, ref status, ref retry, retryCount);
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "Rollback Transaction Error", e);
retryCount++;
cmd.processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, cmd.ErrorMask, "FETCH", ref pe, ref retry);
if (!pe)
{
try
{
ds.Connection.Close();
if (retry)
ds.Connection.Open();
}
Expand Down
38 changes: 21 additions & 17 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,12 @@ public Cursor(string name, string stmt, GxErrorMask nmask, ICollection parmBinds
{
_staticParameters = staticPars;
}
internal GxCommand Command
{
get { return _gxDbCommand; }
}

public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
{

if (_state >= 2)
Expand Down Expand Up @@ -1192,24 +1196,24 @@ public override void execute()
_status = Cursor.EOF;
_closed = false;
}
public override void readNext()
{
if (_state < 2)
throw (new GxADODataException("Could not readNext in ForEachCursor:" + _name + "."));
_status = 0;
public override void readNext()
{
if (_state < 2)
throw (new GxADODataException("Could not readNext in ForEachCursor:" + _name + "."));
_status = 0;

if (!_DR.Read())
{
_status = Cursor.EOF;
_gxDbCommand.HasMoreRows = false;
}
else if (_gxDbCommand.Status == 1 || _gxDbCommand.Status == 103 || _gxDbCommand.Status == 500)
{
_status = _gxDbCommand.Status;
}
if (!_DR.Read())
{
_status = Cursor.EOF;
_gxDbCommand.HasMoreRows = false;
}
else if (_gxDbCommand.Status == 1 || _gxDbCommand.Status == 103 || _gxDbCommand.Status == 500)
{
_status = _gxDbCommand.Status;
}

}
}
}
}
public class UpdateCursor : Cursor
{
public UpdateCursor(CursorDef def) : base(def.Name, def.Stmt, def.Nmask, def.ParmBinds, 0)
Expand Down