From d761d1624b28a9ab3b006b3a3a94f4b805550f8c Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 21 Feb 2010 04:20:22 +0000 Subject: [PATCH] Fix SQLite locking and make it more fascist for now --- OpenSim/Data/SQLite/SQLiteFramework.cs | 36 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs index 2a8a0220e4..96764f3c90 100644 --- a/OpenSim/Data/SQLite/SQLiteFramework.cs +++ b/OpenSim/Data/SQLite/SQLiteFramework.cs @@ -40,12 +40,10 @@ namespace OpenSim.Data.SQLite /// public class SQLiteFramework { - protected SqliteConnection m_Connection; + protected Object m_lockObject = new Object(); protected SQLiteFramework(string connectionString) { - //m_Connection = new SqliteConnection(connectionString); - //m_Connection.Open(); } ////////////////////////////////////////////////////////////// @@ -55,9 +53,13 @@ namespace OpenSim.Data.SQLite // protected int ExecuteNonQuery(SqliteCommand cmd) { - lock (m_Connection) + lock (m_lockObject) { - cmd.Connection = m_Connection; + SqliteConnection newConnection = + (SqliteConnection)((ICloneable)m_Connection).Clone(); + newConnection.Open(); + + cmd.Connection = newConnection; Console.WriteLine("XXX " + cmd.CommandText); return cmd.ExecuteNonQuery(); @@ -66,20 +68,26 @@ namespace OpenSim.Data.SQLite protected IDataReader ExecuteReader(SqliteCommand cmd) { - SqliteConnection newConnection = - (SqliteConnection)((ICloneable)m_Connection).Clone(); - newConnection.Open(); + lock (m_lockObject) + { + SqliteConnection newConnection = + (SqliteConnection)((ICloneable)m_Connection).Clone(); + newConnection.Open(); - cmd.Connection = newConnection; - Console.WriteLine("XXX " + cmd.CommandText); - return cmd.ExecuteReader(); + cmd.Connection = newConnection; + Console.WriteLine("XXX " + cmd.CommandText); + return cmd.ExecuteReader(); + } } protected void CloseReaderCommand(SqliteCommand cmd) { - cmd.Connection.Close(); - cmd.Connection.Dispose(); - cmd.Dispose(); + lock (m_lockObject) + { + cmd.Connection.Close(); + cmd.Connection.Dispose(); + cmd.Dispose(); + } } } }