Add the Migration for the regions table

remotes/origin/0.6.7-post-fixes
Melanie 2009-09-27 21:17:23 +01:00
parent eb892e0545
commit 8e091f5903
3 changed files with 22 additions and 8 deletions

View File

@ -39,6 +39,8 @@ namespace OpenSim.Data
public string RegionName;
public int posX;
public int posY;
public int sizeX;
public int sizeY;
public Dictionary<string, object> Data;
}

View File

@ -138,6 +138,8 @@ namespace OpenSim.Data.MySQL
ret.RegionName = result["regionName"].ToString();
ret.posX = Convert.ToInt32(result["locX"]);
ret.posY = Convert.ToInt32(result["locY"]);
ret.sizeX = Convert.ToInt32(result["sizeX"]);
ret.sizeY = Convert.ToInt32(result["sizeY"]);
if (m_ColumnNames == null)
{
@ -188,21 +190,21 @@ namespace OpenSim.Data.MySQL
data.Data.Remove("posX");
if (data.Data.ContainsKey("posY"))
data.Data.Remove("posY");
if (data.Data.ContainsKey("sizeX"))
data.Data.Remove("sizeX");
if (data.Data.ContainsKey("sizeY"))
data.Data.Remove("sizeY");
string[] fields = new List<string>(data.Data.Keys).ToArray();
MySqlCommand cmd = new MySqlCommand();
string update = "update `"+m_Realm+"` set ";
bool first = true;
string update = "update `"+m_Realm+"` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
foreach (string field in fields)
{
if (!first)
update += ", ";
update += ", ";
update += "`" + field + "` = ?"+field;
first = false;
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
}
@ -214,12 +216,16 @@ namespace OpenSim.Data.MySQL
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?regionID", data.RegionID.ToString());
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
cmd.Parameters.AddWithValue("?posX", data.posX.ToString());
cmd.Parameters.AddWithValue("?posY", data.posY.ToString());
cmd.Parameters.AddWithValue("?sizeX", data.sizeX.ToString());
cmd.Parameters.AddWithValue("?sizeY", data.sizeY.ToString());
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `" +
string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `locX`, `locY`, `sizeX`, `sizeY`, `" +
String.Join("`, `", fields) +
"`) values ( ?regionID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
"`) values ( ?regionID, ?scopeID, ?posX, ?posY, ?sizeX, ?sizeY, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;

View File

@ -0,0 +1,6 @@
BEGIN;
ALTER TABLE regions add column sizeX integer not null default 0;
ALTER TABLE regions add column sizeY integer not null default 0;
COMMIT;