Пример #1
0
        public TreeNode[] GetObjectHierarchy()
        {
            TreeNode[] top = new TreeNode[]
            {
                new TreeNode("User Tables"),
                new TreeNode("User Views"),
            };

            DataSet ds = dbClient.Execute("select TABLE_NAME from USER_TABLES", timeout);

            if (ds == null || ds.Tables.Count == 0)
            {
                return(null);
            }

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                OracleNode node = new OracleNode(row [0].ToString());
                node.type     = "T";
                node.dragText = node.Text;
                top [0].Nodes.Add(node);
                // Add a dummy sub-node to user tables and views so they'll have a clickable expand sign
                // allowing us to have GetSubObjectHierarchy called so the user can view the columns
                node.Nodes.Add(new TreeNode());
            }

            ds = dbClient.Execute("select VIEW_NAME from USER_VIEWS", timeout);
            if (ds == null || ds.Tables.Count == 0)
            {
                return(top);
            }

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                OracleNode node = new OracleNode(row [0].ToString());
                node.type     = "V";
                node.dragText = node.Text;
                top [1].Nodes.Add(node);
                // Add a dummy sub-node to user tables and views so they'll have a clickable expand sign
                // allowing us to have GetSubObjectHierarchy called so the user can view the columns
                node.Nodes.Add(new TreeNode());
            }

            return(top);
        }
Пример #2
0
        public TreeNode[] GetObjectHierarchy()
        {
            TreeNode[] top = new TreeNode[]
            {
                new TreeNode("User Tables"),
                new TreeNode("System Tables"),
                new TreeNode("Views"),
                new TreeNode("User Stored Procs"),
                new TreeNode("MS Stored Procs"),
                new TreeNode("Functions")
            };

            DataSet ds = dbClient.Execute("select type, ObjectProperty (id, N'IsMSShipped') shipped, object_name(id) object, user_name(uid) owner from sysobjects where type in (N'U', N'S', N'V', N'P', N'FN') order by object, owner", timeout);

            if (ds == null || ds.Tables.Count == 0)
            {
                return(null);
            }

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                string type = row ["type"].ToString().Substring(0, 2).Trim();

                int position;
                if (type == "U")
                {
                    position = 0;                                                                                               // user table
                }
                else if (type == "S")
                {
                    position = 1;                                                                               // system table
                }
                else if (type == "V")
                {
                    position = 2;                                                                               // view
                }
                else if (type == "FN")
                {
                    position = 5;                                                                                       // function
                }
                else if ((int)row ["shipped"] == 0)
                {
                    position = 3;                                                               // user stored proc
                }
                else
                {
                    position = 4;                                                                                                               // MS stored proc
                }
                string  prefix = row ["owner"].ToString() == "dbo" ? "" : row ["owner"].ToString() + ".";
                SqlNode node   = new SqlNode(prefix + row ["object"].ToString());
                node.type     = type;
                node.database = dbClient.Database;
                node.name     = row ["object"].ToString();
                node.owner    = row ["owner"].ToString();

                // If the object name contains a space, wrap the "safe name" in square brackets.
                if (node.owner.IndexOf(' ') >= 0 || node.name.IndexOf(' ') >= 0)
                {
                    node.safeName = "[" + node.name + "]";
                    node.dragText = "[" + node.owner + "].[" + node.name + "]";
                }
                else
                {
                    node.safeName = node.name;
                    node.dragText = node.owner + "." + node.name;
                }
                top [position].Nodes.Add(node);

                // Add a dummy sub-node to user tables and views so they'll have a clickable expand sign
                // allowing us to have GetSubObjectHierarchy called so the user can view the columns
                if (type == "U" || type == "V")
                {
                    node.Nodes.Add(new TreeNode());
                }
            }
            return(top);
        }