Esempio n. 1
0
        public void Execute(IDbCommand command, IVariables variables, ILogger logger)
        {
            var valueByName = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            Action <string, string> onVariablesReplace = (name, value) =>
            {
                if (!valueByName.ContainsKey(name))
                {
                    valueByName.Add(name, value);
                }
            };

            var batches = new List <string>();

            using (var sql = ReadSqlContent())
            {
                foreach (var batch in SqlBatchParser.SplitByGo(sql))
                {
                    if (!string.IsNullOrEmpty(batch))
                    {
                        batches.Add(ApplyVariables(batch, variables, onVariablesReplace));
                    }
                }
            }

            if (valueByName.Count > 0)
            {
                foreach (var name in valueByName.Keys.OrderBy(i => i))
                {
                    var value = valueByName[name];
                    logger.Info("variable {0} was replaced with {1}".FormatWith(name, value));
                }
            }

            foreach (var batch in batches)
            {
                command.CommandText = batch;
                command.ExecuteNonQuery();
            }
        }
Esempio n. 2
0
 public void IsGo(string line, bool expected)
 {
     Assert.AreEqual(expected, SqlBatchParser.IsGo(line));
 }
Esempio n. 3
0
        public void SplitByGo(Stream input, string[] expected)
        {
            var actual = SqlBatchParser.SplitByGo(input);

            CollectionAssert.AreEqual(expected, actual);
        }