Exemple #1
0
        /// <summary>
        /// Search through the available completionData to find the primitive type of a
        /// "like xx" phrase
        /// </summary>
        /// <param name="likeStr"></param>
        /// <returns></returns>
        private ParsedPrimitiveType FindPrimitiveTypeOfLike(string likeStr)
        {
            // determines the format
            var nbPoints = likeStr.CountOccurences(".");
            var splitted = likeStr.Split('.');

            // if it's another var
            if (nbPoints == 0)
            {
                var foundVar = _parsedCompletionItemsList.Find(data =>
                                                               (data.Type == CompletionType.VariablePrimitive ||
                                                                data.Type == CompletionType.VariableComplex) && data.DisplayText.EqualsCi(likeStr));
                return(foundVar != null ? ((ParsedDefine)foundVar.ParsedItem).PrimitiveType : ParsedPrimitiveType.Unknow);
            }

            var tableName = splitted[nbPoints == 2 ? 1 : 0];
            var fieldName = splitted[nbPoints == 2 ? 2 : 1];

            // Search through database
            if (DataBase.List.Count > 0)
            {
                ParsedDataBase foundDb = DataBase.List.First();
                if (nbPoints == 2)
                {
                    // find database
                    foundDb = DataBase.FindDatabaseByName(splitted[0]) ?? DataBase.List.First();
                }
                if (foundDb == null)
                {
                    return(ParsedPrimitiveType.Unknow);
                }

                // find table
                var foundTable = DataBase.FindTableByName(tableName, foundDb);
                if (foundTable != null)
                {
                    // find field
                    var foundField = DataBase.FindFieldByName(fieldName, foundTable);
                    if (foundField != null)
                    {
                        return(foundField.Type);
                    }
                }
            }

            // Search in temp tables
            if (nbPoints != 1)
            {
                return(ParsedPrimitiveType.Unknow);
            }
            var foundTtable = FindAnyTableOrBufferByName(tableName);

            if (foundTtable == null)
            {
                return(ParsedPrimitiveType.Unknow);
            }

            var foundTtField = foundTtable.Fields.Find(field => field.Name.EqualsCi(fieldName));

            return(foundTtField == null ? ParsedPrimitiveType.Unknow : foundTtField.Type);
        }
Exemple #2
0
 /// <summary>
 /// Returns the list of tables for a given database
 /// </summary>
 /// <param name="dataBase"></param>
 /// <returns></returns>
 public static List<CompletionItem> GetTablesList(ParsedDataBase dataBase)
 {
     var output = new List<CompletionItem>();
     if (dataBase == null || dataBase.Tables == null || dataBase.Tables.Count == 0) return output;
     output.AddRange(dataBase.Tables.Select(table => new CompletionItem {
         DisplayText = table.Name,
         SubString = dataBase.LogicalName,
         Type = CompletionType.Table,
         FromParser = false,
         Ranking = AutoComplete.FindRankingOfDatabaseItem(table.Name),
         Flag = 0
     }).ToList());
     return output;
 }
Exemple #3
0
        /// <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;
                }
            });
        }
Exemple #4
0
 public static ParsedTable FindTableByName(string name, ParsedDataBase db)
 {
     return db.Tables.Find(table => table.Name.EqualsCi(name));
 }