Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created September 14, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developernotes/3723995 to your computer and use it in GitHub Desktop.
Save developernotes/3723995 to your computer and use it in GitHub Desktop.
OracleDataReader ctor
// Oracle.DataAccess.Client.OracleDataReader
private IntPtr m_pColumnsDataBuffer = IntPtr.Zero;
private object m_disposeSyncObj = new object();
internal unsafe OracleDataReader(OracleConnection connection, IntPtr[] opsSqlCtx, IntPtr opsDacCtx, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, OpoDacValCtx* pOpoDacValCtx, MetaData metaData, int resultCount, CommandBehavior commandBehavior, Hashtable safeMapping, string commandText, int freeOpsSqlCtx, bool bFetchSizePropertySet)
{
int num = 0;
this.m_bBOF = true;
this.m_external = true;
this.m_safeMapping = safeMapping;
this.m_bFetchSizePropertySet = bFetchSizePropertySet;
this.m_resultCount = resultCount;
this.m_commandBehavior = commandBehavior;
this.m_connection = connection;
this.m_fetchArrayPooler = connection.m_opoConCtx.m_fetchArrayPooler;
this.m_conSignature = this.m_connection.m_conSignature;
this.m_opsSqlCtx = opsSqlCtx;
this.m_opsDacCtx = opsDacCtx;
this.m_opsErrCtx = opsErrCtx;
this.m_pOpoSqlValCtx = pOpoSqlValCtx;
this.m_fetchSize = this.m_pOpoSqlValCtx->FetchSize;
this.m_commandText = commandText;
this.m_freeOpsSqlCtx = freeOpsSqlCtx;
if (this.m_pOpoSqlValCtx->AddRowid == 1)
{
this.m_addRowid = true;
}
if (this.m_pOpoSqlValCtx->CommandType == 4 || this.m_pOpoSqlValCtx->CommandType == 2 || this.m_pOpoSqlValCtx->CommandType == 3)
{
this.m_recordsAffected = this.m_pOpoSqlValCtx->RowsAffected;
}
else
{
this.m_recordsAffected = -1;
}
this.m_opsConCtx = this.m_connection.m_opoConCtx.opsConCtx;
if (this.m_opsConCtx == IntPtr.Zero)
{
GC.SuppressFinalize(this);
throw new InvalidOperationException(OpoErrResManager.GetErrorMesg(ErrRes.CON_CLOSED, new string[0]));
}
if (this.m_connection.m_conSignature != this.m_conSignature)
{
GC.SuppressFinalize(this);
throw new InvalidOperationException(OpoErrResManager.GetErrorMesg(ErrRes.CON_REOPENED, new string[0]));
}
try
{
int num2 = OpsCon.AddRef(this.m_opsConCtx);
if (num2 <= 1)
{
throw new InvalidOperationException(OpoErrResManager.GetErrorMesg(ErrRes.CON_CLOSED, new string[0]));
}
}
catch (Exception ex)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex);
}
GC.SuppressFinalize(this);
throw;
}
if (this.m_opsErrCtx == IntPtr.Zero)
{
try
{
num = OpsErr.AllocCtx(ref this.m_opsErrCtx, this.m_opsConCtx);
}
catch (Exception ex2)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex2);
}
num = ErrRes.INT_ERR;
GC.SuppressFinalize(this);
throw;
}
finally
{
if (num != 0)
{
try
{
OpsCon.RelRef(ref this.m_opsConCtx);
}
catch (Exception ex3)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex3);
}
}
if (num != ErrRes.INT_ERR)
{
GC.SuppressFinalize(this);
OracleException.HandleError(num, this.m_connection, this.m_opsErrCtx, this);
}
}
}
}
this.m_metaData = metaData;
if (this.m_metaData != null)
{
if (!this.m_addRowid)
{
this.m_pOpoMetValCtx = this.m_metaData.m_pOpoMetValCtx;
}
else
{
this.m_pOpoMetValCtx = this.m_metaData.m_pOpoMetValCtxWRowid;
}
try
{
OpsMet.AddRef(this.m_pOpoMetValCtx);
}
catch (Exception ex4)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex4);
}
num = ErrRes.INT_ERR;
GC.SuppressFinalize(this);
throw;
}
finally
{
if (num != 0)
{
try
{
OpsCon.RelRef(ref this.m_opsConCtx);
}
catch (Exception ex5)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex5);
}
}
if (num != ErrRes.INT_ERR)
{
GC.SuppressFinalize(this);
OracleException.HandleError(num, this.m_connection, this.m_opsErrCtx, this);
}
}
}
}
if (this.m_opsSqlCtx != null && this.m_pOpoMetValCtx == null && (this.m_pOpoSqlValCtx->CommandType == 8 || this.m_pOpoSqlValCtx->CommandType == 9) && this.m_opsSqlCtx[this.m_currentResultIndex] != IntPtr.Zero)
{
try
{
num = OpsMet.GetValCtx(this.m_opsConCtx, this.m_opsErrCtx, this.m_opsSqlCtx[this.m_currentResultIndex], this.m_pOpoSqlValCtx, ref this.m_pOpoMetValCtx);
}
catch (Exception ex6)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex6);
}
num = ErrRes.INT_ERR;
throw;
}
finally
{
if (num != 0)
{
try
{
OpsCon.RelRef(ref this.m_opsConCtx);
}
catch (Exception ex7)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex7);
}
}
try
{
OpsMet.RelRef(this.m_pOpoMetValCtx);
}
catch (Exception ex8)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex8);
}
}
if (num != ErrRes.INT_ERR)
{
OracleException.HandleError(num, this.m_connection, this.m_opsErrCtx, this);
}
}
}
}
if (this.m_pOpoMetValCtx != null)
{
this.m_rowSize = (long)this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)((*this.m_pOpoMetValCtx).NoOfCols - 1) * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].Offset;
this.m_fieldCount = (int)(this.m_pOpoMetValCtx->NoOfCols - (*this.m_pOpoMetValCtx).NoOfHiddenCols);
this.m_bHasUdtType = (this.m_pOpoMetValCtx->bHasUdtType == 1);
}
try
{
if (this.m_opsDacCtx != IntPtr.Zero && pOpoDacValCtx != null)
{
this.m_pOpoDacValCtx = pOpoDacValCtx;
}
else
{
num = OpsDac.AllocValCtx(ref this.m_pOpoDacValCtx);
}
}
catch (Exception ex9)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex9);
}
num = ErrRes.INT_ERR;
throw;
}
finally
{
if (num != 0)
{
try
{
OpsCon.RelRef(ref this.m_opsConCtx);
}
catch (Exception ex10)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex10);
}
}
try
{
OpsMet.RelRef(this.m_pOpoMetValCtx);
}
catch (Exception ex11)
{
if (OraTrace.m_TraceLevel != 0u)
{
OraTrace.TraceExceptionInfo(ex11);
}
}
if (num != ErrRes.INT_ERR)
{
OracleException.HandleError(num, this.m_connection, this.m_opsErrCtx, this);
}
}
}
this.m_pOpoDacValCtx->InitialLongFS = (*this.m_pOpoSqlValCtx).InitialLongFS;
this.m_pOpoDacValCtx->InitialLobFS = (*this.m_pOpoSqlValCtx).InitialLobFS;
this.m_pOpoDacValCtx->ResultsetIndex = this.m_currentResultIndex;
this.m_pOpoDacValCtx->pSnapShot = (*pOpoSqlValCtx).pSnapShot;
pOpoSqlValCtx->pSnapShot = IntPtr.Zero;
this.m_pOpoDacValCtx->AddRowid = (*this.m_pOpoSqlValCtx).AddRowid;
this.m_pOpoDacValCtx->AddToStmtCache = (*this.m_pOpoSqlValCtx).AddToStmtCache;
this.m_isDBVer10gR2OrHigher = this.m_connection.IsDBVer10gR2OrHigher;
if (this.m_metaData != null && this.m_metaData.m_dotNetNumericAccessor != null && this.m_metaData.m_rowSize == this.m_rowSize)
{
this.m_colOffset = this.m_metaData.m_colOffset;
this.m_colIndOffset = this.m_metaData.m_colIndOffset;
this.m_colLenOffset = this.m_metaData.m_colLenOffset;
this.m_oraType = this.m_metaData.m_oraType;
this.m_oracleDbType = this.m_metaData.m_oracleDbType;
this.m_dotNetNumericAccessor = this.m_metaData.m_dotNetNumericAccessor;
}
else
{
this.m_colOffset = new uint[this.m_fieldCount];
this.m_colIndOffset = new uint[this.m_fieldCount];
this.m_colLenOffset = new uint[this.m_fieldCount];
this.m_oraType = new OraType[this.m_fieldCount];
this.m_oracleDbType = new OracleDbType[this.m_fieldCount];
this.m_dotNetNumericAccessor = new DotNetNumericAccessor[this.m_fieldCount];
for (int i = 0; i < this.m_fieldCount; i++)
{
this.m_colOffset[i] = 0u;
if (i > 0)
{
this.m_colOffset[i] = this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)(i - 1) * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].Offset;
}
this.m_colIndOffset[i] = this.m_colOffset[i] + this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)i * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].Define.Length;
this.m_colLenOffset[i] = this.m_colIndOffset[i] + 2u;
this.m_oraType[i] = (OraType)this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)i * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].OraType;
this.m_oracleDbType[i] = this.GetOraDbTypeEx(i);
int scale = (int)this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)i * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].Scale;
int precision = (int)this.m_pOpoMetValCtx->pColMetaVal[(IntPtr)i * (IntPtr)sizeof(ColMetaVal) / sizeof(ColMetaVal)].Precision;
if (scale <= 0 && precision - scale < 5)
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetInt16;
}
else
{
if (scale <= 0 && precision - scale < 10)
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetInt32;
}
else
{
if (scale <= 0 && precision - scale < 19)
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetInt64;
}
else
{
if (precision < 8 && ((scale <= 0 && precision - scale <= 38) || (scale > 0 && scale <= 44)))
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetFloat;
}
else
{
if (precision < 16)
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetDouble;
}
else
{
this.m_dotNetNumericAccessor[i] = DotNetNumericAccessor.GetDecimal;
}
}
}
}
}
}
if (this.m_metaData != null && this.m_metaData.m_dotNetNumericAccessor == null)
{
MetaData metaData2;
Monitor.Enter(metaData2 = this.m_metaData);
try
{
if (this.m_metaData.m_dotNetNumericAccessor == null)
{
this.m_metaData.m_rowSize = this.m_rowSize;
this.m_metaData.m_colOffset = this.m_colOffset;
this.m_metaData.m_colIndOffset = this.m_colIndOffset;
this.m_metaData.m_colLenOffset = this.m_colLenOffset;
this.m_metaData.m_oraType = this.m_oraType;
this.m_metaData.m_oracleDbType = this.m_oracleDbType;
this.m_metaData.m_dotNetNumericAccessor = this.m_dotNetNumericAccessor;
}
}
finally
{
Monitor.Exit(metaData2);
}
}
}
this.m_currentClientRow = 0;
this.m_recordCount = this.m_pOpoDacValCtx->RecordCount;
this.m_fetchArrayLocation = (long)this.m_pOpoSqlValCtx->FetchArrayLocation;
if (this.m_opsSqlCtx == null || this.m_pOpoMetValCtx == null || (this.m_commandBehavior & CommandBehavior.SchemaOnly) == CommandBehavior.SchemaOnly)
{
this.m_bSetLastFetch = true;
}
this.m_bCmdBehaviorSingleRow = ((this.m_commandBehavior & CommandBehavior.SingleRow) == CommandBehavior.SingleRow);
object syncRoot;
Monitor.Enter(syncRoot = this.m_connection.m_DataReaderList.SyncRoot);
try
{
this.m_connection.m_DataReaderList.Add(this);
}
finally
{
Monitor.Exit(syncRoot);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment