From a27d49b1887700d78498ee0a369c2b3d93d2642c Mon Sep 17 00:00:00 2001
From: AlexRa
Date: Tue, 18 May 2010 14:19:19 +0300
Subject: 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).
---
OpenSim/Data/DBGuids.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 OpenSim/Data/DBGuids.cs
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 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenMetaverse;
+
+namespace OpenSim.Data
+{
+
+ public static class DBGuid
+ {
+ /// This function converts a value returned from the database in one of the
+ /// supported formats into a UUID. This function is not actually DBMS-specific right
+ /// now
+ ///
+ ///
+ ///
+ ///
+ public static UUID FromDB(object id)
+ {
+ if( (id == null) || (id == DBNull.Value))
+ return UUID.Zero;
+
+ if (id.GetType() == typeof(Guid))
+ return new UUID((Guid)id);
+
+ if (id.GetType() == typeof(byte[]))
+ {
+ if (((byte[])id).Length == 0)
+ return UUID.Zero;
+ else if (((byte[])id).Length == 36)
+ return new UUID((byte[])id, 0);
+ }
+ else if (id.GetType() == typeof(string))
+ {
+ if (((string)id).Length == 0)
+ return UUID.Zero;
+ else if (((string)id).Length == 36)
+ return new UUID((string)id);
+ }
+
+ throw new Exception("Failed to convert db value to UUID: " + id.ToString());
+ }
+ }
+}
--
cgit v1.1