Aggiunto locking al database per evitare scritture contemporanee.
Leonardo Robol [2010-02-03 10:38]
Aggiunto locking al database per evitare scritture contemporanee.
diff --git a/GlobalConfig.cs b/GlobalConfig.cs
index 79088b1..b6566c4 100644
--- a/GlobalConfig.cs
+++ b/GlobalConfig.cs
@@ -40,18 +40,23 @@ namespace Dizzy
public void InsertValue(string field, string val)
{
- SQLiteCommand sqlCmd;
+ lock (this)
+ {
- this.conn.Open ();
- sqlCmd = this.conn.CreateCommand ();
+ SQLiteCommand sqlCmd;
- sqlCmd.CommandText = "INSERT OR REPLACE INTO config VALUES ('" + field + "', '" + val + "');";
- sqlCmd.ExecuteNonQuery ();
- this.conn.Close ();
+ this.conn.Open ();
+ sqlCmd = this.conn.CreateCommand ();
+
+ sqlCmd.CommandText = "INSERT OR REPLACE INTO config VALUES ('" + field + "', '" + val + "');";
+ sqlCmd.ExecuteNonQuery ();
+ this.conn.Close ();
+ }
}
protected void Init ()
{
+
SQLiteCommand sqlCmd;
this.conn.Open ();
sqlCmd = this.conn.CreateCommand ();
@@ -66,25 +71,29 @@ namespace Dizzy
}
else
this.conn.Close ();
- }
+
+ }
protected void InitialSetup ()
{
- // Dobbiamo creare la struttura del database
- SQLiteCommand sqlCmd;
- this.conn.Open ();
-
- // Tabelle delle configurazioni
- sqlCmd = this.conn.CreateCommand ();
- sqlCmd.CommandText = "CREATE TABLE config (field TEXT, value TEXT);";
- sqlCmd.ExecuteNonQuery ();
-
- // Tabella della lista
- sqlCmd = this.conn.CreateCommand ();
- sqlCmd.CommandText = "CREATE TABLE list (path TEXT, user TEXT);";
- sqlCmd.ExecuteNonQuery ();
-
- this.conn.Close ();
+ lock (this)
+ {
+ // Dobbiamo creare la struttura del database
+ SQLiteCommand sqlCmd;
+ this.conn.Open ();
+
+ // Tabelle delle configurazioni
+ sqlCmd = this.conn.CreateCommand ();
+ sqlCmd.CommandText = "CREATE TABLE config (field TEXT, value TEXT);";
+ sqlCmd.ExecuteNonQuery ();
+
+ // Tabella della lista
+ sqlCmd = this.conn.CreateCommand ();
+ sqlCmd.CommandText = "CREATE TABLE list (path TEXT, user TEXT);";
+ sqlCmd.ExecuteNonQuery ();
+
+ this.conn.Close ();
+ }
}
protected string DataBaseName ()