diff options
author | Melanie | 2010-03-23 02:05:56 +0000 |
---|---|---|
committer | Melanie | 2010-03-23 02:05:56 +0000 |
commit | dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912 (patch) | |
tree | ef72d57634075b044c65428f31c8f04c4c53a7bb /OpenSim/Data/MySQL | |
parent | Somehow the starting estate number in MySQL was lost. This adds a migration (diff) | |
download | opensim-SC_OLD-dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912.zip opensim-SC_OLD-dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912.tar.gz opensim-SC_OLD-dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912.tar.bz2 opensim-SC_OLD-dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912.tar.xz |
First stage of the new interactive region creation. This will allow creation
of a region and joining it to an existing estate or creating a new estate,
as well as creating an estate owner if in standalone, and assigning estate
owners. In Grid mode, existing users must be used. MySQL ONLY!!!! so far, as
I can't develop or test for either SQLite or MSSQL.
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLEstateData.cs | 175 |
1 files changed, 130 insertions, 45 deletions
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs index e94dcda..7fe1fcc 100644 --- a/OpenSim/Data/MySQL/MySQLEstateData.cs +++ b/OpenSim/Data/MySQL/MySQLEstateData.cs | |||
@@ -123,50 +123,57 @@ namespace OpenSim.Data.MySQL | |||
123 | 123 | ||
124 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) | 124 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) |
125 | { | 125 | { |
126 | EstateSettings es = new EstateSettings(); | ||
127 | es.OnSave += StoreEstateSettings; | ||
128 | |||
129 | string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + | 126 | string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + |
130 | " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID"; | 127 | " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID"; |
131 | 128 | ||
129 | using (MySqlCommand cmd = new MySqlCommand()) | ||
130 | { | ||
131 | cmd.CommandText = sql; | ||
132 | cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); | ||
133 | |||
134 | return DoLoad(cmd, regionID, create); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create) | ||
139 | { | ||
140 | EstateSettings es = new EstateSettings(); | ||
141 | es.OnSave += StoreEstateSettings; | ||
142 | |||
132 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 143 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
133 | { | 144 | { |
134 | dbcon.Open(); | 145 | dbcon.Open(); |
135 | 146 | ||
147 | cmd.Connection = dbcon; | ||
148 | |||
136 | bool found = false; | 149 | bool found = false; |
137 | 150 | ||
138 | using (MySqlCommand cmd = dbcon.CreateCommand()) | 151 | using (IDataReader r = cmd.ExecuteReader()) |
139 | { | 152 | { |
140 | cmd.CommandText = sql; | 153 | if (r.Read()) |
141 | cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); | ||
142 | |||
143 | using (IDataReader r = cmd.ExecuteReader()) | ||
144 | { | 154 | { |
145 | if (r.Read()) | 155 | found = true; |
146 | { | ||
147 | found = true; | ||
148 | 156 | ||
149 | foreach (string name in FieldList) | 157 | foreach (string name in FieldList) |
158 | { | ||
159 | if (m_FieldMap[name].GetValue(es) is bool) | ||
150 | { | 160 | { |
151 | if (m_FieldMap[name].GetValue(es) is bool) | 161 | int v = Convert.ToInt32(r[name]); |
152 | { | 162 | if (v != 0) |
153 | int v = Convert.ToInt32(r[name]); | 163 | m_FieldMap[name].SetValue(es, true); |
154 | if (v != 0) | ||
155 | m_FieldMap[name].SetValue(es, true); | ||
156 | else | ||
157 | m_FieldMap[name].SetValue(es, false); | ||
158 | } | ||
159 | else if (m_FieldMap[name].GetValue(es) is UUID) | ||
160 | { | ||
161 | UUID uuid = UUID.Zero; | ||
162 | |||
163 | UUID.TryParse(r[name].ToString(), out uuid); | ||
164 | m_FieldMap[name].SetValue(es, uuid); | ||
165 | } | ||
166 | else | 164 | else |
167 | { | 165 | m_FieldMap[name].SetValue(es, false); |
168 | m_FieldMap[name].SetValue(es, r[name]); | 166 | } |
169 | } | 167 | else if (m_FieldMap[name].GetValue(es) is UUID) |
168 | { | ||
169 | UUID uuid = UUID.Zero; | ||
170 | |||
171 | UUID.TryParse(r[name].ToString(), out uuid); | ||
172 | m_FieldMap[name].SetValue(es, uuid); | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | m_FieldMap[name].SetValue(es, r[name]); | ||
170 | } | 177 | } |
171 | } | 178 | } |
172 | } | 179 | } |
@@ -179,45 +186,45 @@ namespace OpenSim.Data.MySQL | |||
179 | 186 | ||
180 | names.Remove("EstateID"); | 187 | names.Remove("EstateID"); |
181 | 188 | ||
182 | sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; | 189 | string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; |
183 | 190 | ||
184 | using (MySqlCommand cmd = dbcon.CreateCommand()) | 191 | using (MySqlCommand cmd2 = dbcon.CreateCommand()) |
185 | { | 192 | { |
186 | cmd.CommandText = sql; | 193 | cmd2.CommandText = sql; |
187 | cmd.Parameters.Clear(); | 194 | cmd2.Parameters.Clear(); |
188 | 195 | ||
189 | foreach (string name in FieldList) | 196 | foreach (string name in FieldList) |
190 | { | 197 | { |
191 | if (m_FieldMap[name].GetValue(es) is bool) | 198 | if (m_FieldMap[name].GetValue(es) is bool) |
192 | { | 199 | { |
193 | if ((bool)m_FieldMap[name].GetValue(es)) | 200 | if ((bool)m_FieldMap[name].GetValue(es)) |
194 | cmd.Parameters.AddWithValue("?" + name, "1"); | 201 | cmd2.Parameters.AddWithValue("?" + name, "1"); |
195 | else | 202 | else |
196 | cmd.Parameters.AddWithValue("?" + name, "0"); | 203 | cmd2.Parameters.AddWithValue("?" + name, "0"); |
197 | } | 204 | } |
198 | else | 205 | else |
199 | { | 206 | { |
200 | cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); | 207 | cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); |
201 | } | 208 | } |
202 | } | 209 | } |
203 | 210 | ||
204 | cmd.ExecuteNonQuery(); | 211 | cmd2.ExecuteNonQuery(); |
205 | 212 | ||
206 | cmd.CommandText = "select LAST_INSERT_ID() as id"; | 213 | cmd2.CommandText = "select LAST_INSERT_ID() as id"; |
207 | cmd.Parameters.Clear(); | 214 | cmd2.Parameters.Clear(); |
208 | 215 | ||
209 | using (IDataReader r = cmd.ExecuteReader()) | 216 | using (IDataReader r = cmd2.ExecuteReader()) |
210 | { | 217 | { |
211 | r.Read(); | 218 | r.Read(); |
212 | es.EstateID = Convert.ToUInt32(r["id"]); | 219 | es.EstateID = Convert.ToUInt32(r["id"]); |
213 | } | 220 | } |
214 | 221 | ||
215 | cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; | 222 | cmd2.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; |
216 | cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); | 223 | cmd2.Parameters.AddWithValue("?RegionID", regionID.ToString()); |
217 | cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); | 224 | cmd2.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); |
218 | 225 | ||
219 | // This will throw on dupe key | 226 | // This will throw on dupe key |
220 | try { cmd.ExecuteNonQuery(); } | 227 | try { cmd2.ExecuteNonQuery(); } |
221 | catch (Exception) { } | 228 | catch (Exception) { } |
222 | 229 | ||
223 | es.Save(); | 230 | es.Save(); |
@@ -390,5 +397,83 @@ namespace OpenSim.Data.MySQL | |||
390 | 397 | ||
391 | return uuids.ToArray(); | 398 | return uuids.ToArray(); |
392 | } | 399 | } |
400 | |||
401 | public EstateSettings LoadEstateSettings(int estateID) | ||
402 | { | ||
403 | using (MySqlCommand cmd = new MySqlCommand()) | ||
404 | { | ||
405 | string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_settings where EstateID = ?EstateID"; | ||
406 | |||
407 | cmd.CommandText = sql; | ||
408 | cmd.Parameters.AddWithValue("?EstateID", estateID); | ||
409 | |||
410 | return DoLoad(cmd, UUID.Zero, false); | ||
411 | } | ||
412 | } | ||
413 | |||
414 | public List<int> GetEstates(string search) | ||
415 | { | ||
416 | List<int> result = new List<int>(); | ||
417 | |||
418 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
419 | { | ||
420 | dbcon.Open(); | ||
421 | |||
422 | using (MySqlCommand cmd = dbcon.CreateCommand()) | ||
423 | { | ||
424 | cmd.CommandText = "select estateID from estate_settings where EstateName = ?EstateName"; | ||
425 | cmd.Parameters.AddWithValue("?EstateName", search); | ||
426 | |||
427 | using (IDataReader reader = cmd.ExecuteReader()) | ||
428 | { | ||
429 | while (reader.Read()) | ||
430 | { | ||
431 | result.Add(Convert.ToInt32(reader["EstateID"])); | ||
432 | } | ||
433 | reader.Close(); | ||
434 | } | ||
435 | } | ||
436 | |||
437 | |||
438 | dbcon.Close(); | ||
439 | } | ||
440 | |||
441 | return result; | ||
442 | } | ||
443 | |||
444 | public bool LinkRegion(UUID regionID, int estateID) | ||
445 | { | ||
446 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
447 | { | ||
448 | dbcon.Open(); | ||
449 | |||
450 | using (MySqlCommand cmd = dbcon.CreateCommand()) | ||
451 | { | ||
452 | cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; | ||
453 | cmd.Parameters.AddWithValue("?RegionID", regionID); | ||
454 | cmd.Parameters.AddWithValue("?EstateID", estateID); | ||
455 | |||
456 | if (cmd.ExecuteNonQuery() == 0) | ||
457 | { | ||
458 | dbcon.Close(); | ||
459 | return false; | ||
460 | } | ||
461 | } | ||
462 | |||
463 | dbcon.Close(); | ||
464 | } | ||
465 | |||
466 | return true; | ||
467 | } | ||
468 | |||
469 | public List<UUID> GetRegions(int estateID) | ||
470 | { | ||
471 | return new List<UUID>(); | ||
472 | } | ||
473 | |||
474 | public bool DeleteEstate(int estateID) | ||
475 | { | ||
476 | return false; | ||
477 | } | ||
393 | } | 478 | } |
394 | } | 479 | } |