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

@ -59,12 +59,14 @@ 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));
ds.Tables.Add(createUsersTable()); lock (ds) {
ds.Tables.Add(createUserAgentsTable()); ds.Tables.Add(createUsersTable());
ds.Tables.Add(createUserAgentsTable());
setupUserCommands(da, conn);
da.Fill(ds.Tables["users"]); setupUserCommands(da, conn);
da.Fill(ds.Tables["users"]);
}
return; return;
} }
@ -76,16 +78,18 @@ 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)
{ {
DataRow row = ds.Tables["users"].Rows.Find(uuid); lock (ds) {
if(row != null) { DataRow row = ds.Tables["users"].Rows.Find(uuid);
UserProfileData user = buildUserProfile(row);
row = ds.Tables["useragents"].Rows.Find(uuid);
if(row != null) { if(row != null) {
user.currentAgent = buildUserAgent(row); UserProfileData user = buildUserProfile(row);
row = ds.Tables["useragents"].Rows.Find(uuid);
if(row != null) {
user.currentAgent = buildUserAgent(row);
}
return user;
} else {
return null;
} }
return user;
} else {
return null;
} }
} }
@ -108,16 +112,18 @@ 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 + "'";
DataRow[] rows = ds.Tables["users"].Select(select); lock (ds) {
if(rows.Length > 0) { DataRow[] rows = ds.Tables["users"].Select(select);
UserProfileData user = buildUserProfile(rows[0]); if(rows.Length > 0) {
DataRow row = ds.Tables["useragents"].Rows.Find(user.UUID); UserProfileData user = buildUserProfile(rows[0]);
if(row != null) { DataRow row = ds.Tables["useragents"].Rows.Find(user.UUID);
user.currentAgent = buildUserAgent(row); if(row != null) {
user.currentAgent = buildUserAgent(row);
}
return user;
} else {
return null;
} }
return user;
} else {
return null;
} }
} }
@ -173,35 +179,37 @@ 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"];
DataRow row = users.Rows.Find(user.UUID); lock (ds) {
if (row == null) DataRow row = users.Rows.Find(user.UUID);
{
row = users.NewRow();
fillUserRow(row, user);
users.Rows.Add(row);
}
else
{
fillUserRow(row, user);
}
if(user.currentAgent != null) {
DataTable ua = ds.Tables["useragents"];
row = ua.Rows.Find(user.UUID);
if (row == null) if (row == null)
{ {
row = ua.NewRow(); row = users.NewRow();
fillUserAgentRow(row, user.currentAgent); fillUserRow(row, user);
ua.Rows.Add(row); users.Rows.Add(row);
} }
else else
{ {
fillUserAgentRow(row, user.currentAgent); fillUserRow(row, user);
} }
if(user.currentAgent != null) {
DataTable ua = ds.Tables["useragents"];
row = ua.Rows.Find(user.UUID);
if (row == null)
{
row = ua.NewRow();
fillUserAgentRow(row, user.currentAgent);
ua.Rows.Add(row);
}
else
{
fillUserAgentRow(row, user.currentAgent);
}
}
MainLog.Instance.Verbose("Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored");
// save changes off to disk
da.Update(ds, "users");
} }
MainLog.Instance.Verbose("Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored");
// save changes off to disk
da.Update(ds, "users");
} }
/// <summary> /// <summary>