[smuxi] Engine: dispose all Command instances in SqliteMessageBuffer



commit c4a42ba519089a9a5bb44a08f1cc1e2895d9274c
Author: Mirco Bauer <meebey meebey net>
Date:   Wed Feb 26 22:43:35 2014 +0100

    Engine: dispose all Command instances in SqliteMessageBuffer

 src/Engine/MessageBuffers/SqliteMessageBuffer.cs |   39 ++++++++++++----------
 1 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs 
b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
index 298ffcc..497d021 100644
--- a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
@@ -65,13 +65,14 @@ namespace Smuxi.Engine
             );
             Connection.Open();
 
-            var sql = "CREATE TABLE IF NOT EXISTS Messages (" +
-                          "ID INTEGER PRIMARY KEY," +
-                          "JSON TEXT" +
-                      ")";
-            var cmd = Connection.CreateCommand();
-            cmd.CommandText = sql;
-            cmd.ExecuteNonQuery();
+            using (var cmd = Connection.CreateCommand()) {
+                var sql = "CREATE TABLE IF NOT EXISTS Messages (" +
+                              "ID INTEGER PRIMARY KEY," +
+                              "JSON TEXT" +
+                          ")";
+                cmd.CommandText = sql;
+                cmd.ExecuteNonQuery();
+            }
         }
 
         public override void Add(MessageModel msg)
@@ -83,15 +84,16 @@ namespace Smuxi.Engine
             var dto = new MessageDtoModelV1(msg);
             var json = JsonSerializer.SerializeToString(dto);
 
-            var cmd = Connection.CreateCommand();
-            cmd.CommandText = "INSERT INTO Messages (JSON)" +
-                              " VALUES(@json)";
-            var param = cmd.CreateParameter();
-            param.ParameterName = "json";
-            param.Value = json;
-            cmd.Parameters.Add(param);
+            using (var cmd = Connection.CreateCommand()) {
+                cmd.CommandText = "INSERT INTO Messages (JSON)" +
+                                  " VALUES(@json)";
+                var param = cmd.CreateParameter();
+                param.ParameterName = "json";
+                param.Value = json;
+                cmd.Parameters.Add(param);
 
-            cmd.ExecuteNonQuery();
+                cmd.ExecuteNonQuery();
+            }
         }
 
         public override IList<MessageModel> GetRange(int offset, int limit)
@@ -124,9 +126,10 @@ namespace Smuxi.Engine
 
         public override void Clear()
         {
-            var cmd = Connection.CreateCommand();
-            cmd.CommandText = "DELETE FROM Messages";
-            cmd.ExecuteNonQuery();
+            using (var cmd = Connection.CreateCommand()) {
+                cmd.CommandText = "DELETE FROM Messages";
+                cmd.ExecuteNonQuery();
+            }
         }
 
         public override bool Contains(MessageModel item)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]