Escape reserved separator identifiers in MySQL SQL

This commit is contained in:
2026-07-20 17:19:09 +08:00 Unverified
parent 1a87e06fc8
commit a30477bb58
4 changed files with 14 additions and 8 deletions
+6
View File
@@ -4,12 +4,18 @@ import { resolve } from 'node:path';
import assert from 'node:assert/strict';
import ExcelJS from 'exceljs';
import { relationalTables } from '../database.mjs';
import { mysqlSchema } from '../src/database/schema.mjs';
import { buildCenterMaterialsWorkbook, buildWorkbook } from '../excel.mjs';
const root = resolve(process.cwd());
const port = 4182;
const baseUrl = `http://127.0.0.1:${port}`;
const testDb = resolve(root, 'data', 'test-db.sqlite');
const mysqlRuleSchemas = mysqlSchema.filter(statement => /CREATE TABLE IF NOT EXISTS (?:admission_number_rules|number_rules)\b/.test(statement));
assert.equal(mysqlRuleSchemas.length, 2, 'MySQL 应包含两张号码规则表');
for (const statement of mysqlRuleSchemas) {
assert.match(statement, /`separator` VARCHAR\(10\)/, 'MySQL 保留字 separator 必须作为标识符转义');
}
await rm(testDb, { force: true });
await rm(`${testDb}-shm`, { force: true });
await rm(`${testDb}-wal`, { force: true });