put some locking around user access, which should help with

the exception dalien found during crash-a-thon
afrisby
Sean Dague 2007-09-15 10:43:19 +00:00
parent 4a07800f14
commit b931048b16
1 changed files with 53 additions and 45 deletions

View File

@ -60,11 +60,13 @@ namespace OpenSim.Framework.Data.SQLite
ds = new DataSet(); ds = new DataSet();
da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn)); da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn));
lock (ds) {
ds.Tables.Add(createUsersTable()); ds.Tables.Add(createUsersTable());
ds.Tables.Add(createUserAgentsTable()); ds.Tables.Add(createUserAgentsTable());
setupUserCommands(da, conn); setupUserCommands(da, conn);
da.Fill(ds.Tables["users"]); da.Fill(ds.Tables["users"]);
}
return; return;
} }
@ -76,6 +78,7 @@ namespace OpenSim.Framework.Data.SQLite
/// <returns>A user profile</returns> /// <returns>A user profile</returns>
public UserProfileData getUserByUUID(LLUUID uuid) public UserProfileData getUserByUUID(LLUUID uuid)
{ {
lock (ds) {
DataRow row = ds.Tables["users"].Rows.Find(uuid); DataRow row = ds.Tables["users"].Rows.Find(uuid);
if(row != null) { if(row != null) {
UserProfileData user = buildUserProfile(row); UserProfileData user = buildUserProfile(row);
@ -88,6 +91,7 @@ namespace OpenSim.Framework.Data.SQLite
return null; return null;
} }
} }
}
/// <summary> /// <summary>
/// Returns a user by searching for its name /// Returns a user by searching for its name
@ -108,6 +112,7 @@ namespace OpenSim.Framework.Data.SQLite
public UserProfileData getUserByName(string fname, string lname) public UserProfileData getUserByName(string fname, string lname)
{ {
string select = "surname = '" + lname + "' and username = '" + fname + "'"; string select = "surname = '" + lname + "' and username = '" + fname + "'";
lock (ds) {
DataRow[] rows = ds.Tables["users"].Select(select); DataRow[] rows = ds.Tables["users"].Select(select);
if(rows.Length > 0) { if(rows.Length > 0) {
UserProfileData user = buildUserProfile(rows[0]); UserProfileData user = buildUserProfile(rows[0]);
@ -120,6 +125,7 @@ namespace OpenSim.Framework.Data.SQLite
return null; return null;
} }
} }
}
/// <summary> /// <summary>
/// Returns a user by UUID direct /// Returns a user by UUID direct
@ -173,6 +179,7 @@ namespace OpenSim.Framework.Data.SQLite
public void addNewUserProfile(UserProfileData user) public void addNewUserProfile(UserProfileData user)
{ {
DataTable users = ds.Tables["users"]; DataTable users = ds.Tables["users"];
lock (ds) {
DataRow row = users.Rows.Find(user.UUID); DataRow row = users.Rows.Find(user.UUID);
if (row == null) if (row == null)
{ {
@ -203,6 +210,7 @@ namespace OpenSim.Framework.Data.SQLite
// save changes off to disk // save changes off to disk
da.Update(ds, "users"); da.Update(ds, "users");
} }
}
/// <summary> /// <summary>
/// Creates a new user profile /// Creates a new user profile