diff --git a/.env.shared b/.env.shared index 2f8d9e4d..5bd20005 100644 --- a/.env.shared +++ b/.env.shared @@ -69,4 +69,4 @@ PLM_ORACLE_PORT=1521 PLM_ORACLE_SID=orcl PLM_ORACLE_USERNAME=PLM PLM_ORACLE_PASSWORD=PLM -ORACLE_CLIENT_LIB_DIR=C:\Users\PC\Desktop\HX工作目录\0509\hxops\backend\oracle_client\instantclient_19_30 +ORACLE_CLIENT_LIB_DIR=oracle_client\instantclient_19_30 diff --git a/backend/app/services/text2sql.py b/backend/app/services/text2sql.py index 8969568f..0a4af12c 100644 --- a/backend/app/services/text2sql.py +++ b/backend/app/services/text2sql.py @@ -16,12 +16,19 @@ class Text2SQLService: def _project_root(cls) -> str: return os.path.dirname(cls._backend_dir()) + @classmethod + def _resolve_project_path(cls, path_value: str) -> str: + normalized = os.path.normpath(path_value) + if os.path.isabs(normalized): + return normalized + return os.path.normpath(os.path.join(cls._project_root(), normalized)) + @classmethod def _find_oracle_client_dir(cls) -> str | None: env_dir = (os.getenv("ORACLE_CLIENT_LIB_DIR") or "").strip() candidate_roots = [] if env_dir: - candidate_roots.append(env_dir) + candidate_roots.append(cls._resolve_project_path(env_dir)) candidate_roots.extend([ os.path.join(cls._backend_dir(), 'oracle_client'), os.path.join(cls._project_root(), 'oracle_client'), @@ -152,8 +159,10 @@ class Text2SQLService: @classmethod def _get_oracle_client_dir(cls) -> str | None: env_dir = (os.getenv("ORACLE_CLIENT_LIB_DIR") or "").strip() - if env_dir and os.path.exists(env_dir): - return env_dir + if env_dir: + resolved_env_dir = cls._resolve_project_path(env_dir) + if os.path.exists(resolved_env_dir): + return resolved_env_dir linux_candidates = [ "/opt/oracle/instantclient",