aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLUserProfilesData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLUserProfilesData.cs588
1 files changed, 266 insertions, 322 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserProfilesData.cs b/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
index b35595d..16637c3 100644
--- a/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
@@ -40,39 +40,40 @@ namespace OpenSim.Data.MySQL
40 public class UserProfilesData: IProfilesData 40 public class UserProfilesData: IProfilesData
41 { 41 {
42 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 #region Properites 44 #region Properites
45 string ConnectionString 45 string ConnectionString
46 { 46 {
47 get; set; 47 get; set;
48 } 48 }
49 49
50 protected virtual Assembly Assembly 50 protected virtual Assembly Assembly
51 { 51 {
52 get { return GetType().Assembly; } 52 get { return GetType().Assembly; }
53 } 53 }
54 54
55 #endregion Properties 55 #endregion Properties
56 56
57 #region class Member Functions 57 #region class Member Functions
58 public UserProfilesData(string connectionString) 58 public UserProfilesData(string connectionString)
59 { 59 {
60 ConnectionString = connectionString; 60 ConnectionString = connectionString;
61 Init(); 61 Init();
62 } 62 }
63 63
64 void Init() 64 void Init()
65 { 65 {
66 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 66 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
67 { 67 {
68 dbcon.Open(); 68 dbcon.Open();
69 69
70 Migration m = new Migration(dbcon, Assembly, "UserProfiles"); 70 Migration m = new Migration(dbcon, Assembly, "UserProfiles");
71 m.Update(); 71 m.Update();
72 dbcon.Close();
72 } 73 }
73 } 74 }
74 #endregion Member Functions 75 #endregion Member Functions
75 76
76 #region Classifieds Queries 77 #region Classifieds Queries
77 /// <summary> 78 /// <summary>
78 /// Gets the classified records. 79 /// Gets the classified records.
@@ -86,10 +87,10 @@ namespace OpenSim.Data.MySQL
86 public OSDArray GetClassifiedRecords(UUID creatorId) 87 public OSDArray GetClassifiedRecords(UUID creatorId)
87 { 88 {
88 OSDArray data = new OSDArray(); 89 OSDArray data = new OSDArray();
89 90
90 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 91 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
91 { 92 {
92 string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id"; 93 const string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id";
93 dbcon.Open(); 94 dbcon.Open();
94 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 95 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
95 { 96 {
@@ -102,7 +103,7 @@ namespace OpenSim.Data.MySQL
102 { 103 {
103 OSDMap n = new OSDMap(); 104 OSDMap n = new OSDMap();
104 UUID Id = UUID.Zero; 105 UUID Id = UUID.Zero;
105 106
106 string Name = null; 107 string Name = null;
107 try 108 try
108 { 109 {
@@ -111,8 +112,7 @@ namespace OpenSim.Data.MySQL
111 } 112 }
112 catch (Exception e) 113 catch (Exception e)
113 { 114 {
114 m_log.ErrorFormat("[PROFILES_DATA]" + 115 m_log.ErrorFormat("[PROFILES_DATA] GetClassifiedRecords exception {0}", e.Message);
115 ": UserAccount exception {0}", e.Message);
116 } 116 }
117 n.Add("classifieduuid", OSD.FromUUID(Id)); 117 n.Add("classifieduuid", OSD.FromUUID(Id));
118 n.Add("name", OSD.FromString(Name)); 118 n.Add("name", OSD.FromString(Name));
@@ -121,73 +121,73 @@ namespace OpenSim.Data.MySQL
121 } 121 }
122 } 122 }
123 } 123 }
124 dbcon.Close();
124 } 125 }
125 return data; 126 return data;
126 } 127 }
127 128
128 public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result) 129 public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
129 { 130 {
130 string query = string.Empty; 131 const string query =
131 132 "INSERT INTO classifieds ("
132 133 + "`classifieduuid`,"
133 query += "INSERT INTO classifieds ("; 134 + "`creatoruuid`,"
134 query += "`classifieduuid`,"; 135 + "`creationdate`,"
135 query += "`creatoruuid`,"; 136 + "`expirationdate`,"
136 query += "`creationdate`,"; 137 + "`category`,"
137 query += "`expirationdate`,"; 138 + "`name`,"
138 query += "`category`,"; 139 + "`description`,"
139 query += "`name`,"; 140 + "`parceluuid`,"
140 query += "`description`,"; 141 + "`parentestate`,"
141 query += "`parceluuid`,"; 142 + "`snapshotuuid`,"
142 query += "`parentestate`,"; 143 + "`simname`,"
143 query += "`snapshotuuid`,"; 144 + "`posglobal`,"
144 query += "`simname`,"; 145 + "`parcelname`,"
145 query += "`posglobal`,"; 146 + "`classifiedflags`,"
146 query += "`parcelname`,"; 147 + "`priceforlisting`) "
147 query += "`classifiedflags`,"; 148 + "VALUES ("
148 query += "`priceforlisting`) "; 149 + "?ClassifiedId,"
149 query += "VALUES ("; 150 + "?CreatorId,"
150 query += "?ClassifiedId,"; 151 + "?CreatedDate,"
151 query += "?CreatorId,"; 152 + "?ExpirationDate,"
152 query += "?CreatedDate,"; 153 + "?Category,"
153 query += "?ExpirationDate,"; 154 + "?Name,"
154 query += "?Category,"; 155 + "?Description,"
155 query += "?Name,"; 156 + "?ParcelId,"
156 query += "?Description,"; 157 + "?ParentEstate,"
157 query += "?ParcelId,"; 158 + "?SnapshotId,"
158 query += "?ParentEstate,"; 159 + "?SimName,"
159 query += "?SnapshotId,"; 160 + "?GlobalPos,"
160 query += "?SimName,"; 161 + "?ParcelName,"
161 query += "?GlobalPos,"; 162 + "?Flags,"
162 query += "?ParcelName,"; 163 + "?ListingPrice ) "
163 query += "?Flags,"; 164 + "ON DUPLICATE KEY UPDATE "
164 query += "?ListingPrice ) "; 165 + "category=?Category, "
165 query += "ON DUPLICATE KEY UPDATE "; 166 + "expirationdate=?ExpirationDate, "
166 query += "category=?Category, "; 167 + "name=?Name, "
167 query += "expirationdate=?ExpirationDate, "; 168 + "description=?Description, "
168 query += "name=?Name, "; 169 + "parentestate=?ParentEstate, "
169 query += "description=?Description, "; 170 + "posglobal=?GlobalPos, "
170 query += "parentestate=?ParentEstate, "; 171 + "parcelname=?ParcelName, "
171 query += "posglobal=?GlobalPos, "; 172 + "classifiedflags=?Flags, "
172 query += "parcelname=?ParcelName, "; 173 + "priceforlisting=?ListingPrice, "
173 query += "classifiedflags=?Flags, "; 174 + "snapshotuuid=?SnapshotId"
174 query += "priceforlisting=?ListingPrice, "; 175 ;
175 query += "snapshotuuid=?SnapshotId"; 176
176
177 if(string.IsNullOrEmpty(ad.ParcelName)) 177 if(string.IsNullOrEmpty(ad.ParcelName))
178 ad.ParcelName = "Unknown"; 178 ad.ParcelName = "Unknown";
179 if(ad.ParcelId == null) 179 if(ad.ParcelId == null)
180 ad.ParcelId = UUID.Zero; 180 ad.ParcelId = UUID.Zero;
181 if(string.IsNullOrEmpty(ad.Description)) 181 if(string.IsNullOrEmpty(ad.Description))
182 ad.Description = "No Description"; 182 ad.Description = "No Description";
183 183
184 DateTime epoch = new DateTime(1970, 1, 1); 184 DateTime epoch = new DateTime(1970, 1, 1);
185 DateTime now = DateTime.Now; 185 DateTime now = DateTime.Now;
186 TimeSpan epochnow = now - epoch; 186 TimeSpan epochnow = now - epoch;
187 TimeSpan duration; 187 TimeSpan duration;
188 DateTime expiration; 188 DateTime expiration;
189 TimeSpan epochexp; 189 TimeSpan epochexp;
190 190
191 if(ad.Flags == 2) 191 if(ad.Flags == 2)
192 { 192 {
193 duration = new TimeSpan(7,0,0,0); 193 duration = new TimeSpan(7,0,0,0);
@@ -202,7 +202,7 @@ namespace OpenSim.Data.MySQL
202 } 202 }
203 ad.CreationDate = (int)epochnow.TotalSeconds; 203 ad.CreationDate = (int)epochnow.TotalSeconds;
204 ad.ExpirationDate = (int)epochexp.TotalSeconds; 204 ad.ExpirationDate = (int)epochexp.TotalSeconds;
205 205
206 try 206 try
207 { 207 {
208 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 208 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -225,57 +225,52 @@ namespace OpenSim.Data.MySQL
225 cmd.Parameters.AddWithValue("?ParcelName", ad.ParcelName.ToString()); 225 cmd.Parameters.AddWithValue("?ParcelName", ad.ParcelName.ToString());
226 cmd.Parameters.AddWithValue("?Flags", ad.Flags.ToString()); 226 cmd.Parameters.AddWithValue("?Flags", ad.Flags.ToString());
227 cmd.Parameters.AddWithValue("?ListingPrice", ad.Price.ToString ()); 227 cmd.Parameters.AddWithValue("?ListingPrice", ad.Price.ToString ());
228 228
229 cmd.ExecuteNonQuery(); 229 cmd.ExecuteNonQuery();
230 } 230 }
231 dbcon.Close();
231 } 232 }
232 } 233 }
233 catch (Exception e) 234 catch (Exception e)
234 { 235 {
235 m_log.ErrorFormat("[PROFILES_DATA]" + 236 m_log.ErrorFormat("[PROFILES_DATA]: UpdateClassifiedRecord exception {0}", e.Message);
236 ": ClassifiedesUpdate exception {0}", e.Message);
237 result = e.Message; 237 result = e.Message;
238 return false; 238 return false;
239 } 239 }
240 return true; 240 return true;
241 } 241 }
242 242
243 public bool DeleteClassifiedRecord(UUID recordId) 243 public bool DeleteClassifiedRecord(UUID recordId)
244 { 244 {
245 string query = string.Empty; 245 const string query = "DELETE FROM classifieds WHERE classifieduuid = ?recordId";
246 246
247 query += "DELETE FROM classifieds WHERE ";
248 query += "classifieduuid = ?recordId";
249
250 try 247 try
251 { 248 {
252 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 249 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
253 { 250 {
254 dbcon.Open(); 251 dbcon.Open();
255 252
256 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 253 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
257 { 254 {
258 cmd.Parameters.AddWithValue("?recordId", recordId.ToString()); 255 cmd.Parameters.AddWithValue("?recordId", recordId.ToString());
259 cmd.ExecuteNonQuery(); 256 cmd.ExecuteNonQuery();
260 } 257 }
258 dbcon.Close();
261 } 259 }
262 } 260 }
263 catch (Exception e) 261 catch (Exception e)
264 { 262 {
265 m_log.ErrorFormat("[PROFILES_DATA]" + 263 m_log.ErrorFormat("[PROFILES_DATA]: DeleteClassifiedRecord exception {0}", e.Message);
266 ": DeleteClassifiedRecord exception {0}", e.Message);
267 return false; 264 return false;
268 } 265 }
269 return true; 266 return true;
270 } 267 }
271 268
272 public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result) 269 public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
273 { 270 {
274 string query = string.Empty; 271
275 272 const string query = "SELECT * FROM classifieds WHERE classifieduuid = ?AdId";
276 query += "SELECT * FROM classifieds WHERE "; 273
277 query += "classifieduuid = ?AdId";
278
279 try 274 try
280 { 275 {
281 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 276 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -284,7 +279,7 @@ namespace OpenSim.Data.MySQL
284 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 279 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
285 { 280 {
286 cmd.Parameters.AddWithValue("?AdId", ad.ClassifiedId.ToString()); 281 cmd.Parameters.AddWithValue("?AdId", ad.ClassifiedId.ToString());
287 282
288 using (MySqlDataReader reader = cmd.ExecuteReader()) 283 using (MySqlDataReader reader = cmd.ExecuteReader())
289 { 284 {
290 if(reader.Read ()) 285 if(reader.Read ())
@@ -303,7 +298,7 @@ namespace OpenSim.Data.MySQL
303 ad.SimName = reader.GetString("simname"); 298 ad.SimName = reader.GetString("simname");
304 ad.GlobalPos = reader.GetString("posglobal"); 299 ad.GlobalPos = reader.GetString("posglobal");
305 ad.ParcelName = reader.GetString("parcelname"); 300 ad.ParcelName = reader.GetString("parcelname");
306 301
307 } 302 }
308 } 303 }
309 } 304 }
@@ -312,22 +307,19 @@ namespace OpenSim.Data.MySQL
312 } 307 }
313 catch (Exception e) 308 catch (Exception e)
314 { 309 {
315 m_log.ErrorFormat("[PROFILES_DATA]" + 310 m_log.ErrorFormat("[PROFILES_DATA]: GetClassifiedInfo exception {0}", e.Message);
316 ": GetPickInfo exception {0}", e.Message);
317 } 311 }
318 return true; 312 return true;
319 } 313 }
320 #endregion Classifieds Queries 314 #endregion Classifieds Queries
321 315
322 #region Picks Queries 316 #region Picks Queries
323 public OSDArray GetAvatarPicks(UUID avatarId) 317 public OSDArray GetAvatarPicks(UUID avatarId)
324 { 318 {
325 string query = string.Empty; 319 const string query = "SELECT `pickuuid`,`name` FROM userpicks WHERE creatoruuid = ?Id";
326 320
327 query += "SELECT `pickuuid`,`name` FROM userpicks WHERE ";
328 query += "creatoruuid = ?Id";
329 OSDArray data = new OSDArray(); 321 OSDArray data = new OSDArray();
330 322
331 try 323 try
332 { 324 {
333 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 325 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -336,7 +328,7 @@ namespace OpenSim.Data.MySQL
336 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 328 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
337 { 329 {
338 cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); 330 cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
339 331
340 using (MySqlDataReader reader = cmd.ExecuteReader()) 332 using (MySqlDataReader reader = cmd.ExecuteReader())
341 { 333 {
342 if(reader.HasRows) 334 if(reader.HasRows)
@@ -344,7 +336,7 @@ namespace OpenSim.Data.MySQL
344 while (reader.Read()) 336 while (reader.Read())
345 { 337 {
346 OSDMap record = new OSDMap(); 338 OSDMap record = new OSDMap();
347 339
348 record.Add("pickuuid",OSD.FromString((string)reader["pickuuid"])); 340 record.Add("pickuuid",OSD.FromString((string)reader["pickuuid"]));
349 record.Add("name",OSD.FromString((string)reader["name"])); 341 record.Add("name",OSD.FromString((string)reader["name"]));
350 data.Add(record); 342 data.Add(record);
@@ -352,25 +344,21 @@ namespace OpenSim.Data.MySQL
352 } 344 }
353 } 345 }
354 } 346 }
347 dbcon.Close();
355 } 348 }
356 } 349 }
357 catch (Exception e) 350 catch (Exception e)
358 { 351 {
359 m_log.ErrorFormat("[PROFILES_DATA]" + 352 m_log.ErrorFormat("[PROFILES_DATA]: GetAvatarPicks exception {0}", e.Message);
360 ": GetAvatarPicks exception {0}", e.Message);
361 } 353 }
362 return data; 354 return data;
363 } 355 }
364 356
365 public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId) 357 public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
366 { 358 {
367 string query = string.Empty;
368 UserProfilePick pick = new UserProfilePick(); 359 UserProfilePick pick = new UserProfilePick();
369 360 const string query = "SELECT * FROM userpicks WHERE creatoruuid = ?CreatorId AND pickuuid = ?PickId";
370 query += "SELECT * FROM userpicks WHERE "; 361
371 query += "creatoruuid = ?CreatorId AND ";
372 query += "pickuuid = ?PickId";
373
374 try 362 try
375 { 363 {
376 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 364 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -380,18 +368,18 @@ namespace OpenSim.Data.MySQL
380 { 368 {
381 cmd.Parameters.AddWithValue("?CreatorId", avatarId.ToString()); 369 cmd.Parameters.AddWithValue("?CreatorId", avatarId.ToString());
382 cmd.Parameters.AddWithValue("?PickId", pickId.ToString()); 370 cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
383 371
384 using (MySqlDataReader reader = cmd.ExecuteReader()) 372 using (MySqlDataReader reader = cmd.ExecuteReader())
385 { 373 {
386 if(reader.HasRows) 374 if(reader.HasRows)
387 { 375 {
388 reader.Read(); 376 reader.Read();
389 377
390 string description = (string)reader["description"]; 378 string description = (string)reader["description"];
391 379
392 if (string.IsNullOrEmpty(description)) 380 if (string.IsNullOrEmpty(description))
393 description = "No description given."; 381 description = "No description given.";
394 382
395 UUID.TryParse((string)reader["pickuuid"], out pick.PickId); 383 UUID.TryParse((string)reader["pickuuid"], out pick.PickId);
396 UUID.TryParse((string)reader["creatoruuid"], out pick.CreatorId); 384 UUID.TryParse((string)reader["creatoruuid"], out pick.CreatorId);
397 UUID.TryParse((string)reader["parceluuid"], out pick.ParcelId); 385 UUID.TryParse((string)reader["parceluuid"], out pick.ParcelId);
@@ -414,42 +402,41 @@ namespace OpenSim.Data.MySQL
414 } 402 }
415 catch (Exception e) 403 catch (Exception e)
416 { 404 {
417 m_log.ErrorFormat("[PROFILES_DATA]" + 405 m_log.ErrorFormat("[PROFILES_DATA]: GetPickInfo exception {0}", e.Message);
418 ": GetPickInfo exception {0}", e.Message);
419 } 406 }
420 return pick; 407 return pick;
421 } 408 }
422 409
423 public bool UpdatePicksRecord(UserProfilePick pick) 410 public bool UpdatePicksRecord(UserProfilePick pick)
424 { 411 {
425 string query = string.Empty; 412 const string query =
426 413 "INSERT INTO userpicks VALUES ("
427 query += "INSERT INTO userpicks VALUES ("; 414 + "?PickId,"
428 query += "?PickId,"; 415 + "?CreatorId,"
429 query += "?CreatorId,"; 416 + "?TopPick,"
430 query += "?TopPick,"; 417 + "?ParcelId,"
431 query += "?ParcelId,"; 418 + "?Name,"
432 query += "?Name,"; 419 + "?Desc,"
433 query += "?Desc,"; 420 + "?SnapshotId,"
434 query += "?SnapshotId,"; 421 + "?User,"
435 query += "?User,"; 422 + "?Original,"
436 query += "?Original,"; 423 + "?SimName,"
437 query += "?SimName,"; 424 + "?GlobalPos,"
438 query += "?GlobalPos,"; 425 + "?SortOrder,"
439 query += "?SortOrder,"; 426 + "?Enabled,"
440 query += "?Enabled,"; 427 + "?Gatekeeper)"
441 query += "?Gatekeeper)"; 428 + "ON DUPLICATE KEY UPDATE "
442 query += "ON DUPLICATE KEY UPDATE "; 429 + "parceluuid=?ParcelId,"
443 query += "parceluuid=?ParcelId,"; 430 + "name=?Name,"
444 query += "name=?Name,"; 431 + "description=?Desc,"
445 query += "description=?Desc,"; 432 + "user=?User,"
446 query += "user=?User,"; 433 + "simname=?SimName,"
447 query += "simname=?SimName,"; 434 + "snapshotuuid=?SnapshotId,"
448 query += "snapshotuuid=?SnapshotId,"; 435 + "pickuuid=?PickId,"
449 query += "pickuuid=?PickId,"; 436 + "posglobal=?GlobalPos,"
450 query += "posglobal=?GlobalPos,"; 437 + "gatekeeper=?Gatekeeper"
451 query += "gatekeeper=?Gatekeeper"; 438 ;
452 439
453 try 440 try
454 { 441 {
455 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 442 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -471,61 +458,53 @@ namespace OpenSim.Data.MySQL
471 cmd.Parameters.AddWithValue("?Gatekeeper",pick.Gatekeeper); 458 cmd.Parameters.AddWithValue("?Gatekeeper",pick.Gatekeeper);
472 cmd.Parameters.AddWithValue("?SortOrder", pick.SortOrder.ToString ()); 459 cmd.Parameters.AddWithValue("?SortOrder", pick.SortOrder.ToString ());
473 cmd.Parameters.AddWithValue("?Enabled", pick.Enabled.ToString()); 460 cmd.Parameters.AddWithValue("?Enabled", pick.Enabled.ToString());
474 461
475 cmd.ExecuteNonQuery(); 462 cmd.ExecuteNonQuery();
476 } 463 }
464 dbcon.Close();
477 } 465 }
478 } 466 }
479 catch (Exception e) 467 catch (Exception e)
480 { 468 {
481 m_log.ErrorFormat("[PROFILES_DATA]" + 469 m_log.ErrorFormat("[PROFILES_DATA]: UpdatePicksRecord exception {0}", e.Message);
482 ": UpdateAvatarNotes exception {0}", e.Message);
483 return false; 470 return false;
484 } 471 }
485 return true; 472 return true;
486 } 473 }
487 474
488 public bool DeletePicksRecord(UUID pickId) 475 public bool DeletePicksRecord(UUID pickId)
489 { 476 {
490 string query = string.Empty; 477 string query = "DELETE FROM userpicks WHERE pickuuid = ?PickId";
491 478
492 query += "DELETE FROM userpicks WHERE ";
493 query += "pickuuid = ?PickId";
494
495 try 479 try
496 { 480 {
497 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 481 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
498 { 482 {
499 dbcon.Open(); 483 dbcon.Open();
500 484
501 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 485 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
502 { 486 {
503 cmd.Parameters.AddWithValue("?PickId", pickId.ToString()); 487 cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
504 488
505 cmd.ExecuteNonQuery(); 489 cmd.ExecuteNonQuery();
506 } 490 }
491 dbcon.Close();
507 } 492 }
508 } 493 }
509 catch (Exception e) 494 catch (Exception e)
510 { 495 {
511 m_log.ErrorFormat("[PROFILES_DATA]" + 496 m_log.ErrorFormat("[PROFILES_DATA]: DeletePicksRecord exception {0}", e.Message);
512 ": DeleteUserPickRecord exception {0}", e.Message);
513 return false; 497 return false;
514 } 498 }
515 return true; 499 return true;
516 } 500 }
517 #endregion Picks Queries 501 #endregion Picks Queries
518 502
519 #region Avatar Notes Queries 503 #region Avatar Notes Queries
520 public bool GetAvatarNotes(ref UserProfileNotes notes) 504 public bool GetAvatarNotes(ref UserProfileNotes notes)
521 { // WIP 505 { // WIP
522 string query = string.Empty; 506 const string query = "SELECT `notes` FROM usernotes WHERE useruuid = ?Id AND targetuuid = ?TargetId";
523 507
524 query += "SELECT `notes` FROM usernotes WHERE ";
525 query += "useruuid = ?Id AND ";
526 query += "targetuuid = ?TargetId";
527 OSDArray data = new OSDArray();
528
529 try 508 try
530 { 509 {
531 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 510 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -535,7 +514,7 @@ namespace OpenSim.Data.MySQL
535 { 514 {
536 cmd.Parameters.AddWithValue("?Id", notes.UserId.ToString()); 515 cmd.Parameters.AddWithValue("?Id", notes.UserId.ToString());
537 cmd.Parameters.AddWithValue("?TargetId", notes.TargetId.ToString()); 516 cmd.Parameters.AddWithValue("?TargetId", notes.TargetId.ToString());
538 517
539 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 518 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
540 { 519 {
541 if(reader.HasRows) 520 if(reader.HasRows)
@@ -549,40 +528,39 @@ namespace OpenSim.Data.MySQL
549 } 528 }
550 } 529 }
551 } 530 }
531 dbcon.Close();
552 } 532 }
553 } 533 }
554 catch (Exception e) 534 catch (Exception e)
555 { 535 {
556 m_log.ErrorFormat("[PROFILES_DATA]" + 536 m_log.ErrorFormat("[PROFILES_DATA]: GetAvatarNotes exception {0}", e.Message);
557 ": GetAvatarNotes exception {0}", e.Message);
558 } 537 }
559 return true; 538 return true;
560 } 539 }
561 540
562 public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result) 541 public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
563 { 542 {
564 string query = string.Empty; 543 string query;
565 bool remove; 544 bool remove;
566 545
567 if(string.IsNullOrEmpty(note.Notes)) 546 if(string.IsNullOrEmpty(note.Notes))
568 { 547 {
569 remove = true; 548 remove = true;
570 query += "DELETE FROM usernotes WHERE "; 549 query = "DELETE FROM usernotes WHERE useruuid=?UserId AND targetuuid=?TargetId";
571 query += "useruuid=?UserId AND ";
572 query += "targetuuid=?TargetId";
573 } 550 }
574 else 551 else
575 { 552 {
576 remove = false; 553 remove = false;
577 query += "INSERT INTO usernotes VALUES ( "; 554 query = "INSERT INTO usernotes VALUES ("
578 query += "?UserId,"; 555 + "?UserId,"
579 query += "?TargetId,"; 556 + "?TargetId,"
580 query += "?Notes )"; 557 + "?Notes )"
581 query += "ON DUPLICATE KEY "; 558 + "ON DUPLICATE KEY "
582 query += "UPDATE "; 559 + "UPDATE "
583 query += "notes=?Notes"; 560 + "notes=?Notes"
561 ;
584 } 562 }
585 563
586 try 564 try
587 { 565 {
588 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 566 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -594,30 +572,27 @@ namespace OpenSim.Data.MySQL
594 cmd.Parameters.AddWithValue("?Notes", note.Notes); 572 cmd.Parameters.AddWithValue("?Notes", note.Notes);
595 cmd.Parameters.AddWithValue("?TargetId", note.TargetId.ToString ()); 573 cmd.Parameters.AddWithValue("?TargetId", note.TargetId.ToString ());
596 cmd.Parameters.AddWithValue("?UserId", note.UserId.ToString()); 574 cmd.Parameters.AddWithValue("?UserId", note.UserId.ToString());
597 575
598 cmd.ExecuteNonQuery(); 576 cmd.ExecuteNonQuery();
599 } 577 }
578 dbcon.Close();
600 } 579 }
601 } 580 }
602 catch (Exception e) 581 catch (Exception e)
603 { 582 {
604 m_log.ErrorFormat("[PROFILES_DATA]" + 583 m_log.ErrorFormat("[PROFILES_DATA]: UpdateAvatarNotes exception {0}", e.Message);
605 ": UpdateAvatarNotes exception {0}", e.Message);
606 return false; 584 return false;
607 } 585 }
608 return true; 586 return true;
609 587
610 } 588 }
611 #endregion Avatar Notes Queries 589 #endregion Avatar Notes Queries
612 590
613 #region Avatar Properties 591 #region Avatar Properties
614 public bool GetAvatarProperties(ref UserProfileProperties props, ref string result) 592 public bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
615 { 593 {
616 string query = string.Empty; 594 string query = "SELECT * FROM userprofile WHERE useruuid = ?Id";
617 595
618 query += "SELECT * FROM userprofile WHERE ";
619 query += "useruuid = ?Id";
620
621 try 596 try
622 { 597 {
623 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 598 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -626,11 +601,13 @@ namespace OpenSim.Data.MySQL
626 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 601 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
627 { 602 {
628 cmd.Parameters.AddWithValue("?Id", props.UserId.ToString()); 603 cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
629 604
630 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 605 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
631 { 606 {
632 if(reader.HasRows) 607 if(reader.HasRows)
633 { 608 {
609 m_log.DebugFormat("[PROFILES_DATA]" +
610 ": Getting data for {0}.", props.UserId);
634 reader.Read(); 611 reader.Read();
635 props.WebUrl = (string)reader["profileURL"]; 612 props.WebUrl = (string)reader["profileURL"];
636 UUID.TryParse((string)reader["profileImage"], out props.ImageId); 613 UUID.TryParse((string)reader["profileImage"], out props.ImageId);
@@ -646,6 +623,9 @@ namespace OpenSim.Data.MySQL
646 } 623 }
647 else 624 else
648 { 625 {
626 m_log.DebugFormat("[PROFILES_DATA]" +
627 ": No data for {0}", props.UserId);
628
649 props.WebUrl = string.Empty; 629 props.WebUrl = string.Empty;
650 props.ImageId = UUID.Zero; 630 props.ImageId = UUID.Zero;
651 props.AboutText = string.Empty; 631 props.AboutText = string.Empty;
@@ -660,35 +640,36 @@ namespace OpenSim.Data.MySQL
660 props.PublishProfile = false; 640 props.PublishProfile = false;
661 props.PublishMature = false; 641 props.PublishMature = false;
662 642
663 query = "INSERT INTO userprofile ("; 643 query = "INSERT INTO userprofile ("
664 query += "useruuid, "; 644 + "useruuid, "
665 query += "profilePartner, "; 645 + "profilePartner, "
666 query += "profileAllowPublish, "; 646 + "profileAllowPublish, "
667 query += "profileMaturePublish, "; 647 + "profileMaturePublish, "
668 query += "profileURL, "; 648 + "profileURL, "
669 query += "profileWantToMask, "; 649 + "profileWantToMask, "
670 query += "profileWantToText, "; 650 + "profileWantToText, "
671 query += "profileSkillsMask, "; 651 + "profileSkillsMask, "
672 query += "profileSkillsText, "; 652 + "profileSkillsText, "
673 query += "profileLanguages, "; 653 + "profileLanguages, "
674 query += "profileImage, "; 654 + "profileImage, "
675 query += "profileAboutText, "; 655 + "profileAboutText, "
676 query += "profileFirstImage, "; 656 + "profileFirstImage, "
677 query += "profileFirstText) VALUES ("; 657 + "profileFirstText) VALUES ("
678 query += "?userId, "; 658 + "?userId, "
679 query += "?profilePartner, "; 659 + "?profilePartner, "
680 query += "?profileAllowPublish, "; 660 + "?profileAllowPublish, "
681 query += "?profileMaturePublish, "; 661 + "?profileMaturePublish, "
682 query += "?profileURL, "; 662 + "?profileURL, "
683 query += "?profileWantToMask, "; 663 + "?profileWantToMask, "
684 query += "?profileWantToText, "; 664 + "?profileWantToText, "
685 query += "?profileSkillsMask, "; 665 + "?profileSkillsMask, "
686 query += "?profileSkillsText, "; 666 + "?profileSkillsText, "
687 query += "?profileLanguages, "; 667 + "?profileLanguages, "
688 query += "?profileImage, "; 668 + "?profileImage, "
689 query += "?profileAboutText, "; 669 + "?profileAboutText, "
690 query += "?profileFirstImage, "; 670 + "?profileFirstImage, "
691 query += "?profileFirstText)"; 671 + "?profileFirstText)"
672 ;
692 673
693 dbcon.Close(); 674 dbcon.Close();
694 dbcon.Open(); 675 dbcon.Open();
@@ -715,30 +696,25 @@ namespace OpenSim.Data.MySQL
715 } 696 }
716 } 697 }
717 } 698 }
699 dbcon.Close();
718 } 700 }
719 } 701 }
720 catch (Exception e) 702 catch (Exception e)
721 { 703 {
722 m_log.ErrorFormat("[PROFILES_DATA]" + 704 m_log.ErrorFormat("[PROFILES_DATA]: GetAvatarProperties exception {0}", e.Message);
723 ": Requst properties exception {0}", e.Message);
724 result = e.Message; 705 result = e.Message;
725 return false; 706 return false;
726 } 707 }
727 return true; 708 return true;
728 } 709 }
729 710
730 public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result) 711 public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)
731 { 712 {
732 string query = string.Empty; 713 const string query = "UPDATE userprofile SET profileURL=?profileURL,"
733 714 + "profileImage=?image, profileAboutText=?abouttext,"
734 query += "UPDATE userprofile SET "; 715 + "profileFirstImage=?firstlifeimage, profileFirstText=?firstlifetext "
735 query += "profileURL=?profileURL, "; 716 + "WHERE useruuid=?uuid";
736 query += "profileImage=?image, "; 717
737 query += "profileAboutText=?abouttext,";
738 query += "profileFirstImage=?firstlifeimage,";
739 query += "profileFirstText=?firstlifetext ";
740 query += "WHERE useruuid=?uuid";
741
742 try 718 try
743 { 719 {
744 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 720 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -752,35 +728,33 @@ namespace OpenSim.Data.MySQL
752 cmd.Parameters.AddWithValue("?firstlifeimage", props.FirstLifeImageId.ToString()); 728 cmd.Parameters.AddWithValue("?firstlifeimage", props.FirstLifeImageId.ToString());
753 cmd.Parameters.AddWithValue("?firstlifetext", props.FirstLifeText); 729 cmd.Parameters.AddWithValue("?firstlifetext", props.FirstLifeText);
754 cmd.Parameters.AddWithValue("?uuid", props.UserId.ToString()); 730 cmd.Parameters.AddWithValue("?uuid", props.UserId.ToString());
755 731
756 cmd.ExecuteNonQuery(); 732 cmd.ExecuteNonQuery();
757 } 733 }
734 dbcon.Close();
758 } 735 }
759 } 736 }
760 catch (Exception e) 737 catch (Exception e)
761 { 738 {
762 m_log.ErrorFormat("[PROFILES_DATA]" + 739 m_log.ErrorFormat("[PROFILES_DATA]: UpdateAvatarProperties exception {0}", e.Message);
763 ": AgentPropertiesUpdate exception {0}", e.Message); 740
764
765 return false; 741 return false;
766 } 742 }
767 return true; 743 return true;
768 } 744 }
769 #endregion Avatar Properties 745 #endregion Avatar Properties
770 746
771 #region Avatar Interests 747 #region Avatar Interests
772 public bool UpdateAvatarInterests(UserProfileProperties up, ref string result) 748 public bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
773 { 749 {
774 string query = string.Empty; 750 const string query = "UPDATE userprofile SET "
775 751 + "profileWantToMask=?WantMask, "
776 query += "UPDATE userprofile SET "; 752 + "profileWantToText=?WantText,"
777 query += "profileWantToMask=?WantMask, "; 753 + "profileSkillsMask=?SkillsMask,"
778 query += "profileWantToText=?WantText,"; 754 + "profileSkillsText=?SkillsText, "
779 query += "profileSkillsMask=?SkillsMask,"; 755 + "profileLanguages=?Languages "
780 query += "profileSkillsText=?SkillsText, "; 756 + "WHERE useruuid=?uuid";
781 query += "profileLanguages=?Languages "; 757
782 query += "WHERE useruuid=?uuid";
783
784 try 758 try
785 { 759 {
786 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 760 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -794,15 +768,14 @@ namespace OpenSim.Data.MySQL
794 cmd.Parameters.AddWithValue("?SkillsText", up.SkillsText); 768 cmd.Parameters.AddWithValue("?SkillsText", up.SkillsText);
795 cmd.Parameters.AddWithValue("?Languages", up.Language); 769 cmd.Parameters.AddWithValue("?Languages", up.Language);
796 cmd.Parameters.AddWithValue("?uuid", up.UserId.ToString()); 770 cmd.Parameters.AddWithValue("?uuid", up.UserId.ToString());
797 771
798 cmd.ExecuteNonQuery(); 772 cmd.ExecuteNonQuery();
799 } 773 }
800 } 774 }
801 } 775 }
802 catch (Exception e) 776 catch (Exception e)
803 { 777 {
804 m_log.ErrorFormat("[PROFILES_DATA]" + 778 m_log.ErrorFormat("[PROFILES_DATA]: UpdateAvatarInterests exception {0}", e.Message);
805 ": AgentInterestsUpdate exception {0}", e.Message);
806 result = e.Message; 779 result = e.Message;
807 return false; 780 return false;
808 } 781 }
@@ -813,21 +786,20 @@ namespace OpenSim.Data.MySQL
813 public OSDArray GetUserImageAssets(UUID avatarId) 786 public OSDArray GetUserImageAssets(UUID avatarId)
814 { 787 {
815 OSDArray data = new OSDArray(); 788 OSDArray data = new OSDArray();
816 string query = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id"; 789 const string queryA = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id";
817 790
818 // Get classified image assets 791 // Get classified image assets
819 792
820
821 try 793 try
822 { 794 {
823 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 795 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
824 { 796 {
825 dbcon.Open(); 797 dbcon.Open();
826 798
827 using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`classifieds`"), dbcon)) 799 using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`classifieds`"), dbcon))
828 { 800 {
829 cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); 801 cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
830 802
831 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 803 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
832 { 804 {
833 if(reader.HasRows) 805 if(reader.HasRows)
@@ -843,10 +815,10 @@ namespace OpenSim.Data.MySQL
843 dbcon.Close(); 815 dbcon.Close();
844 dbcon.Open(); 816 dbcon.Open();
845 817
846 using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon)) 818 using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`userpicks`"), dbcon))
847 { 819 {
848 cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); 820 cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
849 821
850 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 822 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
851 { 823 {
852 if(reader.HasRows) 824 if(reader.HasRows)
@@ -858,16 +830,16 @@ namespace OpenSim.Data.MySQL
858 } 830 }
859 } 831 }
860 } 832 }
861 833
862 dbcon.Close(); 834 dbcon.Close();
863 dbcon.Open(); 835 dbcon.Open();
864 836
865 query = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id"; 837 const string queryB = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id";
866 838
867 using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon)) 839 using (MySqlCommand cmd = new MySqlCommand(string.Format (queryB,"`userpicks`"), dbcon))
868 { 840 {
869 cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); 841 cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
870 842
871 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 843 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
872 { 844 {
873 if(reader.HasRows) 845 if(reader.HasRows)
@@ -880,27 +852,21 @@ namespace OpenSim.Data.MySQL
880 } 852 }
881 } 853 }
882 } 854 }
855 dbcon.Close();
883 } 856 }
884 } 857 }
885 catch (Exception e) 858 catch (Exception e)
886 { 859 {
887 m_log.ErrorFormat("[PROFILES_DATA]" + 860 m_log.ErrorFormat("[PROFILES_DATA]: GetUserImageAssets exception {0}", e.Message);
888 ": GetAvatarNotes exception {0}", e.Message);
889 } 861 }
890 return data; 862 return data;
891 } 863 }
892 864
893 #region User Preferences 865 #region User Preferences
894 public bool GetUserPreferences(ref UserPreferences pref, ref string result) 866 public bool GetUserPreferences(ref UserPreferences pref, ref string result)
895 { 867 {
896 string query = string.Empty; 868 const string query = "SELECT imviaemail,visible,email FROM usersettings WHERE useruuid = ?Id";
897 869
898 query += "SELECT imviaemail,visible,email FROM ";
899 query += "usersettings WHERE ";
900 query += "useruuid = ?Id";
901
902 OSDArray data = new OSDArray();
903
904 try 870 try
905 { 871 {
906 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 872 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -909,10 +875,9 @@ namespace OpenSim.Data.MySQL
909 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 875 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
910 { 876 {
911 cmd.Parameters.AddWithValue("?Id", pref.UserId.ToString()); 877 cmd.Parameters.AddWithValue("?Id", pref.UserId.ToString());
912
913 using (MySqlDataReader reader = cmd.ExecuteReader()) 878 using (MySqlDataReader reader = cmd.ExecuteReader())
914 { 879 {
915 if(reader.HasRows) 880 if (reader.HasRows)
916 { 881 {
917 reader.Read(); 882 reader.Read();
918 bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail); 883 bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail);
@@ -923,13 +888,12 @@ namespace OpenSim.Data.MySQL
923 { 888 {
924 dbcon.Close(); 889 dbcon.Close();
925 dbcon.Open(); 890 dbcon.Open();
926
927 query = "INSERT INTO usersettings VALUES ";
928 query += "(?uuid,'false','false', ?Email)";
929 891
930 using (MySqlCommand put = new MySqlCommand(query, dbcon)) 892 const string queryB = "INSERT INTO usersettings VALUES (?uuid,'false','false', ?Email)";
893
894 using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
931 { 895 {
932 896
933 put.Parameters.AddWithValue("?Email", pref.EMail); 897 put.Parameters.AddWithValue("?Email", pref.EMail);
934 put.Parameters.AddWithValue("?uuid", pref.UserId.ToString()); 898 put.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
935 899
@@ -938,28 +902,24 @@ namespace OpenSim.Data.MySQL
938 } 902 }
939 } 903 }
940 } 904 }
905 dbcon.Close();
941 } 906 }
942 } 907 }
943 catch (Exception e) 908 catch (Exception e)
944 { 909 {
945 m_log.ErrorFormat("[PROFILES_DATA]" + 910 m_log.ErrorFormat("[PROFILES_DATA]: GetUserPreferences exception {0}", e.Message);
946 ": Get preferences exception {0}", e.Message);
947 result = e.Message; 911 result = e.Message;
948 return false; 912 return false;
949 } 913 }
950 return true; 914 return true;
951 } 915 }
952 916
953 public bool UpdateUserPreferences(ref UserPreferences pref, ref string result) 917 public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
954 { 918 {
955 string query = string.Empty; 919 const string query = "UPDATE usersettings SET imviaemail=?ImViaEmail,"
956 920 + "visible=?Visible, email=?EMail "
957 query += "UPDATE usersettings SET "; 921 + "WHERE useruuid=?uuid";
958 query += "imviaemail=?ImViaEmail, "; 922
959 query += "visible=?Visible, ";
960 query += "email=?EMail ";
961 query += "WHERE useruuid=?uuid";
962
963 try 923 try
964 { 924 {
965 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 925 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -974,28 +934,24 @@ namespace OpenSim.Data.MySQL
974 934
975 cmd.ExecuteNonQuery(); 935 cmd.ExecuteNonQuery();
976 } 936 }
937 dbcon.Close();
977 } 938 }
978 } 939 }
979 catch (Exception e) 940 catch (Exception e)
980 { 941 {
981 m_log.ErrorFormat("[PROFILES_DATA]" + 942 m_log.ErrorFormat("[PROFILES_DATA]: UpdateUserPreferences exception {0} {1}", e.Message, e.InnerException);
982 ": UserPreferencesUpdate exception {0} {1}", e.Message, e.InnerException);
983 result = e.Message; 943 result = e.Message;
984 return false; 944 return false;
985 } 945 }
986 return true; 946 return true;
987 } 947 }
988 #endregion User Preferences 948 #endregion User Preferences
989 949
990 #region Integration 950 #region Integration
991 public bool GetUserAppData(ref UserAppData props, ref string result) 951 public bool GetUserAppData(ref UserAppData props, ref string result)
992 { 952 {
993 string query = string.Empty; 953 const string query = "SELECT * FROM `userdata` WHERE UserId = ?Id AND TagId = ?TagId";
994 954
995 query += "SELECT * FROM `userdata` WHERE ";
996 query += "UserId = ?Id AND ";
997 query += "TagId = ?TagId";
998
999 try 955 try
1000 { 956 {
1001 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 957 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -1005,7 +961,7 @@ namespace OpenSim.Data.MySQL
1005 { 961 {
1006 cmd.Parameters.AddWithValue("?Id", props.UserId.ToString()); 962 cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
1007 cmd.Parameters.AddWithValue ("?TagId", props.TagId.ToString()); 963 cmd.Parameters.AddWithValue ("?TagId", props.TagId.ToString());
1008 964
1009 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 965 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
1010 { 966 {
1011 if(reader.HasRows) 967 if(reader.HasRows)
@@ -1016,13 +972,8 @@ namespace OpenSim.Data.MySQL
1016 } 972 }
1017 else 973 else
1018 { 974 {
1019 query += "INSERT INTO userdata VALUES ( "; 975 const string queryB = "INSERT INTO userdata VALUES (?UserId, ?TagId, ?DataKey, ?DataVal)";
1020 query += "?UserId,"; 976 using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
1021 query += "?TagId,";
1022 query += "?DataKey,";
1023 query += "?DataVal) ";
1024
1025 using (MySqlCommand put = new MySqlCommand(query, dbcon))
1026 { 977 {
1027 put.Parameters.AddWithValue("?UserId", props.UserId.ToString()); 978 put.Parameters.AddWithValue("?UserId", props.UserId.ToString());
1028 put.Parameters.AddWithValue("?TagId", props.TagId.ToString()); 979 put.Parameters.AddWithValue("?TagId", props.TagId.ToString());
@@ -1034,12 +985,12 @@ namespace OpenSim.Data.MySQL
1034 } 985 }
1035 } 986 }
1036 } 987 }
988 dbcon.Close();
1037 } 989 }
1038 } 990 }
1039 catch (Exception e) 991 catch (Exception e)
1040 { 992 {
1041 m_log.ErrorFormat("[PROFILES_DATA]" + 993 m_log.ErrorFormat("[PROFILES_DATA]: GetUserAppData exception {0}", e.Message);
1042 ": Requst application data exception {0}", e.Message);
1043 result = e.Message; 994 result = e.Message;
1044 return false; 995 return false;
1045 } 996 }
@@ -1047,16 +998,9 @@ namespace OpenSim.Data.MySQL
1047 } 998 }
1048 999
1049 public bool SetUserAppData(UserAppData props, ref string result) 1000 public bool SetUserAppData(UserAppData props, ref string result)
1050 { 1001 {
1051 string query = string.Empty; 1002 const string query = "UPDATE userdata SET TagId = ?TagId, DataKey = ?DataKey, DataVal = ?DataVal WHERE UserId = ?UserId AND TagId = ?TagId";
1052 1003
1053 query += "UPDATE userdata SET ";
1054 query += "TagId = ?TagId, ";
1055 query += "DataKey = ?DataKey, ";
1056 query += "DataVal = ?DataVal WHERE ";
1057 query += "UserId = ?UserId AND ";
1058 query += "TagId = ?TagId";
1059
1060 try 1004 try
1061 { 1005 {
1062 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) 1006 using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
@@ -1071,12 +1015,12 @@ namespace OpenSim.Data.MySQL
1071 1015
1072 cmd.ExecuteNonQuery(); 1016 cmd.ExecuteNonQuery();
1073 } 1017 }
1018 dbcon.Close();
1074 } 1019 }
1075 } 1020 }
1076 catch (Exception e) 1021 catch (Exception e)
1077 { 1022 {
1078 m_log.ErrorFormat("[PROFILES_DATA]" + 1023 m_log.ErrorFormat("[PROFILES_DATA]: SetUserAppData exception {0}", e.Message);
1079 ": SetUserData exception {0}", e.Message);
1080 return false; 1024 return false;
1081 } 1025 }
1082 return true; 1026 return true;