diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs index 271ed47074..7dab6bf011 100644 --- a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs +++ b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs @@ -52,12 +52,16 @@ namespace OpenSim.Data.SQLite if (!m_initialized) { + m_Connection = new SqliteConnection(connectionString); + m_Connection.Open(); + using (SqliteConnection dbcon = new SqliteConnection(m_connectionString)) { dbcon.Open(); Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore"); m.Update(); } + m_initialized = true; } } @@ -105,7 +109,7 @@ namespace OpenSim.Data.SQLite } public bool Store(AuthenticationData data) - { + { if (data.Data.ContainsKey("UUID")) data.Data.Remove("UUID"); @@ -117,31 +121,60 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = new SqliteCommand(); - string update = "update `"+m_Realm+"` set "; - bool first = true; - foreach (string field in fields) + if (Get(data.PrincipalID) != null) { - if (!first) - update += ", "; - update += "`" + field + "` = " + data.Data[field]; - first = false; + string update = "update `" + m_Realm + "` set "; + bool first = true; + foreach (string field in fields) + { + if (!first) + update += ", "; + update += "`" + field + "` = '" + data.Data[field] + "'"; + + first = false; + + } + + update += " where UUID = '" + data.PrincipalID.ToString() + "'"; + + cmd.CommandText = update; + Console.WriteLine("XXX " + cmd.CommandText); + try + { + if (ExecuteNonQuery(cmd) < 1) + { + cmd.Dispose(); + return false; + } + } + catch + { + cmd.Dispose(); + return false; + } } - update += " where UUID = '" + data.PrincipalID.ToString() + "'"; - - cmd.CommandText = update; - - if (ExecuteNonQuery(cmd) < 1) + else { string insert = "insert into `" + m_Realm + "` (`UUID`, `" + String.Join("`, `", fields) + - "`) values ('" + data.PrincipalID.ToString() + "', " + String.Join(", '", values) + "')"; + "`) values ('" + data.PrincipalID.ToString() + "', '" + String.Join("', '", values) + "')"; cmd.CommandText = insert; - if (ExecuteNonQuery(cmd) < 1) + Console.WriteLine("XXX " + cmd.CommandText); + + try + { + if (ExecuteNonQuery(cmd) < 1) + { + cmd.Dispose(); + return false; + } + } + catch { cmd.Dispose(); return false; diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs index d745c92227..2a8a0220e4 100644 --- a/OpenSim/Data/SQLite/SQLiteFramework.cs +++ b/OpenSim/Data/SQLite/SQLiteFramework.cs @@ -40,17 +40,12 @@ namespace OpenSim.Data.SQLite /// public class SQLiteFramework { - protected static SqliteConnection m_Connection; - private bool m_initialized; + protected SqliteConnection m_Connection; protected SQLiteFramework(string connectionString) { - if (!m_initialized) - { - m_Connection = new SqliteConnection(connectionString); - m_Connection.Open(); - m_initialized = true; - } + //m_Connection = new SqliteConnection(connectionString); + //m_Connection.Open(); } ////////////////////////////////////////////////////////////// @@ -63,6 +58,7 @@ namespace OpenSim.Data.SQLite lock (m_Connection) { cmd.Connection = m_Connection; + Console.WriteLine("XXX " + cmd.CommandText); return cmd.ExecuteNonQuery(); } @@ -75,6 +71,7 @@ namespace OpenSim.Data.SQLite newConnection.Open(); cmd.Connection = newConnection; + Console.WriteLine("XXX " + cmd.CommandText); return cmd.ExecuteReader(); } diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index d29efa0f5a..98943a0e8e 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs @@ -57,6 +57,9 @@ namespace OpenSim.Data.SQLite if (!m_initialized) { + m_Connection = new SqliteConnection(connectionString); + m_Connection.Open(); + if (storeName != String.Empty) { Assembly assem = GetType().Assembly; @@ -64,6 +67,7 @@ namespace OpenSim.Data.SQLite Migration m = new Migration(m_Connection, assem, storeName); m.Update(); } + m_initialized = true; } @@ -117,7 +121,7 @@ namespace OpenSim.Data.SQLite for (int i = 0 ; i < fields.Length ; i++) { cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); - terms.Add("`" + fields[i] + "` = :" + fields[i]); + terms.Add("`" + fields[i] + "`='" + keys[i] + "'"); } string where = String.Join(" and ", terms.ToArray()); @@ -215,8 +219,8 @@ namespace OpenSim.Data.SQLite foreach (FieldInfo fi in m_Fields.Values) { names.Add(fi.Name); - values.Add(":" + fi.Name); - cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString())); + values.Add(fi.GetValue(row).ToString()); + cmd.Parameters.Add(new SqliteParameter(fi.Name, fi.GetValue(row).ToString())); } if (m_DataField != null) @@ -227,12 +231,12 @@ namespace OpenSim.Data.SQLite foreach (KeyValuePair kvp in data) { names.Add(kvp.Key); - values.Add(":" + kvp.Key); - cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value)); + values.Add(kvp.Value); + cmd.Parameters.Add(new SqliteParameter(kvp.Key, kvp.Value)); } } - query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")"; + query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values ('" + String.Join("', '", values.ToArray()) + "')"; cmd.CommandText = query; diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs index f6dd085f72..9af61a922a 100644 --- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs @@ -106,12 +106,17 @@ namespace OpenSim.Services.AuthenticationService string passwordSalt = Util.Md5Hash(UUID.Random().ToString()); string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt); - AuthenticationData auth = new AuthenticationData(); - auth.PrincipalID = principalID; - auth.Data = new System.Collections.Generic.Dictionary(); + AuthenticationData auth = m_Database.Get(principalID); + if (auth == null) + { + auth = new AuthenticationData(); + auth.PrincipalID = principalID; + auth.Data = new System.Collections.Generic.Dictionary(); + auth.Data["accountType"] = "UserAccount"; + auth.Data["webLoginKey"] = UUID.Zero.ToString(); + } auth.Data["passwordHash"] = md5PasswdHash; auth.Data["passwordSalt"] = passwordSalt; - auth.Data["webLoginKey"] = UUID.Zero.ToString(); if (!m_Database.Store(auth)) { m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data");