Esempio n. 1
0
        public string UpdateParamsWithValues(string originalSql)
        {
            string[] parts = originalSql.Replace("N'", "'").Replace("''", "'").Split(';');
            if (parts.Length <= 1)
                return originalSql;

            string sql = String.Join(";", parts.Take(parts.Length - 1).ToArray());
            string paramList = parts.Last();

            var parameters = new Dictionary<string, string>();
            ITokenizer tokenizer = new SqlTokenizer(paramList);
            tokenizer.ReadNextToken();
            do
            {
                string parameter = tokenizer.Current.Value;

                tokenizer.ReadNextToken();
                tokenizer.ExpectToken(Constants.Assignment);

                parameters.Add(parameter, ProcessParameter(tokenizer, parameter));
            }
            while (tokenizer.TokenEquals(Constants.Comma));

            foreach (var item in parameters.Reverse())
                sql = sql.Replace(item.Key, item.Value);

            return sql;
        }