public ParsedTable(string name, Token token, string id, string crc, string dumpName, string description, string strLikeTable, ParsedTable likeTable, bool isTempTable, List <ParsedField> fields, List <ParsedIndex> indexes, List <ParsedTrigger> triggers, string useIndex) : base(name, token) { Id = id; Crc = crc; DumpName = dumpName; Description = description; IsTempTable = isTempTable; Fields = fields; Indexes = indexes; Triggers = triggers; UseIndex = useIndex; LikeTable = likeTable; StringLikeTable = strLikeTable; }
/// <summary> /// Defined Temptables /// </summary> public void Visit(ParsedTable pars) { string subStr = string.IsNullOrEmpty(pars.StringLikeTable) ? "" : (pars.LikeTable != null ? @"Like " + pars.LikeTable.Name : @"Like ??"); // to auto completion var parsedTable = new TempTableCompletionItem { DisplayText = pars.Name, Flags = pars.Flags, SubText = subStr, ChildSeparator = '.' }; parsedTable.Children = pars.Fields.Select(field => { var curField = CompletionItem.Factory.New(field.Flags.HasFlag(ParseFlag.Primary) ? CompletionType.FieldPk : CompletionType.Field); curField.DisplayText = field.Name.ConvertCase(Config.Instance.AutoCompleteDatabaseWordCaseMode); curField.ParsedBaseItem = field; curField.FromParser = true; curField.SubText = field.Type.ToString(); curField.Ranking = AutoCompletion.FindRankingOfParsedItem(field.Name); curField.Flags = field.Flags & ~ParseFlag.Primary; curField.ParentItem = parsedTable; return(curField); }).ToList(); PushToAutoCompletion(parsedTable, pars); // to code explorer PushToCodeExplorer( GetExplorerListNode("Defined temp-tables", CodeExplorerIconType.DefinedTempTable), new TempTableCodeItem { DisplayText = pars.Name, Flags = pars.Flags, SubText = subStr, DocumentOwner = pars.FilePath, GoToLine = pars.Line, GoToColumn = pars.Column }); }
/// <summary> /// Defined Temptables /// </summary> /// <param name="pars"></param> public void Visit(ParsedTable pars) { string subStr = ""; // find all primitive types foreach (var parsedField in pars.Fields) { parsedField.Type = ConvertStringToParsedPrimitiveType(parsedField.TempType, parsedField.AsLike == ParsedAsLike.Like); } // temp table is LIKE another table? copy fields if (!string.IsNullOrEmpty(pars.LcLikeTable)) { var foundTable = FindAnyTableByName(pars.LcLikeTable); if (foundTable != null) { // add the fields of the found table (minus the primary information) subStr = @"Like " + foundTable.Name; // handles the use-index, for now only add the isPrimary flag to the field... if (!string.IsNullOrEmpty(pars.UseIndex)) { foreach (var field in foundTable.Fields) { pars.Fields.Add(new ParsedField(field.Name, "", field.Format, field.Order, field.Flag.HasFlag(ParsedFieldFlag.Mandatory) ? ParsedFieldFlag.Mandatory : 0, field.InitialValue, field.Description, field.AsLike) { Type = field.Type }); } foreach (var index in pars.UseIndex.Split(',')) { // we found a primary index var foundIndex = foundTable.Indexes.Find(index2 => index2.Name.EqualsCi(index.Replace("!", ""))); // if the index is a primary if (foundIndex != null && (foundIndex.Flag.HasFlag(ParsedIndexFlag.Primary) || index.ContainsFast("!"))) { foreach (var fieldName in foundIndex.FieldsList) { // then the field is primary var foundfield = pars.Fields.Find(field => field.Name.EqualsCi(fieldName.Replace("+", "").Replace("-", ""))); if (foundfield != null) { foundfield.Flag = foundfield.Flag | ParsedFieldFlag.Primary; } } } } } else { // if there is no "use index", the tt uses the same index as the original table pars.Fields.AddRange(foundTable.Fields.ToList()); } } else { subStr = "Like ??"; } } _parsedCompletionItemsList.Add(new CompletionItem { DisplayText = pars.Name, Type = CompletionType.TempTable, SubString = subStr, Flag = AddExternalFlag(SetFlags(0, pars.LcFlagString)), Ranking = AutoComplete.FindRankingOfParsedItem(pars.Name), ParsedItem = pars, FromParser = true }); }
/// <summary> /// This method parses the output of the .p procedure that exports the database info /// and fills _dataBases /// It then updates the parser with the new info /// </summary> private static void Read(string filePath) { if (!File.Exists(filePath)) return; _dataBases.Clear(); _sequences.Clear(); var defaultToken = new TokenEos(null, 0, 0, 0, 0); ParsedDataBase currentDb = null; ParsedTable currentTable = null; Utils.ForEachLine(filePath, null, (i, items) => { var splitted = items.Split('\t'); switch (items[0]) { case 'H': // base //#H|<Dump date ISO 8601>|<Dump time>|<Logical DB name>|<Physical DB name>|<Progress version> if (splitted.Count() != 6) return; currentDb = new ParsedDataBase( splitted[3], splitted[4], splitted[5], new List<ParsedTable>()); _dataBases.Add(currentDb); break; case 'S': if (splitted.Count() != 3 || currentDb == null) return; _sequences.Add(new CompletionItem { DisplayText = splitted[1], Type = CompletionType.Sequence, SubString = currentDb.LogicalName }); break; case 'T': // table //#T|<Table name>|<Table ID>|<Table CRC>|<Dump name>|<Description> if (splitted.Count() != 6 || currentDb == null) return; currentTable = new ParsedTable( splitted[1], defaultToken, splitted[2], splitted[3], splitted[4], splitted[5], "", false, new List<ParsedField>(), new List<ParsedIndex>(), new List<ParsedTrigger>() , "", ""); currentDb.Tables.Add(currentTable); break; case 'X': // trigger //#X|<Parent table>|<Event>|<Proc name>|<Trigger CRC> if (splitted.Count() != 5 || currentTable == null) return; currentTable.Triggers.Add(new ParsedTrigger( splitted[2], splitted[3])); break; case 'I': // index //#I|<Parent table>|<Index name>|<Primary? 0/1>|<Unique? 0/1>|<Index CRC>|<Fileds separated with %> if (splitted.Count() != 7 || currentTable == null) return; var flag = splitted[3].Equals("1") ? ParsedIndexFlag.Primary : ParsedIndexFlag.None; if (splitted[4].Equals("1")) flag = flag | ParsedIndexFlag.Unique; currentTable.Indexes.Add(new ParsedIndex( splitted[2], flag, splitted[6].Split('%').ToList())); break; case 'F': // field //#F|<Parent table>|<Field name>|<Type>|<Format>|<Order #>|<Mandatory? 0/1>|<Extent? 0/1>|<Part of index? 0/1>|<Part of PK? 0/1>|<Initial value>|<Desription> if (splitted.Count() != 12 || currentTable == null) return; var flag2 = splitted[6].Equals("1") ? ParsedFieldFlag.Mandatory : ParsedFieldFlag.None; if (splitted[7].Equals("1")) flag2 = flag2 | ParsedFieldFlag.Extent; if (splitted[8].Equals("1")) flag2 = flag2 | ParsedFieldFlag.Index; if (splitted[9].Equals("1")) flag2 = flag2 | ParsedFieldFlag.Primary; var curField = new ParsedField( splitted[2], splitted[3], splitted[4], int.Parse(splitted[5]), flag2, splitted[10], splitted[11], ParsedAsLike.None); curField.Type = ParserHandler.ConvertStringToParsedPrimitiveType(curField.TempType, false); currentTable.Fields.Add(curField); break; } }); }
/// <summary> /// Returns the list of fields for a given table (it can also be a temp table!) /// </summary> /// <param name="table"></param> /// <returns></returns> public static List<CompletionItem> GetFieldsList(ParsedTable table) { var output = new List<CompletionItem>(); if (table == null) return output; output.AddRange(table.Fields.Select(field => new CompletionItem { DisplayText = field.Name, Type = (field.Flag.HasFlag(ParsedFieldFlag.Primary)) ? CompletionType.FieldPk : CompletionType.Field, FromParser = false, SubString = field.Type.ToString(), Ranking = AutoComplete.FindRankingOfDatabaseItem(field.Name), Flag = (field.Flag.HasFlag(ParsedFieldFlag.Mandatory) ? ParseFlag.Mandatory : 0) | (field.Flag.HasFlag(ParsedFieldFlag.Index) ? ParseFlag.Index : 0) | (field.Flag.HasFlag(ParsedFieldFlag.Extent) ? ParseFlag.Extent : 0), ParsedItem = table })); return output; }
public static ParsedField FindFieldByName(string name, ParsedTable table) { return table.Fields.Find(field => field.Name.EqualsCi(name)); }