aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/DBGuids.cs
diff options
context:
space:
mode:
authorMelanie2010-05-18 23:02:05 +0100
committerMelanie2010-05-18 23:02:10 +0100
commit397326ddfa5fd14b8423a152dd9ec5a471924a41 (patch)
tree8f719ceba221fd7980b7354bb1928ae734c84fc9 /OpenSim/Data/DBGuids.cs
parentRevert "Looks like the new files were never added to prebuild.xml" (diff)
parentSome more corrections after MySQL connector update (diff)
downloadopensim-SC_OLD-397326ddfa5fd14b8423a152dd9ec5a471924a41.zip
opensim-SC_OLD-397326ddfa5fd14b8423a152dd9ec5a471924a41.tar.gz
opensim-SC_OLD-397326ddfa5fd14b8423a152dd9ec5a471924a41.tar.bz2
opensim-SC_OLD-397326ddfa5fd14b8423a152dd9ec5a471924a41.tar.xz
Merge commit 'alex/Migrations'
Another stab at the tests Signed-off-by: Melanie <melanie@t-data.com>
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}