diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index 4f977a8..917a0a1 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | |||
@@ -132,22 +132,23 @@ namespace OpenSim.Data.SQLite | |||
132 | 132 | ||
133 | List<string> terms = new List<string>(); | 133 | List<string> terms = new List<string>(); |
134 | 134 | ||
135 | SqliteCommand cmd = new SqliteCommand(); | 135 | using (SqliteCommand cmd = new SqliteCommand()) |
136 | |||
137 | for (int i = 0 ; i < fields.Length ; i++) | ||
138 | { | 136 | { |
139 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); | 137 | for (int i = 0 ; i < fields.Length ; i++) |
140 | terms.Add("`" + fields[i] + "` = :" + fields[i]); | 138 | { |
141 | } | 139 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); |
140 | terms.Add("`" + fields[i] + "` = :" + fields[i]); | ||
141 | } | ||
142 | 142 | ||
143 | string where = String.Join(" and ", terms.ToArray()); | 143 | string where = String.Join(" and ", terms.ToArray()); |
144 | 144 | ||
145 | string query = String.Format("select * from {0} where {1}", | 145 | string query = String.Format("select * from {0} where {1}", |
146 | m_Realm, where); | 146 | m_Realm, where); |
147 | 147 | ||
148 | cmd.CommandText = query; | 148 | cmd.CommandText = query; |
149 | 149 | ||
150 | return DoQuery(cmd); | 150 | return DoQuery(cmd); |
151 | } | ||
151 | } | 152 | } |
152 | 153 | ||
153 | protected T[] DoQuery(SqliteCommand cmd) | 154 | protected T[] DoQuery(SqliteCommand cmd) |
@@ -214,50 +215,52 @@ namespace OpenSim.Data.SQLite | |||
214 | 215 | ||
215 | public T[] Get(string where) | 216 | public T[] Get(string where) |
216 | { | 217 | { |
217 | SqliteCommand cmd = new SqliteCommand(); | 218 | using (SqliteCommand cmd = new SqliteCommand()) |
218 | 219 | { | |
219 | string query = String.Format("select * from {0} where {1}", | 220 | string query = String.Format("select * from {0} where {1}", |
220 | m_Realm, where); | 221 | m_Realm, where); |
221 | 222 | ||
222 | cmd.CommandText = query; | 223 | cmd.CommandText = query; |
223 | 224 | ||
224 | return DoQuery(cmd); | 225 | return DoQuery(cmd); |
226 | } | ||
225 | } | 227 | } |
226 | 228 | ||
227 | public bool Store(T row) | 229 | public bool Store(T row) |
228 | { | 230 | { |
229 | SqliteCommand cmd = new SqliteCommand(); | 231 | using (SqliteCommand cmd = new SqliteCommand()) |
230 | |||
231 | string query = ""; | ||
232 | List<String> names = new List<String>(); | ||
233 | List<String> values = new List<String>(); | ||
234 | |||
235 | foreach (FieldInfo fi in m_Fields.Values) | ||
236 | { | 232 | { |
237 | names.Add(fi.Name); | 233 | string query = ""; |
238 | values.Add(":" + fi.Name); | 234 | List<String> names = new List<String>(); |
239 | cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString())); | 235 | List<String> values = new List<String>(); |
240 | } | ||
241 | 236 | ||
242 | if (m_DataField != null) | 237 | foreach (FieldInfo fi in m_Fields.Values) |
243 | { | 238 | { |
244 | Dictionary<string, string> data = | 239 | names.Add(fi.Name); |
245 | (Dictionary<string, string>)m_DataField.GetValue(row); | 240 | values.Add(":" + fi.Name); |
241 | cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString())); | ||
242 | } | ||
246 | 243 | ||
247 | foreach (KeyValuePair<string, string> kvp in data) | 244 | if (m_DataField != null) |
248 | { | 245 | { |
249 | names.Add(kvp.Key); | 246 | Dictionary<string, string> data = |
250 | values.Add(":" + kvp.Key); | 247 | (Dictionary<string, string>)m_DataField.GetValue(row); |
251 | cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value)); | 248 | |
249 | foreach (KeyValuePair<string, string> kvp in data) | ||
250 | { | ||
251 | names.Add(kvp.Key); | ||
252 | values.Add(":" + kvp.Key); | ||
253 | cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value)); | ||
254 | } | ||
252 | } | 255 | } |
253 | } | ||
254 | 256 | ||
255 | query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")"; | 257 | query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")"; |
256 | 258 | ||
257 | cmd.CommandText = query; | 259 | cmd.CommandText = query; |
258 | 260 | ||
259 | if (ExecuteNonQuery(cmd, m_Connection) > 0) | 261 | if (ExecuteNonQuery(cmd, m_Connection) > 0) |
260 | return true; | 262 | return true; |
263 | } | ||
261 | 264 | ||
262 | return false; | 265 | return false; |
263 | } | 266 | } |
@@ -274,21 +277,22 @@ namespace OpenSim.Data.SQLite | |||
274 | 277 | ||
275 | List<string> terms = new List<string>(); | 278 | List<string> terms = new List<string>(); |
276 | 279 | ||
277 | SqliteCommand cmd = new SqliteCommand(); | 280 | using (SqliteCommand cmd = new SqliteCommand()) |
278 | |||
279 | for (int i = 0 ; i < fields.Length ; i++) | ||
280 | { | 281 | { |
281 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); | 282 | for (int i = 0 ; i < fields.Length ; i++) |
282 | terms.Add("`" + fields[i] + "` = :" + fields[i]); | 283 | { |
283 | } | 284 | cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); |
285 | terms.Add("`" + fields[i] + "` = :" + fields[i]); | ||
286 | } | ||
284 | 287 | ||
285 | string where = String.Join(" and ", terms.ToArray()); | 288 | string where = String.Join(" and ", terms.ToArray()); |
286 | 289 | ||
287 | string query = String.Format("delete from {0} where {1}", m_Realm, where); | 290 | string query = String.Format("delete from {0} where {1}", m_Realm, where); |
288 | 291 | ||
289 | cmd.CommandText = query; | 292 | cmd.CommandText = query; |
290 | 293 | ||
291 | return ExecuteNonQuery(cmd, m_Connection) > 0; | 294 | return ExecuteNonQuery(cmd, m_Connection) > 0; |
295 | } | ||
292 | } | 296 | } |
293 | } | 297 | } |
294 | } | 298 | } |