SQLite connector better, but access to tables still doesn't work.

slimupdates
Diva Canto 2010-02-20 20:13:38 -08:00
parent 0ab6aac052
commit df59d098b3
4 changed files with 72 additions and 33 deletions

View File

@ -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;

View File

@ -40,17 +40,12 @@ namespace OpenSim.Data.SQLite
/// </summary>
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();
}

View File

@ -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<string, string> 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;

View File

@ -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<string, object>();
AuthenticationData auth = m_Database.Get(principalID);
if (auth == null)
{
auth = new AuthenticationData();
auth.PrincipalID = principalID;
auth.Data = new System.Collections.Generic.Dictionary<string, object>();
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");