public void AddFile(FileInfo file) { var name = file.FullName; var lastChanged = file.LastWriteTimeUtc; if (_files.ContainsKey(name)) { //do we need to clear out some old ones?? var existingScripts = _files[name]; foreach (var f in existingScripts) { IList <ParseError> err; var parsed = _parser.Parse(new StringReader("--"), out err); _model.AddOrUpdateObjects(parsed as TSqlScript, f, new TSqlObjectOptions()); } } var scripts = GetScripts(name); _caches[name] = lastChanged; var scriptList = new List <string>(); foreach (var script in scripts) { IList <ParseError> err; var parsed = _parser.Parse(new StringReader(script.Content), out err); _model.AddOrUpdateObjects(parsed as TSqlScript, script.Path, new TSqlObjectOptions()); scriptList.Add(script.Path); } _files[name] = scriptList; }
public TSqlFragment GetFragment(TextReader txtRdr, out IList <ParseError> errors, IEnumerable <IOverride> overrides = null) { TSqlFragment fragment; OverrideCompatabilityLevel compatibilityLevel = null; if (overrides != null) { foreach (var lintingOverride in overrides) { if (lintingOverride is OverrideCompatabilityLevel overrideCompatability) { compatibilityLevel = overrideCompatability; } } } if (compatibilityLevel != null) { var tempParser = GetSqlParser(compatibilityLevel.CompatabilityLevel); fragment = tempParser.Parse(txtRdr, out errors); return(fragment?.FirstTokenIndex != -1 ? fragment : null); } fragment = parser.Parse(txtRdr, out errors); return(fragment?.FirstTokenIndex != -1 ? fragment : null); }
public ParserOutput ParseString(string inputString) { TSqlScript tsqlScript; IList <ParseError> parsingErrors; using (StringReader reader = new StringReader(inputString)) { tsqlScript = (TSqlScript)_scriptParser.Parse(reader, out parsingErrors); } return(new ParserOutput() { TsqlScript = tsqlScript, ParsingErrors = parsingErrors }); }
private ScanResults AppendResults(ScanResults results, string batch, string path, int offset, int lineOffset) { var reader = new StringReader(batch); IList <ParseError> errors; var fragment = _parser.Parse(reader, out errors); var visitor = new TestVisitor(path, offset, lineOffset); fragment.Accept(visitor); results.FoundProperties.AddRange(visitor.ExtendedProperties); results.FoundClasses.AddRange(visitor.Schemas); results.FoundPotentialTests.AddRange(visitor.Procedures); return(results); }
public IList <string> SplitInBatches(string script) { using (StringReader sr = new StringReader(script)) { var fragment = _parser.Parse(sr, out IList <ParseError> errors); if (errors.Any()) { throw new System.Exception(errors.First().Message); } return(GetBatches(fragment) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList()); } }
private static TSqlFragment GetAbstractSyntaxTree(string script) { using (TextReader textReader = new StringReader(script)) { TSqlParser parser = GetTSqlParser(true); TSqlFragment rootFragment = parser.Parse(textReader, out IList <ParseError> parsingErrors); // Get the parse tree // if we could not parse the SQL we will throw an exception. Better here than on the server if (parsingErrors.Count > 0) { throw new ParameterizationParsingException(parsingErrors[0].Line, parsingErrors[0].Column, parsingErrors[0].Message); } return(rootFragment); } }
public static IEnumerable <TableInfo> FromFile(TSqlParser parser, string sqlFilePath) { using (var reader = new StreamReader(sqlFilePath)) { IList <ParseError> errors; var result = parser.Parse(reader, out errors); var script = result as TSqlScript; foreach (var ts in script.Batches) { foreach (var st in ts.Statements.OfType <CreateTableStatement>()) { yield return(new TableInfo(st)); } } } }
public static string ParseSqlString(string sqlString, out IList <ParseError> errors) { using (var sr = new StringReader(sqlString)) { var fragment = Parser.Parse(sr, out errors); if (errors.Any()) { return(string.Empty); } var sb = new StringBuilder(); using (var strStream = new StringWriter(sb)) { ScriptGen.GenerateScript(fragment, strStream); } return(sb.ToString()); } }
public TSqlFragment Parse(string input) { using var reader = new StringReader(input); var result = _parser.Parse(reader, out IList <ParseError> errors); QsiSyntaxErrorException[] syntaxErrors = errors .Select(error => new QsiSyntaxErrorException(error.Line, error.Column, error.Message)) .ToArray(); if (syntaxErrors.Length == 1) { throw syntaxErrors[0]; } if (syntaxErrors.Length > 1) { throw new AggregateException(syntaxErrors.Cast <Exception>()); } return(result); }
public TSqlFragment GetFragment(TextReader txtRdr, out IList <ParseError> errors) { var fragment = parser.Parse(txtRdr, out errors); return(fragment?.FirstTokenIndex != -1 ? fragment : null); }