aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs56
1 files changed, 43 insertions, 13 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
index 86eaca1..4f977a8 100644
--- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
+++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
@@ -30,7 +30,11 @@ using System.Collections.Generic;
30using System.Data; 30using System.Data;
31using System.Reflection; 31using System.Reflection;
32using log4net; 32using log4net;
33using Mono.Data.Sqlite; 33#if CSharpSqlite
34 using Community.CsharpSqlite.Sqlite;
35#else
36 using Mono.Data.Sqlite;
37#endif
34using OpenMetaverse; 38using OpenMetaverse;
35using OpenSim.Framework; 39using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
@@ -48,11 +52,20 @@ namespace OpenSim.Data.SQLite
48 protected string m_Realm; 52 protected string m_Realm;
49 protected FieldInfo m_DataField = null; 53 protected FieldInfo m_DataField = null;
50 54
55 protected static SqliteConnection m_Connection;
56 private static bool m_initialized;
57
58 protected virtual Assembly Assembly
59 {
60 get { return GetType().Assembly; }
61 }
62
51 public SQLiteGenericTableHandler(string connectionString, 63 public SQLiteGenericTableHandler(string connectionString,
52 string realm, string storeName) : base(connectionString) 64 string realm, string storeName) : base(connectionString)
53 { 65 {
54 m_Realm = realm; 66 m_Realm = realm;
55 if (storeName != String.Empty) 67
68 if (!m_initialized)
56 { 69 {
57 m_Connection = new SqliteConnection(connectionString); 70 m_Connection = new SqliteConnection(connectionString);
58 //Console.WriteLine(string.Format("OPENING CONNECTION FOR {0} USING {1}", storeName, connectionString)); 71 //Console.WriteLine(string.Format("OPENING CONNECTION FOR {0} USING {1}", storeName, connectionString));
@@ -60,17 +73,18 @@ namespace OpenSim.Data.SQLite
60 73
61 if (storeName != String.Empty) 74 if (storeName != String.Empty)
62 { 75 {
63 Assembly assem = GetType().Assembly;
64 //SqliteConnection newConnection = 76 //SqliteConnection newConnection =
65 // (SqliteConnection)((ICloneable)m_Connection).Clone(); 77 // (SqliteConnection)((ICloneable)m_Connection).Clone();
66 //newConnection.Open(); 78 //newConnection.Open();
67 79
68 //Migration m = new Migration(newConnection, assem, storeName); 80 //Migration m = new Migration(newConnection, Assembly, storeName);
69 Migration m = new Migration(m_Connection, assem, storeName); 81 Migration m = new Migration(m_Connection, Assembly, storeName);
70 m.Update(); 82 m.Update();
71 //newConnection.Close(); 83 //newConnection.Close();
72 //newConnection.Dispose(); 84 //newConnection.Dispose();
73 } 85 }
86
87 m_initialized = true;
74 } 88 }
75 89
76 Type t = typeof(T); 90 Type t = typeof(T);
@@ -138,7 +152,7 @@ namespace OpenSim.Data.SQLite
138 152
139 protected T[] DoQuery(SqliteCommand cmd) 153 protected T[] DoQuery(SqliteCommand cmd)
140 { 154 {
141 IDataReader reader = ExecuteReader(cmd); 155 IDataReader reader = ExecuteReader(cmd, m_Connection);
142 if (reader == null) 156 if (reader == null)
143 return new T[0]; 157 return new T[0];
144 158
@@ -242,23 +256,39 @@ namespace OpenSim.Data.SQLite
242 256
243 cmd.CommandText = query; 257 cmd.CommandText = query;
244 258
245 if (ExecuteNonQuery(cmd) > 0) 259 if (ExecuteNonQuery(cmd, m_Connection) > 0)
246 return true; 260 return true;
247 261
248 return false; 262 return false;
249 } 263 }
250 264
251 public bool Delete(string field, string val) 265 public virtual bool Delete(string field, string key)
252 { 266 {
267 return Delete(new string[] { field }, new string[] { key });
268 }
269
270 public bool Delete(string[] fields, string[] keys)
271 {
272 if (fields.Length != keys.Length)
273 return false;
274
275 List<string> terms = new List<string>();
276
253 SqliteCommand cmd = new SqliteCommand(); 277 SqliteCommand cmd = new SqliteCommand();
254 278
255 cmd.CommandText = String.Format("delete from {0} where `{1}` = :{1}", m_Realm, field); 279 for (int i = 0 ; i < fields.Length ; i++)
256 cmd.Parameters.Add(new SqliteParameter(field, val)); 280 {
281 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i]));
282 terms.Add("`" + fields[i] + "` = :" + fields[i]);
283 }
257 284
258 if (ExecuteNonQuery(cmd) > 0) 285 string where = String.Join(" and ", terms.ToArray());
259 return true;
260 286
261 return false; 287 string query = String.Format("delete from {0} where {1}", m_Realm, where);
288
289 cmd.CommandText = query;
290
291 return ExecuteNonQuery(cmd, m_Connection) > 0;
262 } 292 }
263 } 293 }
264} 294}