fix(mssql): add column/table comment support and fix Chinese encoding issue#3022
Open
yunshaochu wants to merge 1 commit into
Open
fix(mssql): add column/table comment support and fix Chinese encoding issue#3022yunshaochu wants to merge 1 commit into
yunshaochu wants to merge 1 commit into
Conversation
1. table_simple_info: rewrite to reuse get_table_names/get_columns, now includes column comments and table comments in output. 2. get_columns: LEFT JOIN sys.extended_properties to read column comments (MS_Description). Add get_table_comment() method. 3. Fix GBK encoding: MSSQL may return Chinese characters encoded as Latin-1/GBK. Add _transform_val() with latin-1→gbk transcoding, override _query() and query_ex() to apply it.
Aries-ckt
approved these changes
Apr 17, 2026
Aries-ckt
left a comment
Collaborator
There was a problem hiding this comment.
LGTM.Thanks for your contribution.
Collaborator
|
@yunshaochu Thanks for your contribution, please fix code quality with command |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix two issues with the MSSQL connector (
MSSQLConnector):1. Column and table comments cannot be read from MSSQL
MSSQL stores comments as extended properties (
MS_Descriptioninsys.extended_properties), but the originalget_columns()method only queriedINFORMATION_SCHEMA.COLUMNSwhich does not include them. This caused DB-GPT's NL2SQL to miss important schema context (e.g., column descriptions like "客户编号", "订单金额"), reducing SQL generation accuracy for Chinese-named databases.Changes:
get_columns(): AddedLEFT JOIN sys.extended_propertiesto read column comments (MS_Description)get_table_comment(): Reads table-level comments fromsys.extended_propertiestable_simple_info(): Rewritten to reuseget_table_names()/get_columns(), now includes column comments and table comments in output.decode("utf-8") if isinstance(x, bytes) else xwith_decode_if_bytes()helper2. Chinese characters displayed as garbled text (mojibake)
When MSSQL server uses GBK encoding, Chinese characters are returned as Latin-1 encoded GBK strings, causing garbled output in query results and schema information.
Fix: Added
_transform_val()that transcodeslatin-1 → gbk, and overrode_query()andquery_ex()to apply the transformation to all query results.How Has This Been Tested?
我是大家庭,超级变变变,我是大聪明)get_columns()now returns column comments fromMS_Descriptionextended propertiesget_table_comment()correctly reads table-level commentstable_simple_info()output includes comments:dbo.A1(B1(客户编号),B2(客户姓名),...) COMMENT[客户信息表]_transform_val()transcodingmake fmt,make fmt-check— all passedSnapshots:
Before fix -
get_columns()output (no comments, garbled):{"name": "B1", "type": "int", "comment": None} # Missing comment # Chinese query results: ¿¿¿ (garbled)After fix -
get_columns()output (with comments, correct encoding):{"name": "B1", "type": "int", "comment": "客户编号"} # Comment read correctly # Chinese query results: 客户编号 (correct)table_simple_info()output:Checklist: