From cbf9fcfac591bd8c8fcbccaa562c7a5fa05c4d9c Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Fri, 11 Apr 2008 09:56:22 +0000
Subject: * Discerned between AddProfile and UpdateProfile in region
registration
:: Believe it or not, but INSERT/UPDATE is actually a better pattern than REPLACE, since, with INSERT/UPDATE you can catch erroneous UPDATES to non-INSERTed items as well as catch erroneous re-INSERTS. in 95% of the cases, you SHOULD have a clear INSERT context, and a clear and separate UPDATE context. If you think your case falls within the 5%, maybe you should re-evaluate your code. ::
---
OpenSim/Data/MSSQL/MSSQLGridData.cs | 81 +++++++++++++++++++++++++++++++++----
1 file changed, 73 insertions(+), 8 deletions(-)
(limited to 'OpenSim/Data/MSSQL')
diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs
index 03af53c..5617900 100644
--- a/OpenSim/Data/MSSQL/MSSQLGridData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs
@@ -228,19 +228,19 @@ namespace OpenSim.Data.MSSQL
/// A dataresponse enum indicating success
override public DataResponse AddProfile(RegionProfileData profile)
{
- try
+ if (insertRegionRow(profile))
{
- if (GetProfileByLLUUID(profile.UUID) != null)
- {
- return DataResponse.RESPONSE_OK;
- }
+ return DataResponse.RESPONSE_OK;
}
- catch (Exception)
+ else
{
- System.Console.WriteLine("No regions found. Create new one.");
+ return DataResponse.RESPONSE_ERROR;
}
+ }
- if (insertRegionRow(profile))
+ public override DataResponse UpdateProfile(RegionProfileData profile)
+ {
+ if (updateRegionRow(profile))
{
return DataResponse.RESPONSE_OK;
}
@@ -250,6 +250,71 @@ namespace OpenSim.Data.MSSQL
}
}
+ public bool updateRegionRow(RegionProfileData profile)
+ {
+ //Insert new region
+ string sql =
+ "UPDATE " + m_regionsTableName + @" SET
+ [regionHandle]=@regionHandle, [regionName]=@regionName,
+ [regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
+ [regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
+ [locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
+ [westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
+ [northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
+ [regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
+ [regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
+ [regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
+ [serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid
+ where [uuid]=@uuid";
+
+ Dictionary parameters = new Dictionary();
+
+ parameters["regionHandle"] = profile.regionHandle.ToString();
+ parameters["regionName"] = profile.regionName;
+ parameters["uuid"] = profile.UUID.ToString();
+ parameters["regionRecvKey"] = profile.regionRecvKey;
+ parameters["regionSecret"] = profile.regionSecret;
+ parameters["regionSendKey"] = profile.regionSendKey;
+ parameters["regionDataURI"] = profile.regionDataURI;
+ parameters["serverIP"] = profile.serverIP;
+ parameters["serverPort"] = profile.serverPort.ToString();
+ parameters["serverURI"] = profile.serverURI;
+ parameters["locX"] = profile.regionLocX.ToString();
+ parameters["locY"] = profile.regionLocY.ToString();
+ parameters["locZ"] = profile.regionLocZ.ToString();
+ parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
+ parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
+ parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
+ parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
+ parameters["regionAssetURI"] = profile.regionAssetURI;
+ parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
+ parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
+ parameters["regionUserURI"] = profile.regionUserURI;
+ parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
+ parameters["regionUserSendKey"] = profile.regionUserSendKey;
+ parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
+ parameters["serverHttpPort"] = profile.httpPort.ToString();
+ parameters["serverRemotingPort"] = profile.remotingPort.ToString();
+ parameters["owner_uuid"] = profile.owner_uuid.ToString();
+
+ bool returnval = false;
+
+ try
+ {
+ IDbCommand result = database.Query(sql, parameters);
+
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
+
+ result.Dispose();
+ }
+ catch (Exception e)
+ {
+ m_log.Error("MSSQLManager : " + e.ToString());
+ }
+
+ return returnval;
+ }
///
/// Creates a new region in the database
///
--
cgit v1.1