fix(sqlserver): 表结构支持查看约束(主键/唯一/外键/检查/默认值) (#9581)
SQL Server 连接的「编辑表结构」面板里只有 DDL/字段/索引/外键/触发器,
没有「约束」页签;用户无法查看某张表的约束。
list_constraints 在 SQL Server 驱动中完全缺失:驱动侧没有对应实现,
dbx-core 的 list_constraints_core 没有 SQL Server 分支,直接落到默认的
空数组;前端 tableMetadataCapabilities 也没有声明 sqlserver 支持,
因此即使是空页签也不会渲染。
- dbx-drivers 新增 list_constraints,用一条 UNION ALL 查询汇总
sys.key_constraints(PK/UNIQUE)、sys.foreign_keys(含引用库表列、
ON UPDATE/DELETE 动作、is_not_trusted)、sys.check_constraints、
sys.default_constraints;列名用 FOR XML PATH('') 聚合,兼容 SQL Server
2008(无 STRING_AGG)
- list_constraints_core 增加 SQL Server 分支与链接服务器早退
- tableMetadataCapabilities 为 sqlserver 打开 constraints,前端显示「约束」页签
- 新增单测覆盖 SQL 形态与列名拆包,并补充前端能力断言
Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
1 parent
ed1881e323
commit
74c275b2ce
6 files changed
+161
-11
No files matched your search
@@ -7694,7 +7694,8 @@ pub async fn list_triggers_core(
|
||||
|
||||
/// Lists structured constraints for a relation. Exposed generically so the
|
||||
/// agent protocol and native drivers share one route; the built-in drivers
|
||||
/// that implement it today are PostgreSQL, OpenGauss, and the Xugu agent.
|
||||
/// that implement it today are PostgreSQL, OpenGauss, SQL Server, and the
|
||||
/// Xugu agent.
|
||||
pub async fn list_constraints_core(
|
||||
state: &AppState,
|
||||
connection_id: &str,
|
||||
@@ -7702,12 +7703,16 @@ pub async fn list_constraints_core(
|
||||
schema: &str,
|
||||
table: &str,
|
||||
) -> Result<Vec<db::ConstraintInfo>, String> {
|
||||
if crate::sql_dialect::parse_sqlserver_linked_schema_ref(schema).is_some() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
retry_metadata_connection(state, connection_id, Some(database), || async {
|
||||
let pool_key = state.get_or_create_metadata_pool_for_session(connection_id, Some(database), None).await?;
|
||||
let db_config = connection_config(state, connection_id).await;
|
||||
|
||||
{
|
||||
let pool_handle = state.pool_handle(&pool_key).await;
|
||||
try_sqlserver!(pool_handle, list_constraints, schema, table);
|
||||
if let Some(client) = extract_pool!(pool_handle.as_ref(), Agent) {
|
||||
let mut client = client.lock().await;
|
||||
return client
|
||||
|
||||
Reference in new issue
Block a user