diff --git a/ChaosBot/Database/Controller.cs b/ChaosBot/Database/Controller.cs index 43ad76a..47f9e83 100644 --- a/ChaosBot/Database/Controller.cs +++ b/ChaosBot/Database/Controller.cs @@ -122,11 +122,11 @@ namespace ChaosBot.Database string order = null; if (orderByKey != null) { - order = $"ORDER BY ${orderByKey}"; + order = $"ORDER BY {orderByKey}"; } string query = $"SELECT {selectColumns} FROM {table} {filter} {order}"; - + cmd.CommandText = query; cmd.Prepare(); SqliteDataReader executeReader = cmd.ExecuteReader(); diff --git a/ChaosBot/Database/Repository/RaffleRepository.cs b/ChaosBot/Database/Repository/RaffleRepository.cs index b8a23f4..ed6d2da 100644 --- a/ChaosBot/Database/Repository/RaffleRepository.cs +++ b/ChaosBot/Database/Repository/RaffleRepository.cs @@ -65,6 +65,17 @@ namespace ChaosBot.Database.Repository } } + public static Raffle PickRandom() + { + DataTable dataTable = Controller.SelectQuery(Table, "*", orderByKey: "RANDOM()"); + + if (dataTable.Rows.Count == 0) return null; + DataRow row = dataTable.Rows[0]; + int idFetch = Convert.ToInt32((long)row["id"]); + string userIdFetch = row["userId"].ToString(); + return new Raffle(idFetch, userIdFetch); + } + // public static void delete() // { //