From 2284c8509f29b8766794f6482839cd9bc5e9f300 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Thu, 7 May 2009 14:20:32 +0000
Subject: * Consistently used dashed uuid format for mysql region data, as is
 done for all other tables * This revision contains a mysql data migration. 
 Please backup your mysql region database as a precaution before using this
 code. * I also advise that you do a runprebuild[.sh|.bat] and a clean build
 ("nant clean build" if you're using the command line). * This change is
 needed for future id schemes

---
 OpenSim/Data/MySQL/MySQLRegionData.cs            | 55 ++++++++---------
 OpenSim/Data/MySQL/Resources/028_RegionStore.sql | 79 ++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 29 deletions(-)
 create mode 100644 OpenSim/Data/MySQL/Resources/028_RegionStore.sql

diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs
index e39b185..b13813f 100644
--- a/OpenSim/Data/MySQL/MySQLRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLRegionData.cs
@@ -282,7 +282,7 @@ namespace OpenSim.Data.MySQL
                 cmd.CommandText = "select UUID from prims where "+
                         "SceneGroupID= ?UUID";
 
-                cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(obj));
+                cmd.Parameters.AddWithValue("UUID", obj.ToString());
 
                 List<UUID> uuids = new List<UUID>();
 
@@ -365,7 +365,7 @@ namespace OpenSim.Data.MySQL
 
                 for (int i = 0; i < uuids.Count; i++)
                 {
-                    cmd.Parameters.AddWithValue("UUID" + i, Util.ToRawUuidString(uuids[i]));
+                    cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
                 }
 
                 ExecuteNonQuery(cmd);
@@ -426,8 +426,7 @@ namespace OpenSim.Data.MySQL
                         "where RegionUUID = ?RegionUUID " +
                         "order by SceneGroupID asc, sort asc, LinkNumber asc";
                 
-                cmd.Parameters.AddWithValue("RegionUUID",
-                        Util.ToRawUuidString(regionUUID));
+                cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
 
                 IDataReader reader = ExecuteReader(cmd);
 
@@ -549,8 +548,7 @@ namespace OpenSim.Data.MySQL
 
                 cmd.CommandText = "delete from terrain where " +
                         "RegionUUID = ?RegionUUID";
-                cmd.Parameters.AddWithValue("RegionUUID",
-                        Util.ToRawUuidString(regionID));
+                cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
 
                 ExecuteNonQuery(cmd);
                 
@@ -576,7 +574,7 @@ namespace OpenSim.Data.MySQL
                 cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
                         "from terrain where RegionUUID = ?RegionUUID "+
                         "order by Revision desc limit 1";
-                cmd.Parameters.AddWithValue("RegionUUID", Util.ToRawUuidString(regionID));
+                cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
 
                 IDataReader reader = ExecuteReader(cmd);
 
@@ -621,7 +619,7 @@ namespace OpenSim.Data.MySQL
 
                 cmd.CommandText = "delete from land where UUID = ?UUID";
 
-                cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(globalID));
+                cmd.Parameters.AddWithValue("UUID", globalID.ToString());
 
                 ExecuteNonQuery(cmd);
                 cmd.Dispose();
@@ -775,8 +773,7 @@ namespace OpenSim.Data.MySQL
                 cmd.CommandText = "select * from land where " +
                         "RegionUUID = ?RegionUUID";
 
-                cmd.Parameters.AddWithValue("RegionUUID",
-                        Util.ToRawUuidString(regionUUID));
+                cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
 
                 IDataReader reader = ExecuteReader(cmd);
 
@@ -800,8 +797,7 @@ namespace OpenSim.Data.MySQL
                     cmd.CommandText = "select * from landaccesslist " +
                             "where LandUUID = ?LandUUID";
 
-                    cmd.Parameters.AddWithValue("LandUUID",
-                            Util.ToRawUuidString(land.GlobalID));
+                    cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
 
                     reader = ExecuteReader(cmd);
 
@@ -1157,11 +1153,11 @@ namespace OpenSim.Data.MySQL
         /// <param name="regionUUID"></param>
         private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
         {
-            cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(prim.UUID));
-            cmd.Parameters.AddWithValue("RegionUUID", Util.ToRawUuidString(regionUUID));
+            cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
+            cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
             cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
             cmd.Parameters.AddWithValue("Name", prim.Name);
-            cmd.Parameters.AddWithValue("SceneGroupID", Util.ToRawUuidString(sceneGroupID));
+            cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
                 // the UUID of the root part for this SceneObjectGroup
             // various text fields
             cmd.Parameters.AddWithValue("Text", prim.Text);
@@ -1174,10 +1170,10 @@ namespace OpenSim.Data.MySQL
             cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
             // permissions
             cmd.Parameters.AddWithValue("ObjectFlags", prim.ObjectFlags);
-            cmd.Parameters.AddWithValue("CreatorID", Util.ToRawUuidString(prim.CreatorID));
-            cmd.Parameters.AddWithValue("OwnerID", Util.ToRawUuidString(prim.OwnerID));
-            cmd.Parameters.AddWithValue("GroupID", Util.ToRawUuidString(prim.GroupID));
-            cmd.Parameters.AddWithValue("LastOwnerID", Util.ToRawUuidString(prim.LastOwnerID));
+            cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
+            cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
+            cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
+            cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
             cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
             cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
             cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
@@ -1361,8 +1357,8 @@ namespace OpenSim.Data.MySQL
         /// <param name="regionUUID"></param>
         private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
         {
-            cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(land.GlobalID));
-            cmd.Parameters.AddWithValue("RegionUUID", Util.ToRawUuidString(regionUUID));
+            cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
+            cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
             cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
 
             // Bitmap is a byte[512]
@@ -1370,25 +1366,25 @@ namespace OpenSim.Data.MySQL
 
             cmd.Parameters.AddWithValue("Name", land.Name);
             cmd.Parameters.AddWithValue("Description", land.Description);
-            cmd.Parameters.AddWithValue("OwnerUUID", Util.ToRawUuidString(land.OwnerID));
+            cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
             cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
             cmd.Parameters.AddWithValue("Area", land.Area);
             cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
             cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
             cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
             cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
-            cmd.Parameters.AddWithValue("GroupUUID", Util.ToRawUuidString(land.GroupID));
+            cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
             cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
             cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
             cmd.Parameters.AddWithValue("LandFlags", land.Flags);
             cmd.Parameters.AddWithValue("LandingType", land.LandingType);
             cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
-            cmd.Parameters.AddWithValue("MediaTextureUUID", Util.ToRawUuidString(land.MediaID));
+            cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
             cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
             cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
             cmd.Parameters.AddWithValue("PassHours", land.PassHours);
             cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
-            cmd.Parameters.AddWithValue("SnapshotUUID", Util.ToRawUuidString(land.SnapshotID));
+            cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
             cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
             cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
             cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
@@ -1408,8 +1404,8 @@ namespace OpenSim.Data.MySQL
         /// <param name="parcelID"></param>
         private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
         {
-            cmd.Parameters.AddWithValue("LandUUID", Util.ToRawUuidString(parcelID));
-            cmd.Parameters.AddWithValue("AccessUUID", Util.ToRawUuidString(entry.AgentID));
+            cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
+            cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
             cmd.Parameters.AddWithValue("Flags", entry.Flags);
         }
 
@@ -1465,7 +1461,7 @@ namespace OpenSim.Data.MySQL
         private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
         {
             PrimitiveBaseShape s = prim.Shape;
-            cmd.Parameters.AddWithValue("UUID", Util.ToRawUuidString(prim.UUID));
+            cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
             // shape is an enum
             cmd.Parameters.AddWithValue("Shape", 0);
             // vectors
@@ -1533,8 +1529,9 @@ namespace OpenSim.Data.MySQL
 
                     ExecuteNonQuery(cmd);
                 }
+                
                 cmd.Dispose();
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/OpenSim/Data/MySQL/Resources/028_RegionStore.sql b/OpenSim/Data/MySQL/Resources/028_RegionStore.sql
new file mode 100644
index 0000000..078394f
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/028_RegionStore.sql
@@ -0,0 +1,79 @@
+BEGIN;
+
+update terrain
+  set RegionUUID = concat(substr(RegionUUID, 1, 8), "-", substr(RegionUUID, 9, 4), "-", substr(RegionUUID, 13, 4), "-", substr(RegionUUID, 17, 4), "-", substr(RegionUUID, 21, 12))
+  where RegionUUID not like '%-%';
+  
+
+update landaccesslist
+  set LandUUID = concat(substr(LandUUID, 1, 8), "-", substr(LandUUID, 9, 4), "-", substr(LandUUID, 13, 4), "-", substr(LandUUID, 17, 4), "-", substr(LandUUID, 21, 12))
+  where LandUUID not like '%-%';  
+
+update landaccesslist
+  set AccessUUID = concat(substr(AccessUUID, 1, 8), "-", substr(AccessUUID, 9, 4), "-", substr(AccessUUID, 13, 4), "-", substr(AccessUUID, 17, 4), "-", substr(AccessUUID, 21, 12))
+  where AccessUUID not like '%-%';  
+  
+
+update prims
+  set UUID = concat(substr(UUID, 1, 8), "-", substr(UUID, 9, 4), "-", substr(UUID, 13, 4), "-", substr(UUID, 17, 4), "-", substr(UUID, 21, 12))
+  where UUID not like '%-%';
+
+update prims
+  set RegionUUID = concat(substr(RegionUUID, 1, 8), "-", substr(RegionUUID, 9, 4), "-", substr(RegionUUID, 13, 4), "-", substr(RegionUUID, 17, 4), "-", substr(RegionUUID, 21, 12))
+  where RegionUUID not like '%-%';  
+
+update prims
+  set SceneGroupID = concat(substr(SceneGroupID, 1, 8), "-", substr(SceneGroupID, 9, 4), "-", substr(SceneGroupID, 13, 4), "-", substr(SceneGroupID, 17, 4), "-", substr(SceneGroupID, 21, 12))
+  where SceneGroupID not like '%-%';  
+
+update prims
+  set CreatorID = concat(substr(CreatorID, 1, 8), "-", substr(CreatorID, 9, 4), "-", substr(CreatorID, 13, 4), "-", substr(CreatorID, 17, 4), "-", substr(CreatorID, 21, 12))
+  where CreatorID not like '%-%';  
+
+update prims
+  set OwnerID = concat(substr(OwnerID, 1, 8), "-", substr(OwnerID, 9, 4), "-", substr(OwnerID, 13, 4), "-", substr(OwnerID, 17, 4), "-", substr(OwnerID, 21, 12))
+  where OwnerID not like '%-%';  
+
+update prims
+  set GroupID = concat(substr(GroupID, 1, 8), "-", substr(GroupID, 9, 4), "-", substr(GroupID, 13, 4), "-", substr(GroupID, 17, 4), "-", substr(GroupID, 21, 12))
+  where GroupID not like '%-%';  
+
+update prims
+  set LastOwnerID = concat(substr(LastOwnerID, 1, 8), "-", substr(LastOwnerID, 9, 4), "-", substr(LastOwnerID, 13, 4), "-", substr(LastOwnerID, 17, 4), "-", substr(LastOwnerID, 21, 12))
+  where LastOwnerID not like '%-%';  
+
+
+update primshapes
+  set UUID = concat(substr(UUID, 1, 8), "-", substr(UUID, 9, 4), "-", substr(UUID, 13, 4), "-", substr(UUID, 17, 4), "-", substr(UUID, 21, 12))
+  where UUID not like '%-%';    
+
+
+update land
+  set UUID = concat(substr(UUID, 1, 8), "-", substr(UUID, 9, 4), "-", substr(UUID, 13, 4), "-", substr(UUID, 17, 4), "-", substr(UUID, 21, 12))
+  where UUID not like '%-%';      
+  
+update land
+  set RegionUUID = concat(substr(RegionUUID, 1, 8), "-", substr(RegionUUID, 9, 4), "-", substr(RegionUUID, 13, 4), "-", substr(RegionUUID, 17, 4), "-", substr(RegionUUID, 21, 12))
+  where RegionUUID not like '%-%';      
+
+update land
+  set OwnerUUID = concat(substr(OwnerUUID, 1, 8), "-", substr(OwnerUUID, 9, 4), "-", substr(OwnerUUID, 13, 4), "-", substr(OwnerUUID, 17, 4), "-", substr(OwnerUUID, 21, 12))
+  where OwnerUUID not like '%-%';      
+
+update land
+  set GroupUUID = concat(substr(GroupUUID, 1, 8), "-", substr(GroupUUID, 9, 4), "-", substr(GroupUUID, 13, 4), "-", substr(GroupUUID, 17, 4), "-", substr(GroupUUID, 21, 12))
+  where GroupUUID not like '%-%';      
+
+update land
+  set MediaTextureUUID = concat(substr(MediaTextureUUID, 1, 8), "-", substr(MediaTextureUUID, 9, 4), "-", substr(MediaTextureUUID, 13, 4), "-", substr(MediaTextureUUID, 17, 4), "-", substr(MediaTextureUUID, 21, 12))
+  where MediaTextureUUID not like '%-%';      
+
+update land
+  set SnapshotUUID = concat(substr(SnapshotUUID, 1, 8), "-", substr(SnapshotUUID, 9, 4), "-", substr(SnapshotUUID, 13, 4), "-", substr(SnapshotUUID, 17, 4), "-", substr(SnapshotUUID, 21, 12))
+  where SnapshotUUID not like '%-%';      
+
+update land
+  set AuthbuyerID = concat(substr(AuthbuyerID, 1, 8), "-", substr(AuthbuyerID, 9, 4), "-", substr(AuthbuyerID, 13, 4), "-", substr(AuthbuyerID, 17, 4), "-", substr(AuthbuyerID, 21, 12))
+  where AuthbuyerID not like '%-%';      
+  
+COMMIT;
\ No newline at end of file
-- 
cgit v1.1