This website is intended as archive for old content and forums.
Please visit http://opf3.codeplex.com for the project's new website.

General Discussion

FORUM TOPIC

What is Opf3? Why is Opf3? How is Opf3? All these burning questions and issues discussed here.

RSS
Thomas Meutzner
Posted on the 03/23/06 12:06 PM
ORACLE and GUID-Field
Reply Quote
 Hello,

who can i use a GUID-Field under ORACLE, under MS-SQL Server works fine.
The Oracle Field-Type is RAW(16)
I have this class:

[Persistent("TEST1")]
class cProbe
{
private Guid _id;

[Field("ID", Identifier = true, AllowDBNull = false)]
public Guid ID
{
get { return _id; }
set { _id = value; }
}
}

When i run my application, i become a InvalidCastException(Guid to byte[]).
My application must run under ORACLE or MS-SQL Server.

Thomas Meutzner


Christian Liensberger [Moderator]
Posted on the 03/23/06 12:29 PM
RE: ORACLE and GUID-Field
Reply Quote
 Hi Thomas,

The problem is that Oracle does not support GUID. You need to use string and store in there the GUID. Oracle is very special with data types (and GUID is more Microsoft specific). We can't do a transformation to string in the framework, as this would result in a very very confusing behaviour. I hope you can agree with me on that.

What we (when I worked at Sarix) did is use a string.

[Persistent("FOO")]
public class Foo
{
   private string _id = IDUtility.GenerateID();

   [Field("ID", Identifier = true, AllowDBNull = false)]
   public string ID
   {
      get { return _id; }
      private set { _id = value; }
   }
}


I would suppose to use this. I know it's not the very elegant way, but since Oracle does not support GUIDs...

You could also do something else: but this would required that you change a little bit the OracleStorage. You could implement your own OracleStorage by deriving from OracleStorage (please remove the sealed statement of the OracleStorage class definition, it will be removed in the next version of Opf3 on all storages) and implement the ICustomDataTypesStorage (Chili.Opf3.Storages) in your inherited class.

This interface allows you to react when a data type of type "GUID" is tried to be saved. You could convert it... Only react on that data type. For all other return the value without changing it. The same applies when loading an object: you convert it back to GUID, if required.

I hope this helps.

Christian

Thomas Meutzner
Posted on the 03/23/06 12:36 PM
RE: ORACLE and GUID-Field
Reply Quote
 Hello Christian,

thank you for your answer.

Thomas Meutzner
Kommunale Systemtechnik GmbH

jessn
Posted on the 09/04/06 9:11 AM
RE: ORACLE and GUID-Field
Reply Quote
 This might be a help.

CREATE table test
(
sno integer , testguid RAW(16) default SYS_GUID()
)

-- snip --
Use the NEWID() function in SQL Server to obtain a globally unique ID (GUID). 'uniqueidentifier' datatype takes effect as a global identifier and generates data by itself during insertion, only when newid() function is associated with this.

In this case, it handles it by using SYS_GUID function. Also, if 'uniqueidentifier' is used without newid() function, we need to handle in 'insert queries' (Oracle), by using 'HEXTORAW' function to insert the raw values. This could be done with the metadata information. We will update you with a patch containing this fix. Hence please specify your priority for this issue, so as to assist you at the earliest.
-- snip --

HTH

All times are in GMT.