Example #1
0
        private TableCollection GetTablesInternal(DALGetTablesInputParams inputParams)
        {
#if USE_CACHE
            return(HttpContext.Current.Cache.Get(inputParams.ConnectionString + "-tables"
                                                 , () => new TableCollection(DAL.GetTables(inputParams))));
#else
            return(new TableCollection(DAL.GetTables(inputParams)));
#endif
        }
Example #2
0
 public static void TryLoadFromCookies(this DALGetTablesInputParams inputParams, HttpRequest request)
 {
     if (inputParams.UserName.IsNullOrWhiteSpace())
     {
         inputParams.UserName = request.GetCookieString("UserName");
     }
     if (inputParams.Password.IsNullOrWhiteSpace())
     {
         inputParams.Password = request.GetCookieString("Password");
     }
 }
Example #3
0
        public TableCollection GetTables([FromUri] DALGetTablesInputParams inputParams)
        {
            try
            {
                inputParams.TryLoadFromCookies(HttpContext.Current.Request);
                DALGetRefsInputParams.ThrowIfWrong(inputParams);

                return(GetTablesInternal(inputParams));
            }
            catch (Exception ex)
            {
                return(new TableCollection(ex));
            }
        }
        public static ICollection <RefItem> GetRefs(DALGetRefsInputParams inputParams)
        {
            DALGetTablesInputParams.ThrowIfWrong(inputParams);

            using (var con = new SqlConnection(inputParams.ConnectionString))
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = inputParams.RootTableNamesSet.Any() ? COMMAND_TIMEOUT_60 : COMMAND_TIMEOUT_300;
                    cmd.CommandText    = string.Format(SQL_GET_REFS_BY_FOREIGN_TABLENAME
                                                       , inputParams.RootTableNamesSet.Any() ? 0 : 1
                                                       , '\'' + string.Join("','", inputParams.RootTableNamesSet.Select(table => table.Replace("'", "''"))) + '\'');

                    con.Open();

                    var refs = new LinkedList <RefItem>();
                    using (var rd = cmd.ExecuteReader())
                    {
                        for (int idx_1 = rd.GetOrdinal("Level"),
                             idx_2 = rd.GetOrdinal("IsSelfRefs"),
                             idx_3 = rd.GetOrdinal("FKName"),
                             idx_4 = rd.GetOrdinal("TableName"),
                             idx_5 = rd.GetOrdinal("Column"),
                             idx_6 = rd.GetOrdinal("ForeignTableName"),
                             idx_7 = rd.GetOrdinal("ForeignColumn");
                             rd.Read();)
                        {
                            var refItem = new RefItem()
                            {
                                Level            = rd.GetInt32(idx_1),
                                IsSelfRefs       = (rd.GetInt32(idx_2) != 0),
                                FKName           = rd.GetString(idx_3),
                                TableName        = rd.GetString(idx_4),
                                Column           = rd.GetString(idx_5),
                                ForeignTableName = rd.GetString(idx_6),
                                ForeignColumn    = rd.GetString(idx_7),
                            };
                            refs.AddLast(refItem);
                        }
                    }
                    return(refs);
                }
        }
        public static ISet <Table> GetTables(DALGetTablesInputParams inputParams)
        {
            DALGetTablesInputParams.ThrowIfWrong(inputParams);

            using (var con = new SqlConnection(inputParams.ConnectionString))
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = COMMAND_TIMEOUT_15;
                    cmd.CommandText    = SQL_GET_TABLES;

                    con.Open();

                    var tables = new SortedSet <Table>(default(Table));
                    using (var rd = cmd.ExecuteReader())
                    {
                        for (var idx = rd.GetOrdinal("TableName"); rd.Read();)
                        {
                            tables.Add(new Table(rd.GetString(idx)));
                        }
                    }
                    return(tables);
                }
        }