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