Esempio n. 1
0
        //открытия бд и создание информации о каждой таблицы
        public bool open_db_and_show_info()
        {
            q_conn = new SQLiteConnection();
            q_conn.ConnectionString = "Data source =" + path_to_db + ";";

            db_conn_open();
            q_comm = new SQLiteCommand(q_conn);

            //извлечение информации о таблицах
            q_comm.CommandText = "SELECT name FROM sqlite_master WHERE type =\"table\" order by name;";

            SQLiteDataReader q_rd = q_comm.ExecuteReader();
            comboBox1.Items.Clear();
            clear(1);

            if (q_rd.FieldCount > 0)
                //заполнение коллекции таблиц
                while (q_rd.Read())
                {
                    if (q_rd["name"].ToString() != "sqlite_sequence")
                    {
                        info_tbl inf = new info_tbl();

                        //имя базы данных
                        inf.name_tbl = q_rd["name"].ToString();

                        //
                        informations_of_tbl.Add(inf);
                    }
                }

            //заполение comboBox именами таблиц
            foreach (info_tbl tb in informations_of_tbl)
            {
                comboBox1.Items.Add(tb.name_tbl);
            }

            if (comboBox1.Items.Count > 0)
                comboBox1.SelectedItem = comboBox1.Items[0];

            for (int i = 0; i < informations_of_tbl.Count; i++)
            {
                info_tbl tbl = (info_tbl)informations_of_tbl[i];

                q_comm = new SQLiteCommand(q_conn);
                q_comm.CommandText = "PRAGMA TABLE_INFO(" + tbl.name_tbl + ");";
                SQLHistory(q_comm.CommandText);

                q_rd = q_comm.ExecuteReader();

                if (q_rd.FieldCount > 0)
                    while (q_rd.Read())
                    {
                        //структура для хранения имен и типов полей таблицы
                        fields fld = new fields();

                        fld.cid = Convert.ToInt32(q_rd[0]);
                        fld.name_f = q_rd["name"].ToString();
                        fld.type_f = q_rd["type"].ToString();
                        fld.primary_key = Convert.ToInt32(q_rd["pk"]);

                        tbl.fields_arr.Add(fld);

                    }

                informations_of_tbl.RemoveAt(i);
                informations_of_tbl.Insert(i, tbl);

            }
            return true;
        }
Esempio n. 2
0
        //генерация структуры таблицы
        public void gen_struct(info_tbl info_d)
        {
            StructGrid.Rows.Add(1);

            info_tbl tbl = new info_tbl();
            tbl = (info_tbl)informations_of_tbl[comboBox1.SelectedIndex];

            //заполнение грида o структурe таблицы
            for (int i = 0; i < tbl.fields_arr.Count; i++)
            {
                fields fld = (fields)tbl.fields_arr[i];
                StructGrid.Rows[i].Cells[0].Value = fld.name_f;
                StructGrid.Rows[i].Cells[1].Value = fld.type_f;
                StructGrid.Rows[i].Cells[2].Value = fld.primary_key;

                if (i + 1 < tbl.fields_arr.Count)
                    StructGrid.Rows.Add(1);
            }

            //физическая информация БД
            get_info_to_db();
        }