private List <LgObject> GetTablesAndViews()
        {
            var lgObjects = new List <LgObject>();

            using (var connection = new OleDbConnection(ConnectionString))
            {
                connection.Open();
                using (DataTable tables = connection.GetSchema("Tables"))
                {
                    foreach (DataRow row in tables.Rows.Cast <DataRow>().Where(row => ((string)row["TABLE_TYPE"]).ToLower() == "table"))
                    {
                        var obj = new LgObject
                        {
                            IsView     = false,
                            ObjectName = (string)row["TABLE_NAME"]
                        };

                        lgObjects.Add(obj);
                    }

                    foreach (DataRow row in tables.Rows.Cast <DataRow>().Where(row => ((string)row["TABLE_TYPE"]).ToLower() == "view"))
                    {
                        var obj = new LgObject
                        {
                            IsView     = true,
                            ObjectName = (string)row["TABLE_NAME"]
                        };

                        lgObjects.Add(obj);
                    }
                }
            }
            return(lgObjects);
        }
Пример #2
0
        private List <LgObject> GetTablesAndViews()
        {
            var lgObjects = new List <LgObject>();

            using (var connection = new SqlConnection())
            {
                connection.ConnectionString = ConnectionString;
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "sp_tables";
                    command.Parameters.AddWithValue("@table_qualifier", DatabaseName);
                    command.Parameters.AddWithValue("@table_owner", DefaultSchema);

                    using (var adapter = new SqlDataAdapter())
                    {
                        adapter.SelectCommand = command;
                        using (var ds = new DataSet())
                        {
                            adapter.Fill(ds);
                            if (ds.Tables.Count > 0)
                            {
                                foreach (DataRow row in ds.Tables[0].Rows)
                                {
                                    var lgObject = new LgObject {
                                        ObjectName = (string)row["TABLE_NAME"]
                                    };
                                    if (lgObject.ObjectName.ToLower() == "dtproperties" || lgObject.ObjectName.ToLower() == "syscolumns" ||
                                        lgObject.ObjectName.ToLower() == "sysdepends" || lgObject.ObjectName.ToLower() == "syscomments" ||
                                        lgObject.ObjectName.ToLower() == "sysfilegroups" || lgObject.ObjectName.ToLower() == "sysfiles" ||
                                        lgObject.ObjectName.ToLower() == "sysfiles1" || lgObject.ObjectName.ToLower() == "sysforeignkeys" ||
                                        lgObject.ObjectName.ToLower() == "sysproperties" || lgObject.ObjectName.ToLower() == "sysusers" ||
                                        lgObject.ObjectName.ToLower() == "sysconstraints" || lgObject.ObjectName.ToLower() == "syssegments" ||
                                        lgObject.ObjectName.ToLower() == "sysdiagrams")
                                    {
                                        continue;
                                    }

                                    lgObject.IsView = ((string)row["TABLE_TYPE"]).ToLower() == "view";

                                    lgObjects.Add(lgObject);
                                }
                            }
                        }
                    }
                }
            }
            return(lgObjects);
        }
Пример #3
0
        private List <LgObject> GetTablesAndViews()
        {
            var lgObjects = new List <LgObject>();

#if ORACLE
            using (var connection = new Oracle.ManagedDataAccess.Client.OracleConnection(ConnectionString))
            {
                connection.Open();
                using (DataTable tables = connection.GetSchema("Tables"))
                {
                    foreach (DataRow row in tables.Rows.Cast <DataRow>())
                    {
                        if (!string.Equals(((string)row["OWNER"]), DefaultSchema, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        var obj = new LgObject
                        {
                            IsView     = false,
                            ObjectName = (string)row["TABLE_NAME"]
                        };

                        lgObjects.Add(obj);
                    }
                }

                using (DataTable views = connection.GetSchema("Views"))
                {
                    foreach (DataRow row in views.Rows)
                    {
                        if (!string.Equals(((string)row["OWNER"]), DefaultSchema, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        var obj = new LgObject
                        {
                            IsView     = true,
                            ObjectName = (string)row["VIEW_NAME"]
                        };

                        lgObjects.Add(obj);
                    }
                }
            }
#endif
            return(lgObjects);
        }
Пример #4
0
        private List <LgObject> GetTablesAndViews()
        {
            var lgObjects = new List <LgObject>();

            using (var connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();
                using (DataTable tables = connection.GetSchema("Tables"))
                {
                    foreach (DataRow row in tables.Rows.Cast <DataRow>())
                    {
                        if (((string)row["TABLE_SCHEMA"]) != DatabaseName)
                        {
                            continue;
                        }
                        var obj = new LgObject();
                        obj.IsView     = false;
                        obj.ObjectName = (string)row["TABLE_NAME"];

                        lgObjects.Add(obj);
                    }
                }

                using (DataTable views = connection.GetSchema("Views"))
                {
                    foreach (DataRow row in views.Rows)
                    {
                        if (((string)row["TABLE_SCHEMA"]) != DatabaseName)
                        {
                            continue;
                        }
                        var obj = new LgObject
                        {
                            IsView     = true,
                            ObjectName = (string)row["TABLE_NAME"]
                        };

                        lgObjects.Add(obj);
                    }
                }
            }
            return(lgObjects);
        }