Beispiel #1
0
        private static string ScriptFragment(SqlScriptGenerator sg, TSqlFragment fragment)
        {
            string resultString;

            sg.GenerateScript(fragment, out resultString);
            return(resultString);
        }
Beispiel #2
0
 private IEnumerable <string> GetBatches(TSqlFragment fragment)
 {
     if (fragment is TSqlScript script)
     {
         foreach (var batch in script.Batches)
         {
             _sqlScriptGenerator.GenerateScript(batch, out string batchScript);
             yield return(batchScript);
         }
     }
     else
     {
         _sqlScriptGenerator.GenerateScript(fragment, out string fragmentScript);
         yield return(fragmentScript);
     }
 }
Beispiel #3
0
        /// <summary>
        /// This method will parameterize the given SqlCommand.
        /// Any single literal on the RHS of a declare statement will be parameterized
        /// Any other literals will be ignored
        /// </summary>
        /// <param name="commandToParameterize">Command that will need to be parameterized</param>
        public static void Parameterize(this DbCommand commandToParameterize)
        {
            TSqlFragment     rootFragment = GetAbstractSyntaxTree(commandToParameterize);
            TsqlMultiVisitor multiVisitor = new TsqlMultiVisitor(isCodeSenseRequest: false); // Use the vistor pattern to examine the parse tree

            rootFragment.AcceptChildren(multiVisitor);                                       // Now walk the tree

            //reformat and validate the transformed command
            SqlScriptGenerator scriptGenerator = GetScriptGenerator();

            scriptGenerator.GenerateScript(rootFragment, out string formattedSQL);

            if (!string.IsNullOrEmpty(formattedSQL))
            {
                commandToParameterize.CommandText = formattedSQL;
            }

            commandToParameterize.Parameters.AddRange(multiVisitor.Parameters.ToArray());

            multiVisitor.Reset();
        }
 public void WriteBatch(TSqlBatch batch)
 {
     _generator.GenerateScript(batch, _writer);
 }
Beispiel #5
0
 public string GetSql(TSqlBatch sqlBatch)
 {
     _generator.GenerateScript(sqlBatch, out string sql);
     return(sql);
 }