feat(gbase8s): read create-database locale options from the instance
This commit is contained in:
3 files changed
+50
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { supportsCreateDatabaseCharset, supportsCreateDatabaseLocale } from "@/lib/database/createDatabaseSql";
|
||||
import { DEFAULT_GBASE8S_DATABASE_LOCALE, GBASE8S_DATABASE_LOCALES } from "@/lib/database/createDatabaseCharsetOptions";
|
||||
import { DEFAULT_GBASE8S_DATABASE_LOCALE, defaultGbase8sDatabaseLocale, GBASE8S_DATABASE_LOCALES } from "@/lib/database/createDatabaseCharsetOptions";
|
||||
|
||||
describe("GBase 8s / Informix create-database locale support", () => {
|
||||
it("offers a locale picker only for the gbase8s profile", () => {
|
||||
@@ -22,4 +22,16 @@ describe("GBase 8s / Informix create-database locale support", () => {
|
||||
expect(GBASE8S_DATABASE_LOCALES).toContain("zh_CN.utf8");
|
||||
expect(DEFAULT_GBASE8S_DATABASE_LOCALE).toBe("zh_CN.utf8");
|
||||
});
|
||||
|
||||
it("seeds the default from instance locales reporting the numeric UTF-8 code set", () => {
|
||||
// Real GBase 8s instances report dbs_collate like zh_CN.57372 (57372 = UTF-8) alongside
|
||||
// en_US.819 (ISO-8859-1); after ORDER BY 1 the plain first entry cannot hold CJK.
|
||||
expect(defaultGbase8sDatabaseLocale(["en_US.819", "zh_CN.57372"])).toBe("zh_CN.57372");
|
||||
expect(defaultGbase8sDatabaseLocale(["en_US.819", "zh_CN.utf8"])).toBe("zh_CN.utf8");
|
||||
});
|
||||
|
||||
it("falls back to the first locale or the static default when no UTF-8 option exists", () => {
|
||||
expect(defaultGbase8sDatabaseLocale(["en_US.819"])).toBe("en_US.819");
|
||||
expect(defaultGbase8sDatabaseLocale([])).toBe(DEFAULT_GBASE8S_DATABASE_LOCALE);
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,12 @@ export const CREATE_DATABASE_CHARSET_OPTIONS = ["utf8mb4", "utf8", "gbk", "latin
|
||||
export const GBASE8S_DATABASE_LOCALES = ["zh_CN.utf8", "en_US.utf8", "ja_JP.utf8", "ko_KR.utf8", "zh_CN.gbk", "zh_CN.gb18030", "en_US.819"] as const;
|
||||
export const DEFAULT_GBASE8S_DATABASE_LOCALE = "zh_CN.utf8";
|
||||
|
||||
// Informix-family instances report dbs_collate with the numeric code set (57372 = UTF-8,
|
||||
// 819 = ISO-8859-1) instead of the "utf8" mnemonic, so both spellings must seed the default.
|
||||
export function defaultGbase8sDatabaseLocale(locales: string[]): string {
|
||||
return locales.find((locale) => /(?:utf8|57372)/i.test(locale)) ?? locales[0] ?? DEFAULT_GBASE8S_DATABASE_LOCALE;
|
||||
}
|
||||
|
||||
const FALLBACK_COLLATION_OPTIONS: Record<string, string[]> = {
|
||||
ascii: ["ascii_general_ci", "ascii_bin"],
|
||||
big5: ["big5_chinese_ci", "big5_bin"],
|
||||
|
||||
Reference in new issue
Block a user