Files
OnlineJudge/judge/languages.py
yuetsh 9f7f818d51 新增 SQL 题型:SQLite 内联判题(不依赖外部沙箱)
- SQL 作为语言接入现有提交流程,judge_task 按 language 分流到 SQLJudgeDispatcher
- judge/sql_runner.py:内存 SQLite 判题核心,查询题比结果集/增删改题比表状态,
  authorizer + progress_handler + max_page_count 三重防护
- dispatcher 提取 _process_judge_result/_push_status 供 SQL 判题复用(行为不变)
- 测试点通道支持 1.sql..N.sql 压缩包,出题只需数据脚本+标准答案
- Problem 增加 sql_config 字段;options 数据迁移注册 SQL 语言

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 17:23:13 -06:00

180 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from problem.models import ProblemIOMode
default_env = ["LANG=en_US.UTF-8", "LANGUAGE=en_US:en", "LC_ALL=en_US.UTF-8"]
_c_lang_config = {
"template": """//PREPEND BEGIN
#include <stdio.h>
//PREPEND END
//TEMPLATE BEGIN
int add(int a, int b) {
// code
}
//TEMPLATE END
//APPEND BEGIN
int main() {
printf("%d\n", add(1, 2));
return 0;
}
//APPEND END""",
"compile": {
"src_name": "main.c",
"exe_name": "main",
"max_cpu_time": 3000,
"max_real_time": 10000,
"max_memory": 256 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c17 {src_path} -lm -o {exe_path}",
},
"run": {"command": "{exe_path}", "seccomp_rule": {ProblemIOMode.STANDARD: "c_cpp", ProblemIOMode.FILE: "c_cpp_file_io"}, "env": default_env},
}
_cpp_lang_config = {
"template": """//PREPEND BEGIN
#include <iostream>
//PREPEND END
//TEMPLATE BEGIN
int add(int a, int b) {
// code
}
//TEMPLATE END
//APPEND BEGIN
int main() {
std::cout << add(1, 2) << std::endl;
return 0;
}
//APPEND END""",
"compile": {
"src_name": "main.cpp",
"exe_name": "main",
"max_cpu_time": 10000,
"max_real_time": 20000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++20 {src_path} -lm -o {exe_path}",
},
"run": {"command": "{exe_path}", "seccomp_rule": {ProblemIOMode.STANDARD: "c_cpp", ProblemIOMode.FILE: "c_cpp_file_io"}, "env": default_env},
}
_java_lang_config = {
"template": """//PREPEND BEGIN
class Main {
//PREPEND END
//TEMPLATE BEGIN
static int add(int a, int b) {
// code
}
//TEMPLATE END
//APPEND BEGIN
public static void main(String [] args) {
System.out.println(add(1, 2));
}
}
//APPEND END""",
"compile": {
"src_name": "Main.java",
"exe_name": "Main",
"max_cpu_time": 5000,
"max_real_time": 10000,
"max_memory": -1,
"compile_command": "/usr/bin/javac {src_path} -d {exe_dir}",
},
"run": {"command": "/usr/bin/java -cp {exe_dir} -XX:MaxRAM={max_memory}k Main", "seccomp_rule": None, "env": default_env, "memory_limit_check_only": 1},
}
_py3_lang_config = {
"template": """//PREPEND BEGIN
//PREPEND END
//TEMPLATE BEGIN
def add(a, b):
# code
//TEMPLATE END
//APPEND BEGIN
print(add(1, 2))
//APPEND END""",
"compile": {
"src_name": "solution.py",
"exe_name": "solution.py",
"max_cpu_time": 3000,
"max_real_time": 10000,
"max_memory": 128 * 1024 * 1024,
"compile_command": "/usr/bin/python3 -m py_compile {src_path}",
},
"run": {"command": "/usr/bin/python3 -BS {exe_path}", "seccomp_rule": "general", "env": default_env},
}
_go_lang_config = {
"template": """//PREPEND BEGIN
package main
import "fmt"
//PREPEND END
//TEMPLATE BEGIN
func add(a int, b int) int {
// code
}
//TEMPLATE END
//APPEND BEGIN
func main() {
fmt.Println(add(1, 2))
}
//APPEND END""",
"compile": {
"src_name": "main.go",
"exe_name": "main",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/go build -o {exe_path} {src_path}",
"env": ["GOCACHE=/tmp", "GOPATH=/tmp", "GOMAXPROCS=1"] + default_env,
},
"run": {"command": "{exe_path}", "seccomp_rule": "golang", "env": ["GOMAXPROCS=1"] + default_env, "memory_limit_check_only": 1},
}
_node_lang_config = {
"template": """//PREPEND BEGIN
//PREPEND END
//TEMPLATE BEGIN
function add(a, b) {
// code
}
//TEMPLATE END
//APPEND BEGIN
console.log(add(1, 2))
//APPEND END""",
"compile": {
"src_name": "main.js",
"exe_name": "main.js",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/node --check {src_path}",
"env": default_env,
},
"run": {"command": "/usr/bin/node {exe_path}", "seccomp_rule": "node", "env": default_env, "memory_limit_check_only": 1},
}
languages = [
{"config": _c_lang_config, "name": "C", "description": "GCC 13", "content_type": "text/x-csrc"},
{"config": _cpp_lang_config, "name": "C++", "description": "GCC 13", "content_type": "text/x-c++src"},
{"config": _java_lang_config, "name": "Java", "description": "Temurin 21", "content_type": "text/x-java"},
{"config": _py3_lang_config, "name": "Python3", "description": "Python 3.12", "content_type": "text/x-python"},
{"config": _go_lang_config, "name": "Golang", "description": "Golang 1.22", "content_type": "text/x-go"},
{"config": _node_lang_config, "name": "JavaScript", "description": "Node.js 20", "content_type": "text/javascript"},
# SQL 题不走外部 judger 沙箱judge/sql_dispatcher.py 在 worker 内用 sqlite3 判题config 仅占位
{"config": {"template": ""}, "name": "SQL", "description": "SQLite 3", "content_type": "text/x-sql"},
]