From 28009d50fd00c4adf8cef6c10434da9a5c6780e5 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Fri, 10 Apr 2026 19:51:50 +0700 Subject: [PATCH] fix: MSSQL login fails with "Unable to determine initial language" (#661) Root cause: C bridge header had wrong FreeTDS constant values. DBSETCHARSET was 7 (actually DBSETNATLANG), DBSETCHARSET is 10. So "UTF-8" was being sent as the language, and no charset was set. Fix: correct all dbsetlname constants to match FreeTDS master/include/sybdb.h, add DBSETNATLANG=7 with "us_english" to the login packet. --- .../MSSQLDriverPlugin/CFreeTDS/include/sybdb.h | 17 +++++++++++------ Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Plugins/MSSQLDriverPlugin/CFreeTDS/include/sybdb.h b/Plugins/MSSQLDriverPlugin/CFreeTDS/include/sybdb.h index e09e109ae..917609597 100644 --- a/Plugins/MSSQLDriverPlugin/CFreeTDS/include/sybdb.h +++ b/Plugins/MSSQLDriverPlugin/CFreeTDS/include/sybdb.h @@ -44,12 +44,17 @@ typedef struct loginrec LOGINREC; #define SYBDATETIMN 111 #define SYBUNIQUE 36 -// Login property constants for dbsetlname() — values verified against FreeTDS 1.4 sybdb.h -#define DBSETHOST 1 -#define DBSETUSER 2 -#define DBSETPWD 3 -#define DBSETAPP 5 // 4 is unused; real FreeTDS DBSETAPP = 5 -#define DBSETCHARSET 7 // Client charset for dbsetlname() — controls string encoding +// Login property constants for dbsetlname() — values from FreeTDS master/include/sybdb.h +#define DBSETHOST 1 +#define DBSETUSER 2 +#define DBSETPWD 3 +#define DBSETAPP 5 +#define DBSETBCP 6 +#define DBSETNATLANG 7 +#define DBSETCHARSET 10 +#define DBSETPACKET 11 +#define DBSETENCRYPT 12 +#define DBSETDBNAME 14 // Convenience macros (match FreeTDS sybdb.h) #define DBSETLHOST(x, y) dbsetlname((x), (y), DBSETHOST) diff --git a/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift b/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift index d31469650..b77115573 100644 --- a/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift +++ b/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift @@ -196,6 +196,7 @@ private final class FreeTDSConnection: @unchecked Sendable { _ = dbsetlname(login, user, Int32(DBSETUSER)) _ = dbsetlname(login, password, Int32(DBSETPWD)) _ = dbsetlname(login, "TablePro", Int32(DBSETAPP)) + _ = dbsetlname(login, "us_english", Int32(DBSETNATLANG)) _ = dbsetlname(login, "UTF-8", Int32(DBSETCHARSET)) _ = dbsetlversion(login, UInt8(DBVERSION_74))