diff options
author | Melanie | 2010-05-18 23:02:05 +0100 |
---|---|---|
committer | Melanie | 2010-05-18 23:02:10 +0100 |
commit | 397326ddfa5fd14b8423a152dd9ec5a471924a41 (patch) | |
tree | 8f719ceba221fd7980b7354bb1928ae734c84fc9 /OpenSim/Data/DBGuids.cs | |
parent | Revert "Looks like the new files were never added to prebuild.xml" (diff) | |
parent | Some more corrections after MySQL connector update (diff) | |
download | opensim-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.cs | 44 |
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenMetaverse; | ||
5 | |||
6 | namespace 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 | } | ||