[Tdbc] Fix static analysis issues (#5231)
authorjeremy-jang <35089715+jeremy-jang@users.noreply.github.com>
Tue, 2 May 2023 02:41:40 +0000 (11:41 +0900)
committerGitHub <noreply@github.com>
Tue, 2 May 2023 02:41:40 +0000 (11:41 +0900)
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Connection.cs
src/Tizen.Data.Tdbc.Driver.Sqlite/Tizen.Data.Tdbc.Driver.Sqlite/Statement.cs

index 7bcc8bd..0668970 100644 (file)
@@ -90,10 +90,12 @@ namespace Tizen.Data.Tdbc.Driver.Sqlite
             }
 
             Sql sql = new Sql(string.Format("SELECT * from {0} WHERE rowid = {1}", table_name, rowid));
-            IRecord record = CreateStatement().ExecuteQuery(sql).FirstOrDefault();
-
-            RecordChangedEventArgs ev = new RecordChangedEventArgs(operationType, db_name, table_name, record);
-            _recordChanged?.Invoke(this, ev);
+            using (IStatement stmt = CreateStatement())
+            {
+                IRecord record = stmt.ExecuteQuery(sql).FirstOrDefault();
+                RecordChangedEventArgs ev = new RecordChangedEventArgs(operationType, db_name, table_name, record);
+                _recordChanged?.Invoke(this, ev);
+            }
         }
 
         internal IntPtr GetHandle()
index 9114777..45fc530 100644 (file)
@@ -55,27 +55,31 @@ namespace Tizen.Data.Tdbc.Driver.Sqlite
                 if (pos == 0)
                     throw new InvalidOperationException("Invalid binding");
 
-                if (typeof(int) == obj.GetType())
+                // TODO: consider null binding
+                if (obj == null)
+                    continue;
+
+                Type type = obj.GetType();
+                if (typeof(int) == type)
                 {
                     Interop.Sqlite.BindInt(_stmt, pos, (int)obj);
                 }
-                else if (typeof(bool) == obj.GetType())
+                else if (typeof(bool) == type)
                 {
                     bool val = (bool)obj;
                     Interop.Sqlite.BindInt(_stmt, pos, val ? 1 : 0);
                 }
-                else if (typeof(double) == obj.GetType())
+                else if (typeof(double) == type)
                 {
                     Interop.Sqlite.BindDouble(_stmt, pos, (double)obj);
                 }
-                else if (typeof(string) == obj.GetType())
+                else if (typeof(string) == type)
                 {
                     Interop.Sqlite.BindText(_stmt, pos, (string)obj, -1, (IntPtr)(-1));
                 }
-                else if (typeof(byte[]) == obj.GetType())
+                else if (typeof(byte[]) == type)
                 {
-                    if (obj != null)
-                        Interop.Sqlite.BindData(_stmt, pos, (byte[])obj, ((byte[])obj).Length, IntPtr.Zero);
+                    Interop.Sqlite.BindData(_stmt, pos, (byte[])obj, ((byte[])obj).Length, IntPtr.Zero);
                 }
             }