diff options
author | AlexRa | 2010-05-18 14:19:19 +0300 |
---|---|---|
committer | AlexRa | 2010-05-19 01:32:50 +0300 |
commit | a27d49b1887700d78498ee0a369c2b3d93d2642c (patch) | |
tree | e5780142c8a7e939914a5e0f1535c438f2023ce1 /OpenSim | |
parent | Looks like the new files were never added to prebuild.xml (diff) | |
download | opensim-SC_OLD-a27d49b1887700d78498ee0a369c2b3d93d2642c.zip opensim-SC_OLD-a27d49b1887700d78498ee0a369c2b3d93d2642c.tar.gz opensim-SC_OLD-a27d49b1887700d78498ee0a369c2b3d93d2642c.tar.bz2 opensim-SC_OLD-a27d49b1887700d78498ee0a369c2b3d93d2642c.tar.xz |
Added DBGuids.cs (static func DBGuid.FromDB()
This DBMS-independent function to be used converting UUIDs
from whatever format used in the DB (string/binary/Guid).
This is mostly needed for MySQL, as in MSSQL they are always
UNIQUEIDENTIFIERs and in SQLite always strings (but would look
better if we use it there anyway).
Diffstat (limited to '')
-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 | } | ||