コード例 #1
0
        public override ContestRegistration GetRegistration(string userID, int contestID)
        {
            string command = "SELECT SystemRights,IsInvisible FROM Rights WHERE ContestID = @cid AND UserID = @uid";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillMultipleIDs,
                                                           new object[] { userID, contestID }))
                    return(RegistrationFromReader(rdr));
        }
コード例 #2
0
        public override Contest GetContest(int contestID)
        {
            string command = "SELECT * FROM Contests WHERE ID=@id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, contestID))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
        }
コード例 #3
0
        public override Language GetLanguage(string languageID)
        {
            string command = "SELECT * FROM Languages WHERE ID=@id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, languageID))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
        }
コード例 #4
0
        public override Submission GetSubmission(int submissionID)
        {
            string command = "SELECT ID,ProblemID,UserID,LanguageID,Time,Outcome FROM Submissions " +
                             "WHERE ID=@id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, submissionID))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
        }
コード例 #5
0
        public override Contest[] GetContests(ContestTime type)
        {
            string[] conds = new string[]
            {
                "(Beginning <= GETDATE() AND Ending >= GETDATE())",
                "Ending < GETDATE()",
                "Beginning > GETDATE()"
            };

            string command = "SELECT * FROM Contests WHERE ";

            bool first = true;

            int[] inds = new int[] { 1, 2, 4 };
            for (int i = 0; i < 3; i++)
            {
                if (((int)type & inds[i]) != 0)
                {
                    if (!first)
                    {
                        command += " OR ";
                    }
                    first    = false;
                    command += conds[i];
                }
            }

            List <Contest> ret = new List <Contest>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, null, null))
                {
                    while (rdr.Read())
                    {
                        ret.Add(FromReader(rdr));
                    }
                }

            ret.Sort(delegate(Contest a, Contest b)
            {
                if (a.Time > b.Time)
                {
                    return(1);
                }
                if (a.Time < b.Time)
                {
                    return(-1);
                }
                return(0);
            });
            return(ret.ToArray());
        }
コード例 #6
0
        public override Problem GetProblem(int problemID)
        {
            string command = String.Format("{0} WHERE ID=@id", SELECT_STRING);

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
            {
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, problemID))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
            }
        }
コード例 #7
0
        public override Test GetTest(int problemID, int testNumber)
        {
            string command = "SELECT ProblemID,TestNumber,Description,Points FROM Tests WHERE ProblemID=@pid AND TestNumber=@tn";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
            {
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, new int[] { problemID, testNumber }))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
            }
        }
コード例 #8
0
        public override byte[] GetCheckerBytes(int problemID)
        {
            string command = "SELECT CheckerBytes FROM Problems WHERE ID=@id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, problemID))
                {
                    rdr.Read();
                    long   len = rdr.GetBytes(0, 0, null, 0, 0);
                    byte[] buf = new byte[len];
                    rdr.GetBytes(0, 0, buf, 0, buf.Length);
                    return(buf);
                }
        }
コード例 #9
0
        public override User GetUser(string userID)
        {
            string command = "SELECT * FROM Users WHERE ID = @id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, userID))
                {
                    if (rdr.Read())
                    {
                        return(UserFromReader(rdr));
                    }
                    return(null);
                }
        }
コード例 #10
0
        public override Message GetMessage(int messageID)
        {
            string command = "SELECT * FROM Messages WHERE ID = @id";

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, delegate(SqlCommand comm, object customParam)
                {
                    comm.Parameters.AddWithValue("@id", messageID);
                }, null))
                {
                    rdr.Read();
                    return(FromReader(rdr));
                }
        }
コード例 #11
0
        byte[] GetTestBytes(string field, int problemID, int testNumber)
        {
            string command = String.Format("SELECT {0} FROM Tests WHERE ProblemID=@pid AND TestNumber=@tn", field);

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, new int[] { problemID, testNumber }))
                {
                    rdr.Read();
                    long   len = rdr.GetBytes(0, 0, null, 0, 0);
                    byte[] buf = new byte[len];
                    rdr.GetBytes(0, 0, buf, 0, buf.Length);
                    return(buf);
                }
        }
コード例 #12
0
        public override User[] GetUsers()
        {
            string      command = "SELECT * FROM Users";
            List <User> us      = new List <User>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, null, null))
                {
                    while (rdr.Read())
                    {
                        us.Add(UserFromReader(rdr));
                    }
                }
            return(us.ToArray());
        }
コード例 #13
0
        public override Language[] GetLanguages()
        {
            string          command = "SELECT * FROM Languages";
            List <Language> tmp     = new List <Language>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader sr = q.ExecuteReader(command, null, null))
                {
                    while (sr.Read())
                    {
                        tmp.Add(FromReader(sr));
                    }
                }
            return(tmp.ToArray());
        }
コード例 #14
0
        public override Problem[] GetProblems(int contestID)
        {
            string         command  = String.Format("{0} WHERE ContestID=@id ORDER BY ShortName", SELECT_STRING);
            List <Problem> problems = new List <Problem>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
            {
                using (SqlDataReader rdr = q.ExecuteReader(command, FillID, contestID))
                {
                    while (rdr.Read())
                    {
                        problems.Add(FromReader(rdr));
                    }
                }
            }
            return(problems.ToArray());
        }
コード例 #15
0
        public override Submission[] GetSubmissions(SubmissionsFilter filter)
        {
            string command = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY ID DESC)" +
                             " AS RowID,ID,ProblemID,UserID,LanguageID,Time,Outcome FROM (SELECT Submissions.ID,Submissions.ProblemID," +
                             "Submissions.UserID,Submissions.LanguageID,Submissions.Time,Submissions.Outcome " +
                             "FROM Submissions,Contests,Problems" +
                             " WHERE Submissions.ProblemID=Problems.ID AND Problems.ContestID = Contests.ID AND Contests.ID=@cid";

            if (filter.RequiredUserID)
            {
                command += " AND Submissions.UserID=@uid";
            }
            if (filter.RequiredOutcome)
            {
                command += " AND Submissions.Outcome=@ou";
            }
            if (filter.RequiredProblemID)
            {
                command += " AND Submissions.ProblemID = @pid";
            }

            command += ") AS T2) AS T";

            if (filter.RequiredPaging)
            {
                command += string.Format(" WHERE RowID between {0} and {1}", filter.From, filter.To);
            }
            else
            {
                command += " ORDER BY RowID DESC";
            }

            List <Submission> list = new List <Submission>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command.ToString(), addFilterParams, filter))
                {
                    while (rdr.Read())
                    {
                        list.Add(FromReader(rdr));
                    }
                }
            return(list.ToArray());
        }
コード例 #16
0
        public override Message[] GetMessages(MessagesFilter filter)
        {
            List <Message> messages = new List <Message>();
            string         command  = null;

            if (filter.ReguiredProblemID)
            {
                command = "SELECT * FROM Messages WHERE ProblemID = @pid AND Type = @type";
            }
            else
            {
                command = "SELECT Messages.ID,Messages.ProblemID,Messages.UserID,Messages.Time,Messages.Type," +
                          "Messages.ContestantMessage,Messages.JuryMessage FROM Messages,Contests,Problems " +
                          "WHERE Messages.Type = @type AND Messages.ProblemID = Problems.ID AND Problems.ContestID = Contests.ID AND Contests.ID = @cid";
            }
            if (filter.RequiredEmptyJuryMessage)
            {
                command += " AND Messages.JuryMessage = ''";
            }
            else
            {
                command += " AND Messages.JuryMessage != ''";
            }
            if (filter.RequiredUserID)
            {
                command += " AND Messages.UserID=@uid";
            }
            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
                using (SqlDataReader rdr = q.ExecuteReader(command, delegate(SqlCommand comm, object customParam)
                {
                    comm.Parameters.AddWithValue("@type", filter.Type.ToString());
                    comm.Parameters.AddWithValue("@pid", filter.ProblemID);
                    comm.Parameters.AddWithValue("@cid", filter.ContestID);
                    if (filter.RequiredUserID)
                    {
                        comm.Parameters.AddWithValue("@uid", filter.UserID);
                    }
                }, null))
                    while (rdr.Read())
                    {
                        messages.Add(FromReader(rdr));
                    }
            return(messages.ToArray());
        }
コード例 #17
0
        public override Test[] GetTests(int problemID)
        {
            string      command = "SELECT ProblemID,TestNumber,Description,Points FROM Tests WHERE ProblemID=@pid";
            List <Test> tests   = new List <Test>();

            using (MsSqlQuery q = new MsSqlQuery(_connectionString))
            {
                using (SqlDataReader rdr = q.ExecuteReader(command, delegate(SqlCommand comm, object p)
                {
                    comm.Parameters.AddWithValue("@pid", problemID);
                }, null))
                {
                    while (rdr.Read())
                    {
                        tests.Add(FromReader(rdr));
                    }
                }
            }
            return(tests.ToArray());
        }