public void InsertMessage(DatabaseIncomingMessage message) { if (DatabaseProvider == DatabaseProvider.SQLServer) { MS_InsertMessage(message); } else { PG_InsertMessage(message); } }
private void MS_ConfigureInsertCommand(DatabaseIncomingMessage message, SqlCommand command) { command.Parameters.Clear(); command.Parameters.AddWithValue("Отправитель", message.Sender); command.Parameters.AddWithValue("ТипОперации", message.OperationType); command.Parameters.AddWithValue("ТипСообщения", message.MessageType); command.Parameters.AddWithValue("ТелоСообщения", message.MessageBody); command.Parameters.AddWithValue("ОписаниеОшибки", message.ErrorDescription); command.Parameters.AddWithValue("КоличествоОшибок", message.ErrorCount); if (_YearOffset > 0) { command.Parameters.AddWithValue("ДатаВремя", message.DateTimeStamp.AddYears(_YearOffset)); } else { command.Parameters.AddWithValue("ДатаВремя", message.DateTimeStamp); } }
private void MS_InsertMessage(DatabaseIncomingMessage message) { int recordsAffected = 0; using (SqlConnection connection = new SqlConnection(ConnectionString)) using (SqlCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = InsertMessageScript; command.CommandTimeout = 10; // seconds MS_ConfigureInsertCommand(message, command); connection.Open(); recordsAffected = command.ExecuteNonQuery(); } if (recordsAffected == 0) { throw new Exception("Failed to insert message into the database."); } }
private void PG_InsertMessage(DatabaseIncomingMessage message) { // TODO }