public bool OpenConnection() { if (_connObj == null) { throw new InvalidOperationException("Cannot open connection before connecting to the Database. Please use the ConnectAsync function first."); } try { Connection connection = new Connection { connectionObject = _connObj, }; DatabaseConnection.connection = connection; sql = new SQLProcessor(connection); return(true); } catch (Exception exception) { return(false); throw exception; } }
public async Task DisableCommand(ulong guildID, string cmdName) { SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection); if (CommandDisabled(cmdName)) { return; } await sql.ExecuteQueryAsync($"INSERT INTO blacklistedcommands (guildID, command) VALUES ({guildID}, '{cmdName}')"); }
public async Task ChangePrefix(string prefix) { SQLProcessor processor = new SQLProcessor(DatabaseConnection.connection); if (CheckIfRegisteredAsync(_guildId)) { await UpdateGuildPrefix(_guildId, prefix); } else { await InsertGuildPrefix(_guildId, prefix); } }
private bool CheckIfRegisteredAsync(ulong guildID) { var connection = DatabaseConnection.connection; SQLProcessor processor = new SQLProcessor(connection); connection.connectionObject.Open(); using (SqliteTransaction transaction = connection.connectionObject.BeginTransaction()) { var selectCommand = connection.connectionObject.CreateCommand(); selectCommand.Transaction = transaction; selectCommand.CommandText = $"SELECT guildID FROM guildprefix WHERE guildID={guildID}"; var reader = selectCommand.ExecuteReader(); string msg = ""; while (reader.Read()) { msg = reader.GetString(0); } transaction.Commit(); connection.connectionObject.Close(); transaction.Dispose(); bool x = false; try { ulong id = ulong.Parse(msg); if (id == guildID) { x = true; } } catch { x = false; } return(x); } }
private async Task UpdateGuildPrefix(ulong guildId, string newPrefix) { SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection); await sql.ExecuteQueryAsync($"UPDATE guildprefix SET prefix='{newPrefix}' WHERE guildID={guildId}"); }
private async Task InsertGuildPrefix(ulong guildId, string newPrefix) { SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection); await sql.ExecuteQueryAsync($"INSERT INTO guildprefix (guildID, prefix) VALUES ({guildId}, '{newPrefix}')"); }
public async Task EnableCommand(ulong guildID, string cmdName) { SQLProcessor sql = new SQLProcessor(DatabaseConnection.connection); await sql.ExecuteQueryAsync($"DELETE FROM blacklistedcommands WHERE guildID={guildID} and command='{cmdName}'"); }