25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(xugu): match primary keys across catalog case
t8y2f5113def389c
diff --git a/agents/drivers/xugu/main.go b/agents/drivers/xugu/main.goindex 3eb7192c1b..fd69e91068 100644--- a/agents/drivers/xugu/main.go+++ b/agents/drivers/xugu/main.go@@ -2765,7 +2765,7 @@ func (s *server) getColumns(schema, table string) ([]columnInfo, error) {item.DataType = normalizeXuguColumnType(item.DataType, varying)item.IsNullable = !truthy(notNull)item.DefaultOnNull = xuguInt(onNull)- item.IsPrimaryKey = primaryKeys[item.Name]+ item.IsPrimaryKey = xuguPrimaryKeyMatches(item.Name, primaryKeys)item.NumericPrecision, item.NumericScale, item.CharacterMaximumLength = decodeXuguScale(item.DataType, scale)result = append(result, item)}@@ -2802,7 +2802,7 @@ func (s *server) columnsFromSelect(schema, table string, primaryKeys map[string]item := columnInfo{Name: columnType.Name(),DataType: columnType.DatabaseTypeName(),- IsPrimaryKey: primaryKeys[columnType.Name()],+ IsPrimaryKey: xuguPrimaryKeyMatches(columnType.Name(), primaryKeys),}if nullable, ok := columnType.Nullable(); ok {item.IsNullable = nullable@@ -2860,6 +2860,24 @@ func (s *server) primaryKeyColumns(schema, table string) (map[string]bool, errorreturn result, rows.Err()}+// Xugu may report an unquoted primary-key name with a different case from+// ALL_COLUMNS (for example, DEFINE contains "ID" while COL_NAME is "id").+// Exact matches always win so quoted identifiers that differ only by case stay+// distinct; a case-insensitive fallback is used only when it identifies one+// primary-key column.+func xuguPrimaryKeyMatches(columnName string, primaryKeys map[string]bool) bool {+ if primaryKeys[columnName] {+ return true+ }+ matches := 0+ for primaryKey := range primaryKeys {+ if strings.EqualFold(primaryKey, columnName) {+ matches+++ }+ }+ return matches == 1+}+func (s *server) listIndexes(schema, table string) ([]indexInfo, error) {catalogSchema, catalogTable, err := s.resolveCatalogTableName(schema, table)if err != nil {diff --git a/agents/drivers/xugu/main_test.go b/agents/drivers/xugu/main_test.goindex 7692905556..74c19e7aea 100644--- a/agents/drivers/xugu/main_test.go+++ b/agents/drivers/xugu/main_test.go@@ -949,6 +949,23 @@ func TestGetColumnsFallsBackWhenOnNullMetadataIsUnavailable(t *testing.T) {}}+func TestXuguPrimaryKeyMatchesColumnCaseWhenCatalogsDisagree(t *testing.T) {+ primaryKeys := map[string]bool{"ID": true}+ if !xuguPrimaryKeyMatches("id", primaryKeys) {+ t.Fatal("expected an unquoted primary key to match the column despite case differences")+ }+ if !xuguPrimaryKeyMatches("ID", primaryKeys) {+ t.Fatal("expected an exact primary-key match")+ }+}++func TestXuguPrimaryKeyMatchingDoesNotGuessAmbiguousCase(t *testing.T) {+ primaryKeys := map[string]bool{"ID": true, "id": true}+ if xuguPrimaryKeyMatches("Id", primaryKeys) {+ t.Fatal("must not choose between primary-key names that differ only by case")+ }+}+func TestIndexSQLUsesLowPrivilegeDictionary(t *testing.T) {sqlText := strings.ToUpper(xuguListIndexesSQL)