diff options
author | Sean Dague | 2008-01-10 21:32:22 +0000 |
---|---|---|
committer | Sean Dague | 2008-01-10 21:32:22 +0000 |
commit | 8ebaf7aa416ca86a881dc15f2154c59354f1f7e9 (patch) | |
tree | ab0a877943c8066e143701fa31c8c5cc0892990e /OpenSim | |
parent | add sqlite database definitions as Resources for SQLite.dll (diff) | |
download | opensim-SC_OLD-8ebaf7aa416ca86a881dc15f2154c59354f1f7e9.zip opensim-SC_OLD-8ebaf7aa416ca86a881dc15f2154c59354f1f7e9.tar.gz opensim-SC_OLD-8ebaf7aa416ca86a881dc15f2154c59354f1f7e9.tar.bz2 opensim-SC_OLD-8ebaf7aa416ca86a881dc15f2154c59354f1f7e9.tar.xz |
move Friends list to not use ADO.NET layer, it now hits the sqlite
db directly when needed
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteUserData.cs | 139 |
1 files changed, 43 insertions, 96 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs index f1f76c4..9a4a6e7 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs | |||
@@ -45,6 +45,10 @@ namespace OpenSim.Framework.Data.SQLite | |||
45 | /// <summary> | 45 | /// <summary> |
46 | /// Artificial constructor called upon plugin load | 46 | /// Artificial constructor called upon plugin load |
47 | /// </summary> | 47 | /// </summary> |
48 | private const string SelectUserByUUID = "select * from users where UUID=:UUID"; | ||
49 | private const string SelectUserByName = "select * from users where username=:username and surname=:surname"; | ||
50 | 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"; | ||
51 | |||
48 | private const string userSelect = "select * from users"; | 52 | private const string userSelect = "select * from users"; |
49 | 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"; | 53 | 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"; |
50 | 54 | ||
@@ -142,126 +146,69 @@ namespace OpenSim.Framework.Data.SQLite | |||
142 | 146 | ||
143 | public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | 147 | public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) |
144 | { | 148 | { |
145 | //do stuff; | 149 | string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)"; |
146 | MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called"); | 150 | |
147 | DataTable friends = ds.Tables["userfriends"]; | 151 | using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn)) |
148 | DataTable ua = ds.Tables["userfriends"]; | ||
149 | lock (ds) | ||
150 | { | 152 | { |
151 | 153 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString())); | |
152 | 154 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString())); | |
153 | DataRow row = friends.NewRow(); | 155 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); |
154 | fillFriendRow(row, friendlistowner.UUID.ToString(),friend.UUID.ToString(),perms); | 156 | cmd.ExecuteNonQuery(); |
155 | friends.Rows.Add(row); | 157 | } |
156 | 158 | using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn)) | |
157 | row = friends.NewRow(); | 159 | { |
158 | fillFriendRow(row, friend.UUID.ToString(), friendlistowner.UUID.ToString(), perms); | 160 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friend.UUID.ToString())); |
159 | friends.Rows.Add(row); | 161 | cmd.Parameters.Add(new SqliteParameter(":friendID", friendlistowner.UUID.ToString())); |
160 | 162 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); | |
161 | MainLog.Instance.Verbose("SQLITE", | 163 | cmd.ExecuteNonQuery(); |
162 | "Adding Friend: " + ds.Tables["userfriends"].Rows.Count + " friends stored"); | ||
163 | // save changes off to disk | ||
164 | daf.Update(ds, "userfriends"); | ||
165 | } | 164 | } |
166 | } | 165 | } |
167 | 166 | ||
168 | public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | 167 | public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) |
169 | { | 168 | { |
170 | DataTable ua = ds.Tables["userfriends"]; | 169 | string DeletePerms = "delete from friendlist where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)"; |
171 | string select = "`ownerID` ='" + friendlistowner.UUID.ToString() + "' and `friendID` ='" + friend.UUID.ToString() + "'"; | 170 | using (SqliteCommand cmd = new SqliteCommand(DeletePerms, g_conn)) |
172 | lock (ds) | ||
173 | { | 171 | { |
174 | DataRow[] rows = ds.Tables["userfriends"].Select(select); | 172 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString())); |
175 | 173 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString())); | |
176 | if ( rows != null) | 174 | cmd.ExecuteNonQuery(); |
177 | { | ||
178 | if (rows.Length > 0) | ||
179 | { | ||
180 | for (int i = 0; i < rows.Length; i++) | ||
181 | { | ||
182 | DataRow row = rows[i]; | ||
183 | row.Delete(); | ||
184 | } | ||
185 | |||
186 | } | ||
187 | } | ||
188 | } | ||
189 | select = "`ownerID` ='" + friend.UUID.ToString() + "' and `friendID` ='" + friendlistowner.UUID.ToString() + "'"; | ||
190 | lock (ds) | ||
191 | { | ||
192 | DataRow[] rows = ds.Tables["userfriends"].Select(select); | ||
193 | |||
194 | if (rows != null) | ||
195 | { | ||
196 | if (rows.Length > 0) | ||
197 | { | ||
198 | for (int i = 0; i < rows.Length; i++) | ||
199 | { | ||
200 | DataRow row = rows[i]; | ||
201 | row.Delete(); | ||
202 | } | ||
203 | |||
204 | } | ||
205 | } | ||
206 | } | 175 | } |
207 | SqliteCommand deletecommand = new SqliteCommand("delete from userfriends where `ownerID`='" + friendlistowner.UUID.ToString() + "' and `friendID` ='" + friend.UUID.ToString() + "'", g_conn); | ||
208 | g_conn.Open(); | ||
209 | deletecommand.ExecuteNonQuery(); | ||
210 | deletecommand = new SqliteCommand("delete from userfriends where `ownerID`='" + friend.UUID.ToString() + "' and `friendID` ='" + friendlistowner.UUID.ToString() + "'", g_conn); | ||
211 | deletecommand.ExecuteNonQuery(); | ||
212 | g_conn.Close(); | ||
213 | |||
214 | MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called"); | ||
215 | } | 176 | } |
177 | |||
216 | public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | 178 | public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) |
217 | { | 179 | { |
218 | DataTable ua = ds.Tables["userfriends"]; | 180 | string UpdatePerms = "update friendlist set perms=:perms where ownerID=:ownerID and friendID=:friendID"; |
219 | string select = "a.ownerID ='" + friendlistowner.UUID.ToString() + "' and b.friendID ='" + friend.UUID.ToString() + "'"; | 181 | using (SqliteCommand cmd = new SqliteCommand(UpdatePerms, g_conn)) |
220 | lock (ds) | ||
221 | { | 182 | { |
222 | DataRow[] rows = ds.Tables["userfriends"].Select(select); | 183 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); |
223 | 184 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString())); | |
224 | if ( rows != null) | 185 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.UUID.ToString())); |
225 | { | 186 | cmd.ExecuteNonQuery(); |
226 | if (rows.Length > 0) | ||
227 | { | ||
228 | for (int i = 0; i < rows.Length; i++) | ||
229 | { | ||
230 | FriendListItem user = new FriendListItem(); | ||
231 | DataRow row = rows[i]; | ||
232 | row["friendPerms"] = Convert.ToInt32(perms); | ||
233 | } | ||
234 | daf.Update(ds, "userfriends"); | ||
235 | } | ||
236 | } | ||
237 | } | 187 | } |
238 | MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called"); | ||
239 | } | 188 | } |
240 | |||
241 | 189 | ||
242 | public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) | 190 | public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) |
243 | { | 191 | { |
244 | List<FriendListItem> returnlist = new List<FriendListItem>(); | 192 | List<FriendListItem> returnlist = new List<FriendListItem>(); |
245 | 193 | ||
246 | string select = "ownerID = '" + friendlistowner.UUID.ToString() + "' and fownerID = friendID and ffriendID = ownerID"; | 194 | using (SqliteCommand cmd = new SqliteCommand(SelectFriendsByUUID, g_conn)) |
247 | lock (ds) | ||
248 | { | 195 | { |
249 | DataRow[] rows = ds.Tables["userfriends"].Select(select); | 196 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.UUID.ToString())); |
250 | 197 | using (IDataReader reader = cmd.ExecuteReader()) | |
251 | if (rows.Length > 0) | ||
252 | { | 198 | { |
253 | for (int i = 0; i < rows.Length; i++) | 199 | while(reader.Read()) |
254 | { | 200 | { |
255 | FriendListItem user = new FriendListItem(); | 201 | FriendListItem user = new FriendListItem(); |
256 | DataRow row = rows[i]; | 202 | user.FriendListOwner = friendlistowner; |
257 | user.FriendListOwner = new LLUUID((string)row[0]); | 203 | user.Friend = new LLUUID((string)reader[0]); |
258 | user.Friend = new LLUUID((string)row[1]); | 204 | user.FriendPerms = Convert.ToUInt32(reader[1]); |
259 | user.FriendPerms = Convert.ToUInt32(row[2]); | 205 | user.FriendListOwnerPerms = Convert.ToUInt32(reader[2]); |
260 | user.FriendListOwnerPerms = Convert.ToUInt32(row[3]); | ||
261 | returnlist.Add(user); | 206 | returnlist.Add(user); |
262 | } | 207 | } |
208 | reader.Close(); | ||
263 | } | 209 | } |
264 | } | 210 | } |
211 | |||
265 | return returnlist; | 212 | return returnlist; |
266 | } | 213 | } |
267 | 214 | ||