Massive bugfix in MSSQLEstateData (now works!)

soprefactor
AlexRa 2010-05-18 01:44:51 +03:00
parent 3e1f2ddb8e
commit d95f232629
1 changed files with 43 additions and 51 deletions

View File

@ -101,22 +101,30 @@ namespace OpenSim.Data.MSSQL
{ {
foreach (string name in FieldList) foreach (string name in FieldList)
{ {
if (_FieldMap[name].GetValue(es) is bool) FieldInfo f = _FieldMap[name];
object v = reader[name];
if (f.FieldType == typeof(bool) )
{ {
int v = Convert.ToInt32(reader[name]); f.SetValue(es, Convert.ToInt32(v) != 0);
if (v != 0)
_FieldMap[name].SetValue(es, true);
else
_FieldMap[name].SetValue(es, false);
} }
else if (_FieldMap[name].GetValue(es) is UUID) else if (f.FieldType == typeof(UUID) )
{ {
_FieldMap[name].SetValue(es, new UUID((Guid)reader[name])); // uuid); f.SetValue(es, new UUID((Guid)v)); // uuid);
}
else if (f.FieldType == typeof(string))
{
f.SetValue(es, v.ToString());
}
else if (f.FieldType == typeof(UInt32))
{
f.SetValue(es, Convert.ToUInt32(v));
}
else if (f.FieldType == typeof(Single))
{
f.SetValue(es, Convert.ToSingle(v));
} }
else else
{ f.SetValue(es, v);
es.EstateID = Convert.ToUInt32(reader["EstateID"].ToString());
}
} }
} }
else else
@ -288,61 +296,45 @@ namespace OpenSim.Data.MSSQL
private void SaveBanList(EstateSettings es) private void SaveBanList(EstateSettings es)
{ {
//Delete first //Delete first
string sql = "delete from estateban where EstateID = @EstateID";
using (SqlConnection conn = new SqlConnection(m_connectionString)) using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{ {
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
conn.Open(); conn.Open();
cmd.ExecuteNonQuery(); using (SqlCommand cmd = conn.CreateCommand())
}
//Insert after
sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
foreach (EstateBan b in es.EstateBans)
{ {
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); cmd.CommandText = "delete from estateban where EstateID = @EstateID";
cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID)); cmd.Parameters.AddWithValue("@EstateID", (int)es.EstateID);
conn.Open();
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//Insert after
cmd.CommandText = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
cmd.Parameters.AddWithValue("@bannedUUID", Guid.Empty);
foreach (EstateBan b in es.EstateBans)
{
cmd.Parameters["@bannedUUID"].Value = b.BannedUserID.Guid;
cmd.ExecuteNonQuery();
}
} }
} }
} }
private void SaveUUIDList(uint estateID, string table, UUID[] data) private void SaveUUIDList(uint estateID, string table, UUID[] data)
{ {
//Delete first
string sql = string.Format("delete from {0} where EstateID = @EstateID", table);
using (SqlConnection conn = new SqlConnection(m_connectionString)) using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{ {
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); conn.Open();
cmd.ExecuteNonQuery(); using (SqlCommand cmd = conn.CreateCommand())
}
sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
bool createParamOnce = true;
foreach (UUID uuid in data)
{ {
if (createParamOnce) cmd.Parameters.AddWithValue("@EstateID", (int)estateID);
{ cmd.CommandText = string.Format("delete from {0} where EstateID = @EstateID", table);
cmd.Parameters.Add(_Database.CreateParameter("@uuid", uuid));
createParamOnce = false;
}
else
cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works
conn.Open();
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.CommandText = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
cmd.Parameters.AddWithValue("@uuid", Guid.Empty);
foreach (UUID uuid in data)
{
cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works
cmd.ExecuteNonQuery();
}
} }
} }
} }