aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/DBGuids.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/DBGuids.cs')
-rw-r--r--OpenSim/Data/DBGuids.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/OpenSim/Data/DBGuids.cs b/OpenSim/Data/DBGuids.cs
new file mode 100644
index 0000000..1a13e06
--- /dev/null
+++ b/OpenSim/Data/DBGuids.cs
@@ -0,0 +1,44 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenMetaverse;
5
6namespace OpenSim.Data
7{
8
9 public static class DBGuid
10 {
11 /// <summary>This function converts a value returned from the database in one of the
12 /// supported formats into a UUID. This function is not actually DBMS-specific right
13 /// now
14 ///
15 /// </summary>
16 /// <param name="id"></param>
17 /// <returns></returns>
18 public static UUID FromDB(object id)
19 {
20 if( (id == null) || (id == DBNull.Value))
21 return UUID.Zero;
22
23 if (id.GetType() == typeof(Guid))
24 return new UUID((Guid)id);
25
26 if (id.GetType() == typeof(byte[]))
27 {
28 if (((byte[])id).Length == 0)
29 return UUID.Zero;
30 else if (((byte[])id).Length == 36)
31 return new UUID((byte[])id, 0);
32 }
33 else if (id.GetType() == typeof(string))
34 {
35 if (((string)id).Length == 0)
36 return UUID.Zero;
37 else if (((string)id).Length == 36)
38 return new UUID((string)id);
39 }
40
41 throw new Exception("Failed to convert db value to UUID: " + id.ToString());
42 }
43 }
44}