GetGuid from OracleDataReader

S

sjoshi

Hi All

It seems I can't use this to get Guid from OracleDataReader

int iOid = oRdr.GetOrdinal("OID");
while(oRdr.Read())
{
// Guid theOid = oRdr.GetGuid(iOid); //This fails in Oracle
Guid theOid = GetGuidFromRAW(oRdr.GetValue(iOid));
}

I have to use this kludge instead:

public static Guid GetGuidFromRAW(object oracleRaw)
{
byte[] b = (System.Byte[])oracleRaw;
return new System.Guid(b);
}

Is this a known issue ??

thanks
Sunit
 
F

Frans Bouma [C# MVP]

sjoshi said:
Hi All

It seems I can't use this to get Guid from OracleDataReader

int iOid = oRdr.GetOrdinal("OID");
while(oRdr.Read())
{
// Guid theOid = oRdr.GetGuid(iOid); //This fails in Oracle
Guid theOid = GetGuidFromRAW(oRdr.GetValue(iOid));
}

I have to use this kludge instead:

public static Guid GetGuidFromRAW(object oracleRaw)
{
byte[] b = (System.Byte[])oracleRaw;
return new System.Guid(b);
}

Is this a known issue ??

It's indeed a misleading thing. The method code is:

/// <summary>Gets the value of the specified column as a
globally-unique identifier (GUID).</summary>
/// <returns>The value of the specified column as a GUID.</returns>
/// <param name="i">The zero-based column ordinal. </param>
/// <exception cref="T:System.InvalidCastException">The specified cast
is not valid. </exception>
public override Guid GetGuid(int i)
{
throw ADP.NotSupported();
}


While there's a complete documentation page in the MSDN about
OracleDataReader.GetGuid() and that it returns the specified column's
value as a GUID.

I think it's because the base class (DbDataReader) defines this
method, however on Oracle it's often unclear how a GUID is stored: in a
CHAR(16) binary, in a CHAR(32), in a RAW(16) ? ...

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
S

sjoshi

Ok thanks...so I guess I have to use the kludge I mentioned earlier for
Oracle then.

Sunit
sjoshi said:
Hi All

It seems I can't use this to get Guid from OracleDataReader

int iOid = oRdr.GetOrdinal("OID");
while(oRdr.Read())
{
// Guid theOid = oRdr.GetGuid(iOid); //This fails in Oracle
Guid theOid = GetGuidFromRAW(oRdr.GetValue(iOid));
}

I have to use this kludge instead:

public static Guid GetGuidFromRAW(object oracleRaw)
{
byte[] b = (System.Byte[])oracleRaw;
return new System.Guid(b);
}

Is this a known issue ??

It's indeed a misleading thing. The method code is:

/// <summary>Gets the value of the specified column as a
globally-unique identifier (GUID).</summary>
/// <returns>The value of the specified column as a GUID.</returns>
/// <param name="i">The zero-based column ordinal. </param>
/// <exception cref="T:System.InvalidCastException">The specified cast
is not valid. </exception>
public override Guid GetGuid(int i)
{
throw ADP.NotSupported();
}


While there's a complete documentation page in the MSDN about
OracleDataReader.GetGuid() and that it returns the specified column's
value as a GUID.

I think it's because the base class (DbDataReader) defines this
method, however on Oracle it's often unclear how a GUID is stored: in a
CHAR(16) binary, in a CHAR(32), in a RAW(16) ? ...

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top