示例#1
0
        internal static List <Table> getTablesInfo(sqlservers server, DbConnection con)
        {
            var list = new List <Table>();

            using (var r = new DbCommandFactory(con, new SqlBuilderFactory(server).Create(con.Database).getAllFieldsFromAllTablesInDb()).Create().ExecuteReader())
            {
                while (r.Read())
                {
                    list.Add(new Table(r.GetString(0), r.GetString(1), r.GetString(2), r.GetString(3),
                                       r.GetValue(4) != DBNull.Value ? r.GetInt64(4) : default));
                }
            }
            return(list);
        }
示例#2
0
        //returns all fields from all tables
        internal static List <Table> getTablesInfo(sqlservers server, DbConnection con)
        {
            var list = new List <Table>();

            try
            {
                if (sql.Utils.IsDbEmbedded(server.db_type))
                {
                    //case of embedded like sqlite the process to get all fields from all tables is very different.
                    //first get all tables
                    List <string> tables = getTables(con);
                    //and then for every each one get table fields
                    foreach (string table in tables)
                    {
                        string table_info = new SqlBuilderFactory(server).Create(con.Database).describeTableSql(table);
                        using (var r = new DbCommandFactory(con, table_info).Create().ExecuteReader())
                        {
                            while (r.Read())
                            {
                                list.Add(new Table(table, r.GetString(1), r.GetString(2), r.GetInt32(3) == 0 ? "YES" : "NO", 0));
                            }
                        }
                        Terminal.MainTerminal.AppendText(table_info);
                    }
                }
                else
                {
                    string sql = new SqlBuilderFactory(server).Create(con.Database).getAllFieldsFromAllTablesInDb();
                    using (var r = new DbCommandFactory(con, sql).Create().ExecuteReader())
                    {
                        while (r.Read())
                        {
                            list.Add(new Table(r.GetString(0), r.GetString(1), r.GetString(2), r.GetString(3),
                                               r.GetValue(4) != DBNull.Value ? r.GetInt64(4) : default));
                        }
                    }
                    Terminal.MainTerminal.AppendText(sql);
                }
            }
            catch (DbException ex)
            {
                Terminal.MainTerminal.AppendText(ex.Message);
#if DEBUG
                Console.WriteLine(ex.Message);
#endif
            }
            return(list);
        }