add method to use SQL In queries to retrieve lists.
add queries DELETE_TIMELOG_ENTRIES and GET_CARDS_BY_UNIQUE_ID_LIST that use the IN command. this will delete all timelog entries where the ids exist in the list, or get cards in the db where the unique Id exists in the DB respectively. GET_GROUP_BY_NAME is to be used for checking whether a group already exists on create and is designed to only return one record. #95
This commit is contained in:
parent
f871c23631
commit
b329fd6e5a
@ -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";
|
||||
|
||||
/// <summary>
|
||||
/// This works on the tokenisation of the query string.
|
||||
/// where the list of params is to be inserted, the query should have #IN#
|
||||
/// </summary>
|
||||
/// <param name="query">the query to add the list of parameters to</param>
|
||||
/// <param name="args">the parameters to add to the query.</param>
|
||||
/// <returns></returns>
|
||||
public static string FormatInQuery(string query, List<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user