public override bool ExistsChannel(string objectID, string variable) { CheckDbOpen(); ChannelEntry?entry = GetChannelDescription(objectID, variable); return(entry.HasValue); }
public override Channel GetChannel(string objectID, string variable) { CheckDbOpen(); ChannelEntry?entry = GetChannelDescription(objectID, variable); if (!entry.HasValue) { throw new ArgumentException($"No channel found with obj={objectID} avr={variable}"); } return(new PostgresFlatChannel(connection !, entry.Value.MakeInfo(), entry.Value.VarID, $"{objectID}.{variable}")); }
public Channel[] DoCreateChannels(Span <ChannelInfo> channels) { using (var transaction = connection !.BeginTransaction()) { try { var res = new List <Channel>(); foreach (ChannelInfo ch in channels) { using (var command = Factory.MakeCommand("INSERT INTO channel_defs VALUES (@obj, @var, @type)", connection)) { command.Transaction = transaction; command.Parameters.Add(Factory.MakeParameter("obj", ch.Object)); command.Parameters.Add(Factory.MakeParameter("var", ch.Variable)); command.Parameters.Add(Factory.MakeParameter("type", ch.Type.ToString())); command.ExecuteNonQuery(); } ChannelEntry?entry = GetChannelDescription(ch.Object, ch.Variable); if (!entry.HasValue) { throw new Exception($"Failed to create channel entry for {ch.Object}.{ch.Variable}"); } var channel = new PostgresFlatChannel(connection, ch, entry.Value.VarID, $"{ch.Object}.{ch.Variable}"); res.Add(channel); } transaction.Commit(); return(res.ToArray()); } catch (Exception) { try { transaction.Rollback(); } catch (Exception exp) { logger.Warn("DoCreateChannels: transaction.Rollback failed: " + exp.Message); } throw; } } }
public override bool RemoveChannel(string objectID, string variable) { CheckDbOpen(); ChannelEntry?entry = GetChannelDescription(objectID, variable); if (!entry.HasValue) { return(false); } string table = entry.Value.DataTableName; using (var command = Factory.MakeCommand($"DROP TABLE \"{table}\"", connection)) { command.ExecuteNonQuery(); } using (var command = Factory.MakeCommand($"DELETE FROM channel_defs WHERE obj = @obj AND var = @var", connection)) { command.Parameters.Add(Factory.MakeParameter("obj", objectID)); command.Parameters.Add(Factory.MakeParameter("var", variable)); command.ExecuteNonQuery(); } return(true); }
public override bool RemoveChannel(string objectID, string variable) { CheckDbOpen(); ChannelEntry?entry = GetChannelDescription(objectID, variable); if (!entry.HasValue) { return(false); } var ch = (PostgresFlatChannel)GetChannel(objectID, variable); ch.DeleteAll(); using (var command = Factory.MakeCommand($"DELETE FROM channel_defs WHERE obj = @obj AND var = @var", connection !)) { command.Parameters.Add(Factory.MakeParameter("obj", objectID)); command.Parameters.Add(Factory.MakeParameter("var", variable)); command.ExecuteNonQuery(); } cacheChannelEntry.Clear(); return(true); }