Exemplo n.º 1
0
        public static void GetSchema(string Database)
        {
            int StackPointer = Stack.Add($"Engines.GetSchema({Database})");

            if (string.IsNullOrEmpty(Database))//Prevents Prevents Application from querying a nonexistent db
            {
                Stack.Exit(StackPointer);
                return;
            }

            EnginesMode EngineMode = Engine_Type(Database);

            switch (EngineMode)
            {
            case EnginesMode.SQLITE:
                _Tables.Clear();
                _Views.Clear();
                _Indexes.Clear();

                QuerySettings QS = new QuerySettings
                {
                    Database     = Database,
                    SQL          = Sqlite.GetSchema(),
                    FetchRecords = true,
                    User         = Language.Localization["App"],
                    Explanation  = "SCHEMA"
                };

                Primitive Master_Schema_List = Query(QS);
                for (int i = 1; i <= Master_Schema_List.GetItemCount(); i++)
                {
                    string Name = Master_Schema_List[i]["tbl_name"];
                    switch (Master_Schema_List[i]["type"].ToString())
                    {
                    case "table":
                        _Tables.Add(Name);
                        break;

                    case "view":
                        _Views.Add(Name);
                        break;

                    case "index":
                        _Indexes.Add(Name);
                        break;
                    }
                }
                break;
            }

            try
            {
                CurrentTable = _Tables.FirstOrDefault();
            }
            catch (Exception ex)
            {
                Events.LogMessage(ex.ToString(), "System");
            }
            _TrackingDefaultTable.Add(Database + "." + CurrentTable);
            if (Database != null && CurrentTable != null)
            {
                GetColumnsofTable(Database, CurrentTable);
            }

            _Views.Sort();
            OnSchemaChange?.Invoke(null, EventArgs.Empty);
            Stack.Exit(StackPointer);
        }