private static string ScriptFragment(SqlScriptGenerator sg, TSqlFragment fragment) { string resultString; sg.GenerateScript(fragment, out resultString); return(resultString); }
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); } }
/// <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); }
public string GetSql(TSqlBatch sqlBatch) { _generator.GenerateScript(sqlBatch, out string sql); return(sql); }