private static void PrintColumnNames(ParseTreeNode rootNode, ExecutionPlanOptions executionPlanOptions) { if(string.Equals(ID3SQLGrammar.SelectStatementNonTermName, rootNode.Term.Name)) { ParseTreeNode selectListNode = rootNode.ChildNodes[1]; ParseTreeNode topNode = selectListNode.ChildNodes[0]; if (topNode.Token != null && string.Equals(topNode.Token.Text, "*")) { string[] allGetFunctionPropertyNames = TagFunctionManager.AllGetFunctionPropertyNames().ToArray(); string columnNameLine = string.Join(executionPlanOptions.ColumnSeparator, allGetFunctionPropertyNames); Console.WriteLine(columnNameLine); } else if (topNode.ChildNodes.Count > 0) { IEnumerable<string> allGetFunctionPropertyNames = TagFunctionManager.AllGetFunctionPropertyNames(); ICollection<string> propertyNames = new List<string>(); foreach (ParseTreeNode idNode in topNode.ChildNodes) { string propertyName = idNode.Token.Text; if (allGetFunctionPropertyNames.Contains(propertyName)) { propertyNames.Add(propertyName); } else { throw new ID3SQLException("Unknown property name in select list"); } } string columnNameLine = string.Join(executionPlanOptions.ColumnSeparator, propertyNames); Console.WriteLine(columnNameLine); } else { throw new Exception("Unknown select non-term"); } } }
private static string[] ValueToStringArray(object value, ExecutionPlanOptions executionPlanOptions) { if (value is IEnumerable<string>) { return (value as IEnumerable<string>).ToArray(); } else if (value is string) { return (value as string).Split(executionPlanOptions.StringArraySeparator); } else { throw new ID3SQLException(string.Format("Invalid Assignment: {0}", value)); } }
public static void Main(string[] args) { CommandLineOptions options = new CommandLineOptions(); try { if (CommandLine.Parser.Default.ParseArguments(args, options)) { Regex fileRegex; try { fileRegex = new Regex(options.FileRegex ?? DefaultFileRegex()); } catch(Exception ex) { throw new ID3SQLException("Error parsing fileRegex", ex); } string startDirectory = options.Directory ?? DefaultDirectoryPath(); string statement = options.Statement; if(statement == null) { throw new ID3SQLException("No SQL statement supplied"); } Action<IEnumerable<string>, ExecutionPlanOptions> executionPlan = ExecutionPlan.GenerateExecutionPlan(statement); ICollection<string> tagFilePaths = new List<string>(); try { BuildFileList(startDirectory, tagFilePaths, fileRegex); } catch(Exception ex) { throw new ID3SQLException(string.Format("Error building file list from start directory '{0}'", startDirectory), ex); } ExecutionPlanOptions executionPlanOptions = new ExecutionPlanOptions() { Recycle = options.Recycle, DryRun = options.DryRun, Verbose = options.Verbose, StringArraySeparator = options.StringLiteralSeparator, RegexIgnoreCase = options.RegexIgnoreCase, ColumnNames = options.ColumnNames, ColumnSeparator = options.ColumnSeparator }; executionPlan(tagFilePaths, executionPlanOptions); } } catch(ID3SQLException ex) { Console.Error.WriteLine(ex.Message); if(options.Verbose) { Console.Error.Write(ex); } } catch(Exception ex) { Console.Error.WriteLine("Unknown error has occured"); if(options.Verbose) { Console.Error.WriteLine(ex); } } }