aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLRegionData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLRegionData.cs228
1 files changed, 114 insertions, 114 deletions
diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs
index f514076..b0075e8 100644
--- a/OpenSim/Data/MySQL/MySQLRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLRegionData.cs
@@ -56,13 +56,12 @@ namespace OpenSim.Data.MySQL
56 if (scopeID != UUID.Zero) 56 if (scopeID != UUID.Zero)
57 command += " and ScopeID = ?scopeID"; 57 command += " and ScopeID = ?scopeID";
58 58
59 using (MySqlCommand cmd = new MySqlCommand(command)) 59 MySqlCommand cmd = new MySqlCommand(command);
60 {
61 cmd.Parameters.AddWithValue("?regionName", regionName);
62 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
63 60
64 return RunCommand(cmd); 61 cmd.Parameters.AddWithValue("?regionName", regionName);
65 } 62 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
63
64 return RunCommand(cmd);
66 } 65 }
67 66
68 public RegionData Get(int posX, int posY, UUID scopeID) 67 public RegionData Get(int posX, int posY, UUID scopeID)
@@ -71,18 +70,17 @@ namespace OpenSim.Data.MySQL
71 if (scopeID != UUID.Zero) 70 if (scopeID != UUID.Zero)
72 command += " and ScopeID = ?scopeID"; 71 command += " and ScopeID = ?scopeID";
73 72
74 using (MySqlCommand cmd = new MySqlCommand(command)) 73 MySqlCommand cmd = new MySqlCommand(command);
75 {
76 cmd.Parameters.AddWithValue("?posX", posX.ToString());
77 cmd.Parameters.AddWithValue("?posY", posY.ToString());
78 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
79 74
80 List<RegionData> ret = RunCommand(cmd); 75 cmd.Parameters.AddWithValue("?posX", posX.ToString());
81 if (ret.Count == 0) 76 cmd.Parameters.AddWithValue("?posY", posY.ToString());
82 return null; 77 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
83 78
84 return ret[0]; 79 List<RegionData> ret = RunCommand(cmd);
85 } 80 if (ret.Count == 0)
81 return null;
82
83 return ret[0];
86 } 84 }
87 85
88 public RegionData Get(UUID regionID, UUID scopeID) 86 public RegionData Get(UUID regionID, UUID scopeID)
@@ -91,17 +89,16 @@ namespace OpenSim.Data.MySQL
91 if (scopeID != UUID.Zero) 89 if (scopeID != UUID.Zero)
92 command += " and ScopeID = ?scopeID"; 90 command += " and ScopeID = ?scopeID";
93 91
94 using (MySqlCommand cmd = new MySqlCommand(command)) 92 MySqlCommand cmd = new MySqlCommand(command);
95 {
96 cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
97 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
98 93
99 List<RegionData> ret = RunCommand(cmd); 94 cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
100 if (ret.Count == 0) 95 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
101 return null;
102 96
103 return ret[0]; 97 List<RegionData> ret = RunCommand(cmd);
104 } 98 if (ret.Count == 0)
99 return null;
100
101 return ret[0];
105 } 102 }
106 103
107 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) 104 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
@@ -110,44 +107,43 @@ namespace OpenSim.Data.MySQL
110 if (scopeID != UUID.Zero) 107 if (scopeID != UUID.Zero)
111 command += " and ScopeID = ?scopeID"; 108 command += " and ScopeID = ?scopeID";
112 109
113 using (MySqlCommand cmd = new MySqlCommand(command)) 110 MySqlCommand cmd = new MySqlCommand(command);
114 {
115 cmd.Parameters.AddWithValue("?startX", startX.ToString());
116 cmd.Parameters.AddWithValue("?startY", startY.ToString());
117 cmd.Parameters.AddWithValue("?endX", endX.ToString());
118 cmd.Parameters.AddWithValue("?endY", endY.ToString());
119 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
120 111
121 return RunCommand(cmd); 112 cmd.Parameters.AddWithValue("?startX", startX.ToString());
122 } 113 cmd.Parameters.AddWithValue("?startY", startY.ToString());
114 cmd.Parameters.AddWithValue("?endX", endX.ToString());
115 cmd.Parameters.AddWithValue("?endY", endY.ToString());
116 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
117
118 return RunCommand(cmd);
123 } 119 }
124 120
125 public List<RegionData> RunCommand(MySqlCommand cmd) 121 public List<RegionData> RunCommand(MySqlCommand cmd)
126 { 122 {
127 List<RegionData> retList = new List<RegionData>(); 123 List<RegionData> retList = new List<RegionData>();
128 124
129 using (IDataReader result = ExecuteReader(cmd)) 125 IDataReader result = ExecuteReader(cmd);
126
127 while (result.Read())
130 { 128 {
131 while (result.Read()) 129 RegionData ret = new RegionData();
130 ret.Data = new Dictionary<string, object>();
131
132 UUID regionID;
133 UUID.TryParse(result["uuid"].ToString(), out regionID);
134 ret.RegionID = regionID;
135 UUID scope;
136 UUID.TryParse(result["ScopeID"].ToString(), out scope);
137 ret.ScopeID = scope;
138 ret.RegionName = result["regionName"].ToString();
139 ret.posX = Convert.ToInt32(result["locX"]);
140 ret.posY = Convert.ToInt32(result["locY"]);
141 ret.sizeX = Convert.ToInt32(result["sizeX"]);
142 ret.sizeY = Convert.ToInt32(result["sizeY"]);
143
144 if (m_ColumnNames == null)
132 { 145 {
133 RegionData ret = new RegionData(); 146 m_ColumnNames = new List<string>();
134 ret.Data = new Dictionary<string, object>();
135
136 UUID regionID;
137 UUID.TryParse(result["uuid"].ToString(), out regionID);
138 ret.RegionID = regionID;
139 UUID scope;
140 UUID.TryParse(result["ScopeID"].ToString(), out scope);
141 ret.ScopeID = scope;
142 ret.RegionName = result["regionName"].ToString();
143 ret.posX = Convert.ToInt32(result["locX"]);
144 ret.posY = Convert.ToInt32(result["locY"]);
145 ret.sizeX = Convert.ToInt32(result["sizeX"]);
146 ret.sizeY = Convert.ToInt32(result["sizeY"]);
147
148 if (m_ColumnNames == null)
149 {
150 m_ColumnNames = new List<string>();
151 147
152 DataTable schemaTable = result.GetSchemaTable(); 148 DataTable schemaTable = result.GetSchemaTable();
153 foreach (DataRow row in schemaTable.Rows) 149 foreach (DataRow row in schemaTable.Rows)
@@ -157,28 +153,28 @@ namespace OpenSim.Data.MySQL
157 } 153 }
158 } 154 }
159 155
160 foreach (string s in m_ColumnNames) 156 foreach (string s in m_ColumnNames)
161 { 157 {
162 if (s == "uuid") 158 if (s == "uuid")
163 continue; 159 continue;
164 if (s == "ScopeID") 160 if (s == "ScopeID")
165 continue; 161 continue;
166 if (s == "regionName") 162 if (s == "regionName")
167 continue; 163 continue;
168 if (s == "locX") 164 if (s == "locX")
169 continue; 165 continue;
170 if (s == "locY") 166 if (s == "locY")
171 continue; 167 continue;
172 168
173 ret.Data[s] = result[s].ToString(); 169 ret.Data[s] = result[s].ToString();
174 }
175
176 retList.Add(ret);
177 } 170 }
178 171
179 CloseDBConnection(result, cmd); 172 retList.Add(ret);
180 } 173 }
181 174
175 result.Close();
176 CloseReaderCommand(cmd);
177
182 return retList; 178 return retList;
183 } 179 }
184 180
@@ -205,72 +201,76 @@ namespace OpenSim.Data.MySQL
205 201
206 string[] fields = new List<string>(data.Data.Keys).ToArray(); 202 string[] fields = new List<string>(data.Data.Keys).ToArray();
207 203
208 using (MySqlCommand cmd = new MySqlCommand()) 204 MySqlCommand cmd = new MySqlCommand();
205
206 string update = "update `"+m_Realm+"` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
207 foreach (string field in fields)
209 { 208 {
210 string update = "update `" + m_Realm + "` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY"; 209 update += ", ";
211 foreach (string field in fields) 210 update += "`" + field + "` = ?"+field;
212 {
213 update += ", ";
214 update += "`" + field + "` = ?" + field;
215 211
216 cmd.Parameters.AddWithValue("?" + field, data.Data[field]); 212 cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
217 } 213 }
218 214
219 update += " where uuid = ?regionID"; 215 update += " where uuid = ?regionID";
220 216
221 if (data.ScopeID != UUID.Zero) 217 if (data.ScopeID != UUID.Zero)
222 update += " and ScopeID = ?scopeID"; 218 update += " and ScopeID = ?scopeID";
223 219
224 cmd.CommandText = update; 220 cmd.CommandText = update;
225 cmd.Parameters.AddWithValue("?regionID", data.RegionID.ToString()); 221 cmd.Parameters.AddWithValue("?regionID", data.RegionID.ToString());
226 cmd.Parameters.AddWithValue("?regionName", data.RegionName); 222 cmd.Parameters.AddWithValue("?regionName", data.RegionName);
227 cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); 223 cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
228 cmd.Parameters.AddWithValue("?posX", data.posX.ToString()); 224 cmd.Parameters.AddWithValue("?posX", data.posX.ToString());
229 cmd.Parameters.AddWithValue("?posY", data.posY.ToString()); 225 cmd.Parameters.AddWithValue("?posY", data.posY.ToString());
230 cmd.Parameters.AddWithValue("?sizeX", data.sizeX.ToString()); 226 cmd.Parameters.AddWithValue("?sizeX", data.sizeX.ToString());
231 cmd.Parameters.AddWithValue("?sizeY", data.sizeY.ToString()); 227 cmd.Parameters.AddWithValue("?sizeY", data.sizeY.ToString());
232 228
233 if (ExecuteNonQuery(cmd) < 1) 229 if (ExecuteNonQuery(cmd) < 1)
234 { 230 {
235 string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `locX`, `locY`, `sizeX`, `sizeY`, `regionName`, `" + 231 string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `locX`, `locY`, `sizeX`, `sizeY`, `regionName`, `" +
236 String.Join("`, `", fields) + 232 String.Join("`, `", fields) +
237 "`) values ( ?regionID, ?scopeID, ?posX, ?posY, ?sizeX, ?sizeY, ?regionName, ?" + String.Join(", ?", fields) + ")"; 233 "`) values ( ?regionID, ?scopeID, ?posX, ?posY, ?sizeX, ?sizeY, ?regionName, ?" + String.Join(", ?", fields) + ")";
238 234
239 cmd.CommandText = insert; 235 cmd.CommandText = insert;
240 236
241 if (ExecuteNonQuery(cmd) < 1) 237 if (ExecuteNonQuery(cmd) < 1)
242 { 238 {
243 return false; 239 cmd.Dispose();
244 } 240 return false;
245 } 241 }
246 } 242 }
247 243
244 cmd.Dispose();
245
248 return true; 246 return true;
249 } 247 }
250 248
251 public bool SetDataItem(UUID regionID, string item, string value) 249 public bool SetDataItem(UUID regionID, string item, string value)
252 { 250 {
253 using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" + item + "` = ?" + item + " where uuid = ?UUID")) 251 MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
254 { 252 "` set `" + item + "` = ?" + item + " where uuid = ?UUID");
255 cmd.Parameters.AddWithValue("?" + item, value);
256 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
257 253
258 if (ExecuteNonQuery(cmd) > 0) 254
259 return true; 255 cmd.Parameters.AddWithValue("?"+item, value);
260 } 256 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
257
258 if (ExecuteNonQuery(cmd) > 0)
259 return true;
261 260
262 return false; 261 return false;
263 } 262 }
264 263
265 public bool Delete(UUID regionID) 264 public bool Delete(UUID regionID)
266 { 265 {
267 using (MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm + "` where uuid = ?UUID")) 266 MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm +
268 { 267 "` where uuid = ?UUID");
269 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
270 268
271 if (ExecuteNonQuery(cmd) > 0) 269
272 return true; 270 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
273 } 271
272 if (ExecuteNonQuery(cmd) > 0)
273 return true;
274 274
275 return false; 275 return false;
276 } 276 }