30 using System.Reflection;
32 using OpenSim.Framework;
34 using OpenMetaverse.StructuredData;
38 namespace OpenSim.Data.PGSQL
42 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 string ConnectionString
53 protected virtual Assembly Assembly
55 get {
return GetType().Assembly; }
60 #region class Member Functions
63 ConnectionString = connectionString;
69 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
78 #endregion Member Functions
80 #region Classifieds Queries
81 public OSDArray GetClassifiedRecords(UUID creatorId)
94 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
96 string query =
@"SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = :Id";
98 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
100 cmd.Parameters.Add(m_database.CreateParameter(
"Id", creatorId));
101 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
105 while (reader.Read())
113 Id = DBGuid.FromDB(reader[
"classifieduuid"]);
114 Name = Convert.ToString(reader[
"name"]);
118 m_log.Error(
"[PROFILES_DATA]: UserAccount exception ", e);
121 n.Add(
"classifieduuid", OSD.FromUUID(Id));
122 n.Add(
"name", OSD.FromString(Name));
134 string query = string.Empty;
136 query =
@"WITH upsert AS (
137 UPDATE classifieds SET
138 classifieduuid = :ClassifiedId, creatoruuid = :CreatorId, creationdate = :CreatedDate,
139 expirationdate = :ExpirationDate,category =:Category, name = :Name, description = :Description,
140 parceluuid = :ParcelId, parentestate = :ParentEstate, snapshotuuid = :SnapshotId,
141 simname = :SimName, posglobal = :GlobalPos, parcelname = :ParcelName, classifiedflags = :Flags,
142 priceforlisting = :ListingPrice
144 INSERT INTO classifieds (classifieduuid,creatoruuid,creationdate,expirationdate,category,name,
145 description,parceluuid,parentestate,snapshotuuid,simname,posglobal,parcelname,classifiedflags,
148 :ClassifiedId,:CreatorId,:CreatedDate,:ExpirationDate,:Category,:Name,:Description,
149 :ParcelId,:ParentEstate,:SnapshotId,:SimName,:GlobalPos,:ParcelName,:Flags,:ListingPrice
151 SELECT * FROM upsert )";
154 ad.ParcelName =
"Unknown";
156 ad.ParcelId = UUID.Zero;
158 ad.Description =
"No Description";
160 DateTime epoch =
new DateTime(1970, 1, 1);
161 DateTime now = DateTime.Now;
162 TimeSpan epochnow = now - epoch;
169 duration =
new TimeSpan(7, 0, 0, 0);
170 expiration = now.Add(duration);
171 epochexp = expiration - epoch;
175 duration =
new TimeSpan(365, 0, 0, 0);
176 expiration = now.Add(duration);
177 epochexp = expiration - epoch;
179 ad.CreationDate = (int)epochnow.TotalSeconds;
184 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
187 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
189 cmd.Parameters.Add(m_database.CreateParameter(
"ClassifiedId", ad.ClassifiedId));
190 cmd.Parameters.Add(m_database.CreateParameter(
"CreatorId", ad.CreatorId));
191 cmd.Parameters.Add(m_database.CreateParameter(
"CreatedDate", (int)ad.
CreationDate));
192 cmd.Parameters.Add(m_database.CreateParameter(
"ExpirationDate", (int)ad.
ExpirationDate));
193 cmd.Parameters.Add(m_database.CreateParameter(
"Category", ad.Category.ToString()));
194 cmd.Parameters.Add(m_database.CreateParameter(
"Name", ad.Name.ToString()));
195 cmd.Parameters.Add(m_database.CreateParameter(
"Description", ad.Description.ToString()));
196 cmd.Parameters.Add(m_database.CreateParameter(
"ParcelId", ad.ParcelId));
197 cmd.Parameters.Add(m_database.CreateParameter(
"ParentEstate", (int)ad.
ParentEstate));
198 cmd.Parameters.Add(m_database.CreateParameter(
"SnapshotId", ad.SnapshotId));
199 cmd.Parameters.Add(m_database.CreateParameter(
"SimName", ad.SimName.ToString()));
200 cmd.Parameters.Add(m_database.CreateParameter(
"GlobalPos", ad.GlobalPos.ToString()));
201 cmd.Parameters.Add(m_database.CreateParameter(
"ParcelName", ad.ParcelName.ToString()));
202 cmd.Parameters.Add(m_database.CreateParameter(
"Flags", (int)Convert.ToInt32(ad.
Flags)));
203 cmd.Parameters.Add(m_database.CreateParameter(
"ListingPrice", (int)Convert.ToInt32(ad.
Price)));
205 cmd.ExecuteNonQuery();
211 m_log.Error(
"[PROFILES_DATA]: ClassifiedsUpdate exception ", e);
221 string query = string.Empty;
223 query =
@"DELETE FROM classifieds WHERE classifieduuid = :ClassifiedId ;";
227 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
231 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
233 cmd.Parameters.Add(m_database.CreateParameter(
"ClassifiedId", recordId));
234 cmd.ExecuteNonQuery();
240 m_log.Error(
"[PROFILES_DATA]: DeleteClassifiedRecord exception ", e);
249 string query = string.Empty;
251 query +=
"SELECT * FROM classifieds WHERE ";
252 query +=
"classifieduuid = :AdId";
256 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
259 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
261 cmd.Parameters.Add(m_database.CreateParameter(
"AdId", ad.ClassifiedId));
263 using (NpgsqlDataReader reader = cmd.ExecuteReader())
267 ad.CreatorId = DBGuid.FromDB(reader[
"creatoruuid"]);
268 ad.ParcelId = DBGuid.FromDB(reader[
"parceluuid"]);
269 ad.SnapshotId = DBGuid.FromDB(reader[
"snapshotuuid"]);
270 ad.CreationDate = Convert.ToInt32(reader[
"creationdate"]);
271 ad.ExpirationDate = Convert.ToInt32(reader[
"expirationdate"]);
272 ad.ParentEstate = Convert.ToInt32(reader[
"parentestate"]);
273 ad.Flags = (byte)Convert.ToInt16(reader[
"classifiedflags"]);
274 ad.Category = Convert.ToInt32(reader[
"category"]);
275 ad.Price = Convert.ToInt16(reader[
"priceforlisting"]);
276 ad.Name = reader[
"name"].ToString();
277 ad.Description = reader[
"description"].ToString();
278 ad.SimName = reader[
"simname"].ToString();
279 ad.GlobalPos = reader[
"posglobal"].ToString();
280 ad.ParcelName = reader[
"parcelname"].ToString();
289 m_log.Error(
"[PROFILES_DATA]: GetClassifiedInfo exception ", e);
298 UUID ret = UUID.Zero;
300 UUID.TryParse(uuidValue.ToString(), out ret);
305 #endregion Classifieds Queries
307 #region Picks Queries
310 string query = string.Empty;
312 query +=
"SELECT pickuuid, name FROM userpicks WHERE ";
313 query +=
"creatoruuid = :Id";
318 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
321 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
323 cmd.Parameters.Add(m_database.CreateParameter(
"Id", avatarId));
325 using (NpgsqlDataReader reader = cmd.ExecuteReader())
329 while (reader.Read())
333 record.Add(
"pickuuid", OSD.FromUUID(DBGuid.FromDB(reader[
"pickuuid"])));
334 record.Add(
"name", OSD.FromString((string)reader[
"name"]));
344 m_log.Error(
"[PROFILES_DATA]: GetAvatarPicks exception ", e);
352 string query = string.Empty;
355 query +=
"SELECT * FROM userpicks WHERE ";
356 query +=
"creatoruuid = :CreatorId AND ";
357 query +=
"pickuuid = :PickId";
361 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
364 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
366 cmd.Parameters.Add(m_database.CreateParameter(
"CreatorId", avatarId));
367 cmd.Parameters.Add(m_database.CreateParameter(
"PickId", pickId));
369 using (NpgsqlDataReader reader = cmd.ExecuteReader())
375 string description = (string)reader[
"description"];
377 if (
string.IsNullOrEmpty(description))
378 description =
"No description given.";
380 pick.PickId = DBGuid.FromDB(reader[
"pickuuid"]);
381 pick.CreatorId = DBGuid.FromDB(reader[
"creatoruuid"]);
382 pick.ParcelId = DBGuid.FromDB(reader[
"parceluuid"]);
383 pick.SnapshotId = DBGuid.FromDB(reader[
"snapshotuuid"]);
384 pick.GlobalPos = (string)reader[
"posglobal"].ToString();
385 pick.TopPick = Convert.ToBoolean(reader[
"toppick"]);
386 pick.Enabled = Convert.ToBoolean(reader[
"enabled"]);
387 pick.Name = reader[
"name"].ToString();
388 pick.Desc = reader[
"description"].ToString();
389 pick.ParcelName = reader[
"user"].ToString();
390 pick.OriginalName = reader[
"originalname"].ToString();
391 pick.SimName = reader[
"simname"].ToString();
392 pick.SortOrder = (int)reader[
"sortorder"];
401 m_log.Error(
"[PROFILES_DATA]: GetPickInfo exception ", e);
409 string query = string.Empty;
412 query =
@"WITH upsert AS (
414 pickuuid = :PickId, creatoruuid = :CreatorId, toppick = :TopPick, parceluuid = :ParcelId,
415 name = :Name, description = :Desc, snapshotuuid = :SnapshotId, ""user"" = :User,
416 originalname = :Original, simname = :SimName, posglobal = :GlobalPos,
417 sortorder = :SortOrder, enabled = :Enabled
419 INSERT INTO userpicks (pickuuid,creatoruuid,toppick,parceluuid,name,description,
420 snapshotuuid,""user"",originalname,simname,posglobal,sortorder,enabled)
422 :PickId,:CreatorId,:TopPick,:ParcelId,:Name,:Desc,:SnapshotId,:User,
423 :Original,:SimName,:GlobalPos,:SortOrder,:Enabled
425 SELECT * FROM upsert )";
429 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
432 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
434 cmd.Parameters.Add(m_database.CreateParameter(
"PickId", pick.PickId));
435 cmd.Parameters.Add(m_database.CreateParameter(
"CreatorId", pick.CreatorId));
436 cmd.Parameters.Add(m_database.CreateParameter(
"TopPick", pick.TopPick));
437 cmd.Parameters.Add(m_database.CreateParameter(
"ParcelId", pick.ParcelId));
438 cmd.Parameters.Add(m_database.CreateParameter(
"Name", pick.Name));
439 cmd.Parameters.Add(m_database.CreateParameter(
"Desc", pick.Desc));
440 cmd.Parameters.Add(m_database.CreateParameter(
"SnapshotId", pick.SnapshotId));
441 cmd.Parameters.Add(m_database.CreateParameter(
"User", pick.ParcelName));
442 cmd.Parameters.Add(m_database.CreateParameter(
"Original", pick.OriginalName));
443 cmd.Parameters.Add(m_database.CreateParameter(
"SimName", pick.SimName));
444 cmd.Parameters.Add(m_database.CreateParameter(
"GlobalPos", pick.GlobalPos));
445 cmd.Parameters.Add(m_database.CreateParameter(
"SortOrder", pick.SortOrder));
446 cmd.Parameters.Add(m_database.CreateParameter(
"Enabled", pick.Enabled));
448 cmd.ExecuteNonQuery();
454 m_log.Error(
"[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
463 string query = string.Empty;
465 query +=
"DELETE FROM userpicks WHERE ";
466 query +=
"pickuuid = :PickId";
470 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
474 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
476 cmd.Parameters.Add(m_database.CreateParameter(
"PickId", pickId));
478 cmd.ExecuteNonQuery();
484 m_log.Error(
"[PROFILES_DATA]: DeleteUserPickRecord exception ", e);
491 #endregion Picks Queries
493 #region Avatar Notes Queries
497 string query = string.Empty;
499 query +=
"SELECT notes FROM usernotes WHERE ";
500 query +=
"useruuid = :Id AND ";
501 query +=
"targetuuid = :TargetId";
506 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
509 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
511 cmd.Parameters.Add(m_database.CreateParameter(
"Id", notes.UserId));
512 cmd.Parameters.Add(m_database.CreateParameter(
"TargetId", notes.TargetId));
514 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
519 notes.Notes = OSD.FromString((string)reader[
"notes"]);
527 m_log.Error(
"[PROFILES_DATA]: GetAvatarNotes exception ", e);
535 string query = string.Empty;
538 if (
string.IsNullOrEmpty(note.Notes))
541 query +=
"DELETE FROM usernotes WHERE ";
542 query +=
"useruuid=:UserId AND ";
543 query +=
"targetuuid=:TargetId";
549 query =
@"WITH upsert AS (
550 UPDATE usernotes SET notes = :Notes, useruuid = :UserId, targetuuid = :TargetId RETURNING * )
551 INSERT INTO usernotes (notes,useruuid,targetuuid)
552 SELECT :Notes,:UserId,:TargetId
560 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
563 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
566 cmd.Parameters.Add(m_database.CreateParameter(
"Notes", note.Notes));
568 cmd.Parameters.Add(m_database.CreateParameter(
"TargetId", note.TargetId));
569 cmd.Parameters.Add(m_database.CreateParameter(
"UserId", note.UserId));
571 cmd.ExecuteNonQuery();
577 m_log.Error(
"[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
584 #endregion Avatar Notes Queries
586 #region Avatar Properties
590 string query = string.Empty;
592 query +=
"SELECT * FROM userprofile WHERE ";
593 query +=
"useruuid = :Id";
597 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
600 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
602 cmd.Parameters.Add(m_database.CreateParameter(
"Id", props.UserId));
604 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
611 props.WebUrl = (string)reader[
"profileURL"].ToString();
612 props.ImageId = DBGuid.FromDB(reader[
"profileImage"]);
613 props.AboutText = (string)reader[
"profileAboutText"];
614 props.FirstLifeImageId = DBGuid.FromDB(reader[
"profileFirstImage"]);
615 props.FirstLifeText = (string)reader[
"profileFirstText"];
616 props.PartnerId = DBGuid.FromDB(reader[
"profilePartner"]);
617 props.WantToMask = (int)reader[
"profileWantToMask"];
618 props.WantToText = (string)reader[
"profileWantToText"];
619 props.SkillsMask = (int)reader[
"profileSkillsMask"];
620 props.SkillsText = (string)reader[
"profileSkillsText"];
621 props.Language = (string)reader[
"profileLanguages"];
628 props.WebUrl = string.Empty;
629 props.ImageId = UUID.Zero;
630 props.AboutText = string.Empty;
631 props.FirstLifeImageId = UUID.Zero;
632 props.FirstLifeText = string.Empty;
633 props.PartnerId = UUID.Zero;
634 props.WantToMask = 0;
635 props.WantToText = string.Empty;
636 props.SkillsMask = 0;
637 props.SkillsText = string.Empty;
638 props.Language = string.Empty;
639 props.PublishProfile =
false;
640 props.PublishMature =
false;
642 query =
"INSERT INTO userprofile (";
643 query +=
"useruuid, ";
644 query +=
"\"profilePartner\", ";
645 query +=
"\"profileAllowPublish\", ";
646 query +=
"\"profileMaturePublish\", ";
647 query +=
"\"profileURL\", ";
648 query +=
"\"profileWantToMask\", ";
649 query +=
"\"profileWantToText\", ";
650 query +=
"\"profileSkillsMask\", ";
651 query +=
"\"profileSkillsText\", ";
652 query +=
"\"profileLanguages\", ";
653 query +=
"\"profileImage\", ";
654 query +=
"\"profileAboutText\", ";
655 query +=
"\"profileFirstImage\", ";
656 query +=
"\"profileFirstText\") VALUES (";
657 query +=
":userId, ";
658 query +=
":profilePartner, ";
659 query +=
":profileAllowPublish, ";
660 query +=
":profileMaturePublish, ";
661 query +=
":profileURL, ";
662 query +=
":profileWantToMask, ";
663 query +=
":profileWantToText, ";
664 query +=
":profileSkillsMask, ";
665 query +=
":profileSkillsText, ";
666 query +=
":profileLanguages, ";
667 query +=
":profileImage, ";
668 query +=
":profileAboutText, ";
669 query +=
":profileFirstImage, ";
670 query +=
":profileFirstText)";
675 using (NpgsqlCommand put =
new NpgsqlCommand(query, dbcon))
680 put.Parameters.Add(m_database.CreateParameter(
"userId", props.UserId));
681 put.Parameters.Add(m_database.CreateParameter(
"profilePartner", props.PartnerId));
682 put.Parameters.Add(m_database.CreateParameter(
"profileAllowPublish", props.PublishProfile));
683 put.Parameters.Add(m_database.CreateParameter(
"profileMaturePublish", props.PublishMature));
684 put.Parameters.Add(m_database.CreateParameter(
"profileURL", props.WebUrl));
685 put.Parameters.Add(m_database.CreateParameter(
"profileWantToMask", props.WantToMask));
686 put.Parameters.Add(m_database.CreateParameter(
"profileWantToText", props.WantToText));
687 put.Parameters.Add(m_database.CreateParameter(
"profileSkillsMask", props.SkillsMask));
688 put.Parameters.Add(m_database.CreateParameter(
"profileSkillsText", props.SkillsText));
689 put.Parameters.Add(m_database.CreateParameter(
"profileLanguages", props.Language));
690 put.Parameters.Add(m_database.CreateParameter(
"profileImage", props.ImageId));
691 put.Parameters.Add(m_database.CreateParameter(
"profileAboutText", props.AboutText));
692 put.Parameters.Add(m_database.CreateParameter(
"profileFirstImage", props.FirstLifeImageId));
693 put.Parameters.Add(m_database.CreateParameter(
"profileFirstText", props.FirstLifeText));
695 put.ExecuteNonQuery();
704 m_log.Error(
"[PROFILES_DATA]: GetAvatarProperties exception ", e);
714 string query = string.Empty;
716 query +=
"UPDATE userprofile SET ";
717 query +=
"\"profileURL\"=:profileURL, ";
718 query +=
"\"profileImage\"=:image, ";
719 query +=
"\"profileAboutText\"=:abouttext,";
720 query +=
"\"profileFirstImage\"=:firstlifeimage,";
721 query +=
"\"profileFirstText\"=:firstlifetext ";
722 query +=
"WHERE \"useruuid\"=:uuid";
726 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
729 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
731 cmd.Parameters.Add(m_database.CreateParameter(
"profileURL", props.WebUrl));
732 cmd.Parameters.Add(m_database.CreateParameter(
"image", props.ImageId));
733 cmd.Parameters.Add(m_database.CreateParameter(
"abouttext", props.AboutText));
734 cmd.Parameters.Add(m_database.CreateParameter(
"firstlifeimage", props.FirstLifeImageId));
735 cmd.Parameters.Add(m_database.CreateParameter(
"firstlifetext", props.FirstLifeText));
736 cmd.Parameters.Add(m_database.CreateParameter(
"uuid", props.UserId));
738 cmd.ExecuteNonQuery();
744 m_log.Error(
"[PROFILES_DATA]: AgentPropertiesUpdate exception ", e);
751 #endregion Avatar Properties
753 #region Avatar Interests
757 string query = string.Empty;
759 query +=
"UPDATE userprofile SET ";
760 query +=
"\"profileWantToMask\"=:WantMask, ";
761 query +=
"\"profileWantToText\"=:WantText,";
762 query +=
"\"profileSkillsMask\"=:SkillsMask,";
763 query +=
"\"profileSkillsText\"=:SkillsText, ";
764 query +=
"\"profileLanguages\"=:Languages ";
765 query +=
"WHERE \"useruuid\"=:uuid";
769 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
772 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
774 cmd.Parameters.Add(m_database.CreateParameter(
"WantMask", up.WantToMask));
775 cmd.Parameters.Add(m_database.CreateParameter(
"WantText", up.WantToText));
776 cmd.Parameters.Add(m_database.CreateParameter(
"SkillsMask", up.SkillsMask));
777 cmd.Parameters.Add(m_database.CreateParameter(
"SkillsText", up.SkillsText));
778 cmd.Parameters.Add(m_database.CreateParameter(
"Languages", up.Language));
779 cmd.Parameters.Add(m_database.CreateParameter(
"uuid", up.UserId));
781 cmd.ExecuteNonQuery();
787 m_log.Error(
"[PROFILES_DATA]: UpdateAvatarInterests exception ", e);
795 #endregion Avatar Interests
800 string query =
"SELECT \"snapshotuuid\" FROM {0} WHERE \"creatoruuid\" = :Id";
804 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
808 using (NpgsqlCommand cmd =
new NpgsqlCommand(
string.Format(query,
"\"classifieds\""), dbcon))
810 cmd.Parameters.Add(m_database.CreateParameter(
"Id", avatarId));
812 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
816 while (reader.Read())
818 data.Add(
new OSDString(reader[
"snapshotuuid"].ToString()));
827 using (NpgsqlCommand cmd =
new NpgsqlCommand(
string.Format(query,
"\"userpicks\""), dbcon))
829 cmd.Parameters.Add(m_database.CreateParameter(
"Id", avatarId));
831 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
835 while (reader.Read())
837 data.Add(
new OSDString(reader[
"snapshotuuid"].ToString()));
846 query =
"SELECT \"profileImage\", \"profileFirstImage\" FROM \"userprofile\" WHERE \"useruuid\" = :Id";
848 using (NpgsqlCommand cmd =
new NpgsqlCommand(
string.Format(query,
"\"userpicks\""), dbcon))
850 cmd.Parameters.Add(m_database.CreateParameter(
"Id", avatarId));
852 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
856 while (reader.Read())
858 data.Add(
new OSDString(reader[
"profileImage"].ToString()));
859 data.Add(
new OSDString(reader[
"profileFirstImage"].ToString()));
868 m_log.Error(
"[PROFILES_DATA]: GetUserImageAssets exception ", e);
874 #region User Preferences
878 string query = string.Empty;
880 query +=
"SELECT imviaemail::VARCHAR,visible::VARCHAR,email FROM ";
881 query +=
"usersettings WHERE ";
882 query +=
"useruuid = :Id";
888 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
891 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
893 cmd.Parameters.Add(m_database.CreateParameter(
"Id", pref.UserId));
895 using (NpgsqlDataReader reader = cmd.ExecuteReader())
900 bool.TryParse((string)reader[
"imviaemail"], out pref.IMViaEmail);
901 bool.TryParse((string)reader[
"visible"], out pref.Visible);
902 pref.EMail = (string)reader[
"email"];
906 using (NpgsqlCommand put =
new NpgsqlCommand(query, dbcon))
908 put.Parameters.Add(m_database.CreateParameter(
"Id", pref.UserId));
909 query =
"INSERT INTO usersettings VALUES ";
910 query +=
"(:Id,'false','false', '')";
912 put.ExecuteNonQuery();
921 m_log.Error(
"[PROFILES_DATA]: GetUserPreferences exception ", e);
930 string query = string.Empty;
932 query +=
"UPDATE usersettings SET ";
933 query +=
"imviaemail=:ImViaEmail, ";
934 query +=
"visible=:Visible, ";
935 query +=
"email=:Email ";
936 query +=
"WHERE useruuid=:uuid";
940 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
943 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
945 cmd.Parameters.Add(m_database.CreateParameter(
"ImViaEmail", pref.IMViaEmail));
946 cmd.Parameters.Add(m_database.CreateParameter(
"Visible", pref.Visible));
947 cmd.Parameters.Add(m_database.CreateParameter(
"EMail", pref.EMail.ToString().ToLower()));
948 cmd.Parameters.Add(m_database.CreateParameter(
"uuid", pref.UserId));
950 cmd.ExecuteNonQuery();
956 m_log.Error(
"[PROFILES_DATA]: UpdateUserPreferences exception ", e);
964 #endregion User Preferences
970 string query = string.Empty;
972 query +=
"SELECT * FROM userdata WHERE ";
973 query +=
"\"UserId\" = :Id AND ";
974 query +=
"\"TagId\" = :TagId";
978 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
981 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
983 cmd.Parameters.Add(m_database.CreateParameter(
"Id", props.UserId));
984 cmd.Parameters.Add(m_database.CreateParameter(
"TagId", props.TagId));
986 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
991 props.DataKey = (string)reader[
"DataKey"];
992 props.DataVal = (string)reader[
"DataVal"];
996 query +=
"INSERT INTO userdata VALUES ( ";
999 query +=
":DataKey,";
1000 query +=
":DataVal) ";
1002 using (NpgsqlCommand put =
new NpgsqlCommand(query, dbcon))
1004 put.Parameters.Add(m_database.CreateParameter(
"UserId", props.UserId));
1005 put.Parameters.Add(m_database.CreateParameter(
"TagId", props.TagId));
1006 put.Parameters.Add(m_database.CreateParameter(
"DataKey", props.DataKey.ToString()));
1007 put.Parameters.Add(m_database.CreateParameter(
"DataVal", props.DataVal.ToString()));
1009 put.ExecuteNonQuery();
1018 m_log.Error(
"[PROFILES_DATA]: GetUserAppData exception ", e);
1028 string query = string.Empty;
1030 query +=
"UPDATE userdata SET ";
1031 query +=
"\"TagId\" = :TagId, ";
1032 query +=
"\"DataKey\" = :DataKey, ";
1033 query +=
"\"DataVal\" = :DataVal WHERE ";
1034 query +=
"\"UserId\" = :UserId AND ";
1035 query +=
"\"TagId\" = :TagId";
1039 using (NpgsqlConnection dbcon =
new NpgsqlConnection(ConnectionString))
1042 using (NpgsqlCommand cmd =
new NpgsqlCommand(query, dbcon))
1044 cmd.Parameters.Add(m_database.CreateParameter(
"UserId", props.UserId.ToString()));
1045 cmd.Parameters.Add(m_database.CreateParameter(
"TagId", props.TagId.ToString()));
1046 cmd.Parameters.Add(m_database.CreateParameter(
"DataKey", props.DataKey.ToString()));
1047 cmd.Parameters.Add(m_database.CreateParameter(
"DataVal", props.DataKey.ToString()));
1049 cmd.ExecuteNonQuery();
1055 m_log.Error(
"[PROFILES_DATA]: SetUserData exception ", e);
1062 #endregion Integration
bool UpdatePicksRecord(UserProfilePick pick)
bool SetUserAppData(UserAppData props, ref string result)
OpenMetaverse.StructuredData.OSDArray OSDArray
bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
bool DeleteClassifiedRecord(UUID recordId)
OSDArray GetUserImageAssets(UUID avatarId)
OpenMetaverse.StructuredData.OSDMap OSDMap
bool GetAvatarNotes(ref UserProfileNotes notes)
bool GetUserAppData(ref UserAppData props, ref string result)
A management class for the MS SQL Storage Engine
static UUID GetUUID(object uuidValue)
bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
OSDArray GetAvatarPicks(UUID avatarId)
bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
bool DeletePicksRecord(UUID pickId)
bool GetUserPreferences(ref UserPreferences pref, ref string result)
UserProfilesData(string connectionString)
UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)