新增 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>
This commit is contained in:
2026-07-02 17:23:13 -06:00
parent d1a1c05b9f
commit 9f7f818d51
10 changed files with 551 additions and 93 deletions

View File

@@ -0,0 +1,43 @@
# SysOptions.languages 存在数据库里_init_option 只在 key 缺失时写入默认值,
# 因此新增 SQL 语言必须用数据迁移追加到已部署库;不用 reset_languages()(会覆盖管理员的自定义配置)。
from django.db import migrations
SQL_LANGUAGE = {
"config": {"template": ""},
"name": "SQL",
"description": "SQLite 3",
"content_type": "text/x-sql",
}
def add_sql_language(apps, schema_editor):
SysOptions = apps.get_model("options", "SysOptions")
try:
option = SysOptions.objects.get(key="languages")
except SysOptions.DoesNotExist:
# 库还没初始化过 languages留给 _init_option 用代码默认值(已含 SQL创建
return
if not any(item.get("name") == "SQL" for item in option.value):
option.value.append(SQL_LANGUAGE)
option.save(update_fields=["value"])
def remove_sql_language(apps, schema_editor):
SysOptions = apps.get_model("options", "SysOptions")
try:
option = SysOptions.objects.get(key="languages")
except SysOptions.DoesNotExist:
return
option.value = [item for item in option.value if item.get("name") != "SQL"]
option.save(update_fields=["value"])
class Migration(migrations.Migration):
dependencies = [
("options", "0001_initial"),
]
operations = [
migrations.RunPython(add_sql_language, remove_sql_language),
]