aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite
diff options
context:
space:
mode:
authorKevin Houlihan2011-09-12 23:08:16 +0100
committerJustin Clark-Casey (justincc)2011-09-16 18:50:25 +0100
commit1458fab82c4dab9901d81419e6b515f47ea7320f (patch)
tree674a9ff24d27da1f5d47d77def4c92206983f376 /OpenSim/Data/SQLite
parentPass any region scope through to the CreateUser() method (diff)
downloadopensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.zip
opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.gz
opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.bz2
opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.xz
Reattaching a region was failing if the estate name had not changed (issue 5035).
Using the RemoteAdmin API to close then recreate a region would fail if the estate name had not changed. If the estate name /was/ changed then the existing estate would be renamed rather than a new one being created. The problem really arose from a lack of distinction in the data storage layer between creating new estates and loading existing ones.
Diffstat (limited to 'OpenSim/Data/SQLite')
-rw-r--r--OpenSim/Data/SQLite/SQLiteEstateData.cs126
1 files changed, 78 insertions, 48 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs
index 65719a6..8db9262 100644
--- a/OpenSim/Data/SQLite/SQLiteEstateData.cs
+++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs
@@ -151,67 +151,77 @@ namespace OpenSim.Data.SQLite
151 } 151 }
152 else if (create) 152 else if (create)
153 { 153 {
154 r.Close(); 154 DoCreate(es);
155 LinkRegion(regionID, (int)es.EstateID);
156 }
155 157
156 List<string> names = new List<string>(FieldList); 158 LoadBanList(es);
157 159
158 names.Remove("EstateID"); 160 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
161 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
162 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
163 return es;
164 }
159 165
160 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; 166 public EstateSettings CreateNewEstate()
167 {
168 EstateSettings es = new EstateSettings();
169 es.OnSave += StoreEstateSettings;
161 170
162 cmd.CommandText = sql; 171 DoCreate(es);
163 cmd.Parameters.Clear();
164 172
165 foreach (string name in FieldList) 173 LoadBanList(es);
166 {
167 if (m_FieldMap[name].GetValue(es) is bool)
168 {
169 if ((bool)m_FieldMap[name].GetValue(es))
170 cmd.Parameters.AddWithValue(":"+name, "1");
171 else
172 cmd.Parameters.AddWithValue(":"+name, "0");
173 }
174 else
175 {
176 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
177 }
178 }
179 174
180 cmd.ExecuteNonQuery(); 175 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
176 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
177 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
181 178
182 cmd.CommandText = "select LAST_INSERT_ROWID() as id"; 179 return es;
183 cmd.Parameters.Clear(); 180 }
184 181
185 r = cmd.ExecuteReader(); 182 private void DoCreate(EstateSettings es)
183 {
184 List<string> names = new List<string>(FieldList);
186 185
187 r.Read(); 186 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
187 IDataReader r = null;
188 188
189 es.EstateID = Convert.ToUInt32(r["id"]); 189 names.Remove("EstateID");
190 190
191 r.Close(); 191 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
192 192
193 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; 193 cmd.CommandText = sql;
194 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); 194 cmd.Parameters.Clear();
195 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
196 195
197 // This will throw on dupe key 196 foreach (string name in FieldList)
198 try 197 {
198 if (m_FieldMap[name].GetValue(es) is bool)
199 { 199 {
200 cmd.ExecuteNonQuery(); 200 if ((bool)m_FieldMap[name].GetValue(es))
201 cmd.Parameters.AddWithValue(":"+name, "1");
202 else
203 cmd.Parameters.AddWithValue(":"+name, "0");
201 } 204 }
202 catch (Exception) 205 else
203 { 206 {
207 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
204 } 208 }
205
206 es.Save();
207 } 209 }
208 210
209 LoadBanList(es); 211 cmd.ExecuteNonQuery();
210 212
211 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); 213 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
212 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); 214 cmd.Parameters.Clear();
213 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); 215
214 return es; 216 r = cmd.ExecuteReader();
217
218 r.Read();
219
220 es.EstateID = Convert.ToUInt32(r["id"]);
221
222 r.Close();
223
224 es.Save();
215 } 225 }
216 226
217 public void StoreEstateSettings(EstateSettings es) 227 public void StoreEstateSettings(EstateSettings es)
@@ -440,16 +450,36 @@ namespace OpenSim.Data.SQLite
440 450
441 public bool LinkRegion(UUID regionID, int estateID) 451 public bool LinkRegion(UUID regionID, int estateID)
442 { 452 {
443 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 453 SqliteTransaction transaction = m_connection.BeginTransaction();
444 454
445 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; 455 // Delete any existing estate mapping for this region.
446 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); 456 using(SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
447 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); 457 {
458 cmd.CommandText = "delete from estate_map where RegionID = :RegionID";
459 cmd.Transaction = transaction;
460 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
448 461
449 if (cmd.ExecuteNonQuery() == 0) 462 cmd.ExecuteNonQuery();
450 return false; 463 }
451 464
452 return true; 465 using(SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
466 {
467 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
468 cmd.Transaction = transaction;
469 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
470 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString());
471
472 if (cmd.ExecuteNonQuery() == 0)
473 {
474 transaction.Rollback();
475 return false;
476 }
477 else
478 {
479 transaction.Commit();
480 return true;
481 }
482 }
453 } 483 }
454 484
455 public List<UUID> GetRegions(int estateID) 485 public List<UUID> GetRegions(int estateID)