Documentation
¶
Overview ¶
Package turkish provides normalization utilities for Turkish character handling in legacy MSSQL databases.
Background ¶
Many Turkish ERP systems (e.g. Logo, Netsis, Mikro) store text data in varchar/char columns with Turkish_CI_AS (Windows-1254 / code page 1254) collation. These systems typically store names in uppercase ASCII:
"HÜSEYIN" → "HUSEYIN" "İSTANBUL" → "ISTANBUL"
When an AI assistant generates a query like:
SELECT * FROM MUSTERI WHERE ADI = 'Hüseyin'
the database may return zero results because it performs a byte-level comparison and "Hüseyin" ≠ "HUSEYIN" even with CI (case-insensitive) collation when the character encoding differs.
What this package provides ¶
NormalizeSQLLiterals – rewrites Turkish characters inside SQL single-quoted string literals to their ASCII uppercase equivalents before the query is sent.
ToASCIIUpper – converts an arbitrary string to uppercase ASCII by replacing every Turkish character with its closest ASCII counterpart.
FixMojibake – corrects the most common mojibake pattern that occurs when Windows-1254 (Turkish) encoded bytes are mistakenly decoded as Windows-1252 (Western European / Latin-1 superset). This can happen with older ODBC/JDBC bridges or misconfigured data pipelines.
FixResultValue – convenience wrapper for FixMojibake that accepts any interface{} value (string or []byte) and returns the fixed value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixMojibake ¶
FixMojibake corrects strings where Windows-1254 (Turkish) encoded bytes were mistakenly decoded as Windows-1252 (Western European / Latin-1 superset).
Apply this to query result strings when you see Latin characters like Ð, Ý, Þ, ð, ý, þ in positions where Turkish characters (Ğ, İ, Ş, ğ, ı, ş) are expected.
This is a targeted, heuristic fix. It does not use full re-encoding because Go strings are already UTF-8 by the time the result is returned from the database driver; we can only correct the characters we know are wrong.
If you need full re-encoding, use the golang.org/x/text/encoding/charmap package directly.
Examples:
FixMojibake("ÝSTANbul") → "İSTANbul"
FixMojibake("HüSEYÝN") → "HüSEYİN" (non-Turkish chars are untouched)
FixMojibake("SAÐLIK") → "SAĞLIK"
func FixResultValue ¶
FixResultValue applies FixMojibake to string-typed database result values. Other value types (int, float64, time.Time, nil, etc.) are returned unchanged.
This function is intended to be called inside the result-row scanning loop of the MSSQL adapter when normalize_turkish is enabled.
func NormalizeSQLLiterals ¶
NormalizeSQLLiterals rewrites single-quoted SQL string literals so that Turkish characters inside them are converted to their ASCII uppercase equivalents.
This is the primary entry-point for the query normalization middleware. It transforms queries generated by an AI assistant into a form that is compatible with old Turkish ERP databases that store data as uppercase ASCII.
Only the contents of string literals are modified — SQL keywords, column names, and the rest of the query syntax are left completely untouched.
Examples:
Input: SELECT * FROM MUSTERI WHERE ADI = 'Hüseyin' Output: SELECT * FROM MUSTERI WHERE ADI = 'HUSEYIN' Input: SELECT * FROM URUN WHERE ACIKLAMA LIKE '%şeker%' Output: SELECT * FROM URUN WHERE ACIKLAMA LIKE '%SEKER%' Input: SELECT * FROM SEHIR WHERE AD = 'İstanbul' OR AD = 'Çanakkale' Output: SELECT * FROM SEHIR WHERE AD = 'ISTANBUL' OR AD = 'CANAKKALE'
func ToASCIIUpper ¶
ToASCIIUpper converts s to uppercase and replaces all Turkish-specific characters with their ASCII equivalents.
Useful for generating normalized display values or search keys outside of a full SQL query context.
Examples:
ToASCIIUpper("Hüseyin") → "HUSEYIN"
ToASCIIUpper("İstanbul") → "ISTANBUL"
ToASCIIUpper("çiçek") → "CICEK"
Types ¶
This section is empty.