diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs index c6d0e80..56611d7 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs @@ -1,3 +1,8 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.Design; +using System.Linq; + namespace SQLiteRepository { internal static class SQLiteProcedures @@ -60,6 +65,9 @@ namespace SQLiteRepository public const string GET_CARDS_BY_UNIQUE_ID = "select * from " + nameof(CardUniqueId) + " where " + nameof(CardUniqueId.CardUId) + "=?"; + public const string GET_CARDS_BY_UNIQUE_ID_LIST = + "select * from " + nameof(CardUniqueId) + " where " + nameof(CardUniqueId.CardUId) + " in (#IN#)"; + public const string GET_UNASSIGNED_CARD_LIST = "select * from " + nameof(CardUniqueId) + " where " + nameof(CardUniqueId.UserId_FK) + "=?"; @@ -112,12 +120,18 @@ namespace SQLiteRepository public const string UPDATE_GROUP = "update " + nameof(GroupDb) + " set " + nameof(GroupDb.GroupName) + "=? where " + nameof(GroupDb.GroupId) + "=?"; + public const string GET_GROUP_BY_NAME = + "select 1 from " + nameof(GroupDb)+" where "+nameof(GroupDb.GroupName)+"= ?"; + public const string GET_TIMELOG_ENTRY = "select * from " + nameof(TimeLogDb) + " where " + nameof(TimeLogDb.Id) + "=?"; public const string DELETE_TIMELOG_ENTRY = "delete from " + nameof(TimeLogDb) + " where " + nameof(TimeLogDb.Id) + "=?"; + public const string DELETE_TIMELOG_ENTRIES = + "delete from " + nameof(TimeLogDb) + " where " + nameof(TimeLogDb.Id) + "in (#IN#)"; + public const string UPDATE_TIMELOG_ENTRY = "update " + nameof(TimeLogDb) + " set " + nameof(TimeLogDb.UserId_FK) + "=?, " + nameof(TimeLogDb.Direction) + "=?," @@ -128,5 +142,25 @@ namespace SQLiteRepository + "where " + nameof(TimeLogDb.Id) + "=?"; public const string GET_DB_VERSION = "select * from DbVersion"; + + /// + /// This works on the tokenisation of the query string. + /// where the list of params is to be inserted, the query should have #IN# + /// + /// the query to add the list of parameters to + /// the parameters to add to the query. + /// + public static string FormatInQuery(string query, List args) + { + if (!query.Contains("#IN#")) + { + throw new ArgumentException("query doesnt contain any #IN# tokenisation"); + } + //Convert to a comma separated list e.g.: val1,val2,val3 + //but we need to use string.. so.. enclose in single quotes 'val1','val2'..etc + var argsFormatted = string.Join(",", args.Select(x=>$"'{x}'")); + + return query.Replace("#IN#", argsFormatted); + } } } \ No newline at end of file