Пример #1
0
        public override void LoadStructure()
        {
            tables.Clear();

            using (QMySql s = new QMySql())
            {
                s.Open("select table_name, table_type from information_schema.tables where table_type in ('BASE TABLE','VIEW') and table_schema='" + databaseName + "'");
                while (s.GetRow())
                {
                    DbTable t = new DbTable("", s[0], s[1]);
                    tables.Add(t.name, t);
                    using (QMySql sFields = new QMySql())
                    {
                        sFields.Open("describe " + t.name);
                        // List<string> tableFieldNames = new List<string>();
                        while (sFields.GetRow())
                        {
                            DbColumn c = new DbColumn(t, sFields[0], sFields[1],
                                                      sFields[3] == "PRI",
                                                      sFields[2] == "YES", sFields[4]);
                            t.columns.Add(c.name, c);
                            tablesByColumnName.Add(c.name, t);
                        }
                    }
                }
            }
        }
Пример #2
0
        public Plant GetPlant(int id)
        {
            using (QMySql s = new QMySql())
            {
                s.Open(@"
select * from plants where id=@1", id);
                if (s.GetRow())
                {
                    Plant p = new Plant();
                    QObject.PopulateFromRow(s, p);

                    p.habitats = QMySql.SqlList(@"
select h.name 
from habitats h
inner join plantHabitat p on p.habitat_id=h.id
where p.plant_id=" + id).ToList();

                    p.uses = QMySql.SqlList(@"
select h.name 
from uses h
inner join plantUse p on p.use_id=h.id
where p.plant_id=" + id).ToList();

                    p.soilPreferences = QMySql.SqlList(@"
select h.name 
from soilPreferences h
inner join plantSoilPreference p on p.soilPreference_id=h.id
where p.plant_id=" + id).ToList();

                    p.shadePreferences = QMySql.SqlList(@"
select h.name 
from shadePreferences h
inner join plantShadePreference p on p.shadePreference_id=h.id
where p.plant_id=" + id).ToList();
                    p.images           = QMySql.SqlList(@"
select p.image 
from plantImages p
where p.plant_id=" + id + " order by p.seq").ToList();

                    p.heatMapData = GetHeatMapData(p.habitats);

                    return(p);
                }
            }

            throw new ArgumentException();
        }
Пример #3
0
        public IEnumerable <PlantSummary> GetPlantSummaries(string sql, string typ)
        {
            List <PlantSummary> result = new List <PlantSummary>();

            using (QMySql s = new QMySql())
            {
                s.Open(sql, typ);
                while (s.GetRow())
                {
                    PlantSummary p = new PlantSummary();
                    QObject.PopulateFromRow(s, p);
                    p.image = GetFirstImage(p.id);
                    result.Add(p);
                }
            }

            return(result);
        }