fix: list/search quickSearch 参数名修正 + SQL 方言友好报错 + E071 传输请求改 IN

- list_objects: maxrow/name/type 改为 operation=quickSearch/query/maxResults/objectType,
  并剥离 NW 7.40/7.50 quickSearch name 里的本地化类型标签(如 "ZCL_FOO (Class)")
- query_table_data: HTTP 400 转抛 SapCliError,说明方言限制(WHERE 仅 IN/LIKE),不再打堆栈
- _query_transport_request: E071 查询 WHERE 改用 IN(...),区分「无」与「无法获取」
This commit is contained in:
吴让宇
2026-09-11 01:52:35 +08:00
parent d0d65db137
commit 53ea2d854d
6 changed files with 69 additions and 13 deletions
+7 -1
View File
@@ -6,7 +6,7 @@ import logging
import xml.etree.ElementTree as ET
from typing import Any
from sapcli.exceptions import CreateError, DeleteError
from sapcli.exceptions import CreateError, DeleteError, SapCliError
from sapcli.types import ObjectTypeConfig, get_type_config
logger = logging.getLogger("sapcli.client")
@@ -839,6 +839,12 @@ class DdicMixin:
logger.info("QUERY TABLE DATA: POST %s sql=%s maxRows=%d", url, sql[:80], max_rows)
resp = self.session.post(url, headers=hdrs, params=params, data=sql.encode("utf-8"))
logger.info("QUERY TABLE DATA RESPONSE: HTTP %s", resp.status_code)
if resp.status_code == 400:
raise SapCliError(
"ADT Data Preview 拒绝该 SQLHTTP 400)。本系统 SQL 方言限制:"
"WHERE 只支持 IN(...) / LIKE '...',不支持 '='SELECT 列表必须逗号分隔。"
"请改用 IN / LIKE 重试。"
)
resp.raise_for_status()
root = ET.fromstring(resp.content)
+13 -9
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
import re
import xml.etree.ElementTree as ET
from sapcli.exceptions import SapCliError
@@ -10,6 +11,11 @@ from sapcli.exceptions import SapCliError
logger = logging.getLogger("sapcli.client")
def _strip_type_label(name: str) -> str:
"""剥离 NW 7.40/7.50 quickSearch 名称里的本地化类型标签(如 ``ZCL_FOO (Class)``)。"""
return re.sub(r"\s*\(.*$", "", name).strip()
class SearchMixin:
"""Object search, where-used listing, and source-code search."""
@@ -30,15 +36,13 @@ class SearchMixin:
列表,每项含 ``name``, ``type``, ``description``, ``package``。
"""
url = f"{self.host}/sap/bc/adt/repository/informationsystem/search"
params: dict[str, str] = {"maxrow": "200"}
params: dict[str, str] = {
"operation": "quickSearch",
"query": prefix or "*",
"maxResults": "200",
}
if obj_type:
params["type"] = obj_type
if prefix:
params["name"] = prefix
else:
params["name"] = "*"
if package:
params["pkg"] = package
params["objectType"] = obj_type
hdrs = self._headers()
hdrs["Accept"] = "application/xml"
@@ -51,7 +55,7 @@ class SearchMixin:
results: list[dict[str, str]] = []
core_ns = "http://www.sap.com/adt/core"
for ref in root.findall(f".//{{{core_ns}}}objectReference"):
name = ref.attrib.get(f"{{{core_ns}}}name", "")
name = _strip_type_label(ref.attrib.get(f"{{{core_ns}}}name", ""))
otype = ref.attrib.get(f"{{{core_ns}}}type", "")
desc = ref.attrib.get(f"{{{core_ns}}}description", "")
pkg = ref.attrib.get(f"{{{core_ns}}}package", "")