move Friends list to not use ADO.NET layer, it now hits the sqlite
db directly when neededThreadPoolClientBranch
parent
13736995d2
commit
8ebaf7aa41
|
@ -45,6 +45,10 @@ namespace OpenSim.Framework.Data.SQLite
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Artificial constructor called upon plugin load
|
/// Artificial constructor called upon plugin load
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private const string SelectUserByUUID = "select * from users where UUID=:UUID";
|
||||||
|
private const string SelectUserByName = "select * from users where username=:username and surname=:surname";
|
||||||
|
private const string SelectFriendsByUUID = "select a.friendID, a.friendPerms, b.friendPerms from userfriends as a, userfriends as b where a.ownerID=:ownerID and b.ownerID=a.friendID and b.friendID=a.ownerID";
|
||||||
|
|
||||||
private const string userSelect = "select * from users";
|
private const string userSelect = "select * from users";
|
||||||
private const string userFriendsSelect = "select a.ownerID as ownerID,a.friendID as friendID,a.friendPerms as friendPerms,b.friendPerms as ownerperms, b.ownerID as fownerID, b.friendID as ffriendID from userfriends as a, userfriends as b";
|
private const string userFriendsSelect = "select a.ownerID as ownerID,a.friendID as friendID,a.friendPerms as friendPerms,b.friendPerms as ownerperms, b.ownerID as fownerID, b.friendID as ffriendID from userfriends as a, userfriends as b";
|
||||||
|
|
||||||
|
@ -142,126 +146,69 @@ namespace OpenSim.Framework.Data.SQLite
|
||||||
|
|
||||||
public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
|
public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
|
||||||
{
|
{
|
||||||
//do stuff;
|
string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
|
||||||
MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called");
|
|
||||||
DataTable friends = ds.Tables["userfriends"];
|
using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
|
||||||
DataTable ua = ds.Tables["userfriends"];
|
|
||||||
lock (ds)
|
|
||||||
{
|
{
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString()));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString()));
|
||||||
DataRow row = friends.NewRow();
|
cmd.Parameters.Add(new SqliteParameter(":perms", perms));
|
||||||
fillFriendRow(row, friendlistowner.UUID.ToString(),friend.UUID.ToString(),perms);
|
cmd.ExecuteNonQuery();
|
||||||
friends.Rows.Add(row);
|
|
||||||
|
|
||||||
row = friends.NewRow();
|
|
||||||
fillFriendRow(row, friend.UUID.ToString(), friendlistowner.UUID.ToString(), perms);
|
|
||||||
friends.Rows.Add(row);
|
|
||||||
|
|
||||||
MainLog.Instance.Verbose("SQLITE",
|
|
||||||
"Adding Friend: " + ds.Tables["userfriends"].Rows.Count + " friends stored");
|
|
||||||
// save changes off to disk
|
|
||||||
daf.Update(ds, "userfriends");
|
|
||||||
}
|
}
|
||||||
}
|
using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
|
||||||
|
|
||||||
public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
|
|
||||||
{
|
|
||||||
DataTable ua = ds.Tables["userfriends"];
|
|
||||||
string select = "`ownerID` ='" + friendlistowner.UUID.ToString() + "' and `friendID` ='" + friend.UUID.ToString() + "'";
|
|
||||||
lock (ds)
|
|
||||||
{
|
{
|
||||||
DataRow[] rows = ds.Tables["userfriends"].Select(select);
|
cmd.Parameters.Add(new SqliteParameter(":ownerID", friend.UUID.ToString()));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":friendID", friendlistowner.UUID.ToString()));
|
||||||
if ( rows != null)
|
cmd.Parameters.Add(new SqliteParameter(":perms", perms));
|
||||||
{
|
cmd.ExecuteNonQuery();
|
||||||
if (rows.Length > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < rows.Length; i++)
|
|
||||||
{
|
|
||||||
DataRow row = rows[i];
|
|
||||||
row.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
select = "`ownerID` ='" + friend.UUID.ToString() + "' and `friendID` ='" + friendlistowner.UUID.ToString() + "'";
|
|
||||||
lock (ds)
|
|
||||||
{
|
|
||||||
DataRow[] rows = ds.Tables["userfriends"].Select(select);
|
|
||||||
|
|
||||||
if (rows != null)
|
|
||||||
{
|
|
||||||
if (rows.Length > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < rows.Length; i++)
|
|
||||||
{
|
|
||||||
DataRow row = rows[i];
|
|
||||||
row.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SqliteCommand deletecommand = new SqliteCommand("delete from userfriends where `ownerID`='" + friendlistowner.UUID.ToString() + "' and `friendID` ='" + friend.UUID.ToString() + "'", g_conn);
|
|
||||||
g_conn.Open();
|
|
||||||
deletecommand.ExecuteNonQuery();
|
|
||||||
deletecommand = new SqliteCommand("delete from userfriends where `ownerID`='" + friend.UUID.ToString() + "' and `friendID` ='" + friendlistowner.UUID.ToString() + "'", g_conn);
|
|
||||||
deletecommand.ExecuteNonQuery();
|
|
||||||
g_conn.Close();
|
|
||||||
|
|
||||||
MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called");
|
|
||||||
}
|
|
||||||
public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
|
|
||||||
{
|
|
||||||
DataTable ua = ds.Tables["userfriends"];
|
|
||||||
string select = "a.ownerID ='" + friendlistowner.UUID.ToString() + "' and b.friendID ='" + friend.UUID.ToString() + "'";
|
|
||||||
lock (ds)
|
|
||||||
{
|
|
||||||
DataRow[] rows = ds.Tables["userfriends"].Select(select);
|
|
||||||
|
|
||||||
if ( rows != null)
|
|
||||||
{
|
|
||||||
if (rows.Length > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < rows.Length; i++)
|
|
||||||
{
|
|
||||||
FriendListItem user = new FriendListItem();
|
|
||||||
DataRow row = rows[i];
|
|
||||||
row["friendPerms"] = Convert.ToInt32(perms);
|
|
||||||
}
|
|
||||||
daf.Update(ds, "userfriends");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
|
||||||
|
{
|
||||||
|
string DeletePerms = "delete from friendlist where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
|
||||||
|
using (SqliteCommand cmd = new SqliteCommand(DeletePerms, g_conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString()));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString()));
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
|
||||||
|
{
|
||||||
|
string UpdatePerms = "update friendlist set perms=:perms where ownerID=:ownerID and friendID=:friendID";
|
||||||
|
using (SqliteCommand cmd = new SqliteCommand(UpdatePerms, g_conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":perms", perms));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString()));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString()));
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
|
public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
|
||||||
{
|
{
|
||||||
List<FriendListItem> returnlist = new List<FriendListItem>();
|
List<FriendListItem> returnlist = new List<FriendListItem>();
|
||||||
|
|
||||||
string select = "ownerID = '" + friendlistowner.UUID.ToString() + "' and fownerID = friendID and ffriendID = ownerID";
|
using (SqliteCommand cmd = new SqliteCommand(SelectFriendsByUUID, g_conn))
|
||||||
lock (ds)
|
|
||||||
{
|
{
|
||||||
DataRow[] rows = ds.Tables["userfriends"].Select(select);
|
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString()));
|
||||||
|
using (IDataReader reader = cmd.ExecuteReader())
|
||||||
if (rows.Length > 0)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rows.Length; i++)
|
while(reader.Read())
|
||||||
{
|
{
|
||||||
FriendListItem user = new FriendListItem();
|
FriendListItem user = new FriendListItem();
|
||||||
DataRow row = rows[i];
|
user.FriendListOwner = friendlistowner;
|
||||||
user.FriendListOwner = new LLUUID((string)row[0]);
|
user.Friend = new LLUUID((string)reader[0]);
|
||||||
user.Friend = new LLUUID((string)row[1]);
|
user.FriendPerms = Convert.ToUInt32(reader[1]);
|
||||||
user.FriendPerms = Convert.ToUInt32(row[2]);
|
user.FriendListOwnerPerms = Convert.ToUInt32(reader[2]);
|
||||||
user.FriendListOwnerPerms = Convert.ToUInt32(row[3]);
|
|
||||||
returnlist.Add(user);
|
returnlist.Add(user);
|
||||||
}
|
}
|
||||||
|
reader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnlist;
|
return returnlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue