fix: address SQL feature code review findings

- Normalize student SQL to end with exactly one semicolon before
  appending the trailing SELECT, so a missing trailing ; no longer
  produces a confusing parse error (sqlTable.ts)
- Remove unused description field from SqlTablePreset and all presets
  (dead data, nothing in the UI reads it)
- Clear output when the candidate table selection changes, so stale
  results from the previous table don't linger (SqlSection.vue)
- Remove stray console.log(props.language) debug statement
  (CodeEditor.vue)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-05 00:16:26 -06:00
parent 62ef50fb76
commit f8e59e9850
4 changed files with 8 additions and 7 deletions

View File

@@ -65,7 +65,6 @@ const langExtension = computed(() => {
}) })
const enhanceAutoCompletion = computed(() => { const enhanceAutoCompletion = computed(() => {
console.log(props.language)
return autocompletion({ return autocompletion({
override: [enhanceCompletion(props.language), completeAnyWord], override: [enhanceCompletion(props.language), completeAnyWord],
}) })

View File

@@ -11,5 +11,6 @@ export function buildSqlScript(studentSql: string) {
const table = const table =
sqlTables.find((item) => item.id === selectedTableId.value) ?? sqlTables.find((item) => item.id === selectedTableId.value) ??
sqlTables[0] sqlTables[0]
return `${table.setupSql}\n\n${studentSql}\n\nSELECT * FROM ${table.tableName};` const normalizedSql = studentSql.trim().replace(/;?\s*$/, ";")
return `${table.setupSql}\n\n${normalizedSql}\n\nSELECT * FROM ${table.tableName};`
} }

View File

@@ -1,7 +1,6 @@
export interface SqlTablePreset { export interface SqlTablePreset {
id: string id: string
label: string label: string
description: string
tableName: string tableName: string
setupSql: string setupSql: string
} }
@@ -63,21 +62,18 @@ export const sqlTables: SqlTablePreset[] = [
{ {
id: "students", id: "students",
label: "学生成绩表", label: "学生成绩表",
description: "适合练习按分数筛选、批量更新、删除不及格记录",
tableName: "students", tableName: "students",
setupSql: studentsSetupSql, setupSql: studentsSetupSql,
}, },
{ {
id: "employees", id: "employees",
label: "员工工资表", label: "员工工资表",
description: "适合练习按部门分组调薪、按入职日期筛选",
tableName: "employees", tableName: "employees",
setupSql: employeesSetupSql, setupSql: employeesSetupSql,
}, },
{ {
id: "products", id: "products",
label: "商品库存表", label: "商品库存表",
description: "适合练习新增商品、调整库存、下架缺货商品",
tableName: "products", tableName: "products",
setupSql: productsSetupSql, setupSql: productsSetupSql,
}, },

View File

@@ -1,6 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue" import { computed, watch } from "vue"
import CodeEditor from "../components/CodeEditor.vue" import CodeEditor from "../components/CodeEditor.vue"
import { output } from "../composables/code"
import { selectedTableId } from "../composables/sqlTable" import { selectedTableId } from "../composables/sqlTable"
import { sqlTables } from "../data/sqlTables" import { sqlTables } from "../data/sqlTables"
import OutputSection from "./OutputSection.vue" import OutputSection from "./OutputSection.vue"
@@ -10,6 +11,10 @@ const selectedTable = computed(
sqlTables.find((table) => table.id === selectedTableId.value) ?? sqlTables.find((table) => table.id === selectedTableId.value) ??
sqlTables[0], sqlTables[0],
) )
watch(selectedTableId, () => {
output.value = ""
})
</script> </script>
<template> <template>