コード例 #1
0
        private List<LgObject> GetTablesAndViews()
        {
            var lgObjects = new List<LgObject>();

            using (var connection = new SQLiteConnection(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();
                        obj.IsView = false;
                        obj.ObjectName = (string) row["TABLE_NAME"];

                        lgObjects.Add(obj);
                    }
                }

                using (DataTable views = connection.GetSchema("Views"))
                {
                    foreach (DataRow row in views.Rows)
                    {
                        var obj = new LgObject();
                        obj.IsView = true;
                        obj.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();
                                    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>();

            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();
                        obj.IsView     = true;
                        obj.ObjectName = (string)row["TABLE_NAME"];

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