private CompareResult CompareQuery(DbQueryData stdQuery, DbQueryData usrQuery)
        {
            if (stdQuery.FieldCount != usrQuery.FieldCount || stdQuery.Records.Count != usrQuery.Records.Count)
            {
                return(CompareResult.WrongAnswer);
            }

            int filedCount  = stdQuery.FieldCount;
            int recordCount = stdQuery.Records.Count;

            for (int i = 0; i < filedCount; i++)
            {
                if (!CmpString(stdQuery.FieldNames[i], usrQuery.FieldNames[i]))
                {
                    return(CompareResult.WrongAnswer);
                }
            }

            for (int i = 0; i < recordCount; i++)
            {
                for (int j = 0; j < filedCount; j++)
                {
                    if (stdQuery.Records[i][j] != usrQuery.Records[i][j])
                    {
                        return(CompareResult.WrongAnswer);
                    }
                }
            }

            return(CompareResult.Accepted);
        }
Example #2
0
        private void BuildStandardData(DbTestData testData, out string inputData, out DbData outputData,
                                       out DbQueryData queryData)
        {
            inputData  = testData.Input;
            outputData = null;
            queryData  = null;
            string stdOperCmd  = testData.Operation;
            string stdQueryCmd = testData.Query;

            BaseDbOperator stdOperator = CreateJudgeEnv(inputData);

            try
            {
                DbDataReader reader = stdOperator.ExecuteReader(stdOperCmd ?? stdQueryCmd);
                if (stdOperCmd != null)
                {
                    outputData = stdOperator.ReadDbData();
                }

                if (stdQueryCmd != null)
                {
                    queryData = BaseDbOperator.ReadQueryData(reader);
                }
            }
            catch (Exception ex)
            {
                throw new JudgeException("Build Db test data failed!" + ex);
            }
            finally
            {
                ClearJudgeEnv(stdOperator);
            }
        }
Example #3
0
        /// <summary>
        /// 查询表的所有记录
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns>表数据</returns>
        private DbQueryData GetTableData(string tableName)
        {
            string       cmd    = $"SELECT * FROM {tableName}";
            DbDataReader reader = ExecuteReader(cmd);

            DbQueryData queryData = ReadQueryData(reader, tableName);

            return(queryData);
        }
        private CompareResult CompareAnswer(DbData stdOutput, DbQueryData stdQuery, DbData usrOutput,
                                            DbQueryData usrQuery)
        {
            if (stdOutput != null && CompareDbData(stdOutput, usrOutput) == CompareResult.WrongAnswer)
            {
                return(CompareResult.WrongAnswer);
            }

            if (stdQuery != null && CompareQuery(stdQuery, usrQuery) == CompareResult.WrongAnswer)
            {
                return(CompareResult.WrongAnswer);
            }

            return(CompareResult.Accepted);
        }
Example #5
0
        public override DbData ReadDbData()
        {
            string[]      tablesName = GetAllTablesName();
            DbQueryData[] data       = new DbQueryData[tablesName.Length];
            for (int i = 0; i < tablesName.Length; i++)
            {
                data[i] = GetTableData(tablesName[i]);
            }

            Array.Sort(data, (a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            return(new DbData
            {
                TablesData = data
            });
        }
Example #6
0
        /// <summary>
        /// 评测一组用例
        /// </summary>
        /// <param name="stdInput">标准输入</param>
        /// <param name="stdOutput">标准输出</param>
        /// <param name="stdQuery">标准查询</param>
        /// <returns></returns>
        public SingleJudgeResult Judge(string stdInput, DbData stdOutput, DbQueryData stdQuery)
        {
            Stopwatch    sw        = new Stopwatch();
            DbDataReader reader    = null;
            DbQueryData  usrQuery  = null;
            DbData       usrOutput = null;

            try
            {
                sw.Start();
                reader = UserOperator.ExecuteReader(JudgeTask.SourceCode, JudgeTask.TimeLimit);

                usrQuery  = BaseDbOperator.ReadQueryData(reader);
                usrOutput = UserOperator.ReadDbData();
            }
            catch (Exception ex)
            {
                return(new SingleJudgeResult
                {
                    ResultCode = JudgeResultCode.RuntimeError,
                    JudgeDetail = ex.Message,
                    TimeCost = 0
                });
            }
            finally
            {
                sw.Stop();
            }

            CompareResult   result     = CompareAnswer(stdOutput, stdQuery, usrOutput, usrQuery);
            JudgeResultCode resultCode = (result == CompareResult.Accepted)
                ? JudgeResultCode.Accepted
                : JudgeResultCode.WrongAnswer;

            return(new SingleJudgeResult
            {
                ResultCode = resultCode,
                TimeCost = (int)sw.ElapsedMilliseconds
            });
        }