Skip to content

Commit 4e86e4e

Browse files
author
junjie.miao
committed
add support oracle 11g
1 parent ddc58bd commit 4e86e4e

File tree

6 files changed

+138
-28
lines changed

6 files changed

+138
-28
lines changed

db_query/README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Database Query Tools
1616

1717
数据库查询工具
1818

19-
Currently supported database types: mysql, oracle, postgresql, or mssql.
19+
Currently supported database types: mysql, oracle, oracle11g, postgresql, or mssql.
2020

21-
目前支持的数据库类型:mysql、oracle、postgresql、mssql。
21+
目前支持的数据库类型:mysql、oracle、oracle11g、postgresql、mssql。
2222

2323
![db_query](_assets/db_query.png)
2424

@@ -66,7 +66,56 @@ Once this field is added, the Dify platform will allow the installation of all p
6666
添加该字段后,Dify 平台将允许安装所有未在 Dify Marketplace 上架(审核)的插件,可能存在安全隐患。
6767

6868

69-
#### 2. How to install the offline version 如何安装离线版本
69+
#### 2. How to connect to oracle 11g 如何连接Oracle 11g
70+
71+
2.1、下载 oracle11g 的 client,这里下的是 11.2.0.4.0 版本
72+
73+
https://www.oracle.com/database/technologies/instant-client/downloads.html
74+
75+
比如:instantclient-basic-linux.x64-11.2.0.4.0.zip
76+
77+
78+
2.2、上传 oracle 的 client 到宿主机的 dify 的挂载目录
79+
80+
将 instantclient-basic-linux.x64-11.2.0.4.0.zip 解压后的 instantclient_11_2 目录放到 docker/volumes 下面
81+
> 注:需要将 `instantclient_11_2``libclntsh.so.11.1` 改成 `libclntsh.so``libocci.so.11.1` 改成 `libocci.so`
82+
83+
2.3、在 `docker/docker-compose.yml` 中进行配置
84+
```
85+
# 在 plugin_daemon 下,添加一个变量
86+
environment:
87+
......
88+
LD_LIBRARY_PATH: "/root/instantclient_11_2:$LD_LIBRARY_PATH"
89+
```
90+
91+
Red Hat 系(如 CentOS、RHEL)64 位:
92+
```
93+
# 在 plugin_daemon 下,添加三个挂载
94+
volumes:
95+
......
96+
- ./volumes/instantclient_11_2:/root/instantclient_11_2
97+
- /usr/lib64/libaio.so.1.0.1:/usr/lib/x86_64-linux-gnu/libaio.so.1.0.1
98+
- /usr/lib64/libaio.so.1:/usr/lib/x86_64-linux-gnu/libaio.so.1
99+
```
100+
101+
Debian 系(如 Ubuntu)64 位:
102+
```
103+
# 在 plugin_daemon 下,添加三个挂载
104+
volumes:
105+
......
106+
- ./volumes/instantclient_11_2:/root/instantclient_11_2
107+
- /usr/lib/x86_64-linux-gnu/libaio.so.1.0.1:/usr/lib/x86_64-linux-gnu/libaio.so.1.0.1
108+
- /usr/lib/x86_64-linux-gnu/libaio.so.1:/usr/lib/x86_64-linux-gnu/libaio.so.1
109+
```
110+
111+
2.4、重启 plugin_daemon
112+
```shell
113+
docker stop docker-plugin_daemon-1
114+
docker compose up -d plugin_daemon
115+
```
116+
117+
118+
#### 3. How to install the offline version 如何安装离线版本
70119

71120
Scripting tool for downloading Dify plugin package from Dify Marketplace and Github and repackaging [true] offline package (contains dependencies, no need to be connected to the Internet).
72121

db_query/tools/db_util.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from urllib import parse
55
from uuid import UUID
66

7+
import oracledb
78
import pandas as pd
89
from pandas import Timestamp
910
from sqlalchemy import create_engine
@@ -16,25 +17,27 @@ def __init__(self, db_type: str,
1617
host: str, port: Optional[str] = None,
1718
database: Optional[str] = None,
1819
properties: Optional[str] = None) -> None:
19-
self.db_type = db_type
20+
self.db_type = db_type.lower()
2021
self.username = username
2122
self.password = password
2223
self.host = host
2324
self.port = port
2425
self.database = database
2526
self.properties = properties
27+
if self.db_type == 'oracle11g':
28+
# To change from the default python-oracledb Thin mode to Thick mode
29+
oracledb.init_oracle_client()
2630
self.engine = create_engine(self.get_url(), pool_size=100, pool_recycle=36)
2731

2832
def get_driver_name(self):
29-
db_type = self.db_type.lower()
30-
driver_name = db_type
31-
if db_type == 'mysql':
33+
driver_name = self.db_type
34+
if self.db_type == 'mysql':
3235
driver_name = 'mysql+pymysql'
33-
elif db_type == 'oracle':
36+
elif self.db_type in {'oracle', 'oracle11g'}:
3437
driver_name = 'oracle+oracledb'
35-
elif db_type == 'postgresql':
38+
elif self.db_type == 'postgresql':
3639
driver_name = 'postgresql+psycopg2'
37-
elif db_type == 'mssql':
40+
elif self.db_type == 'mssql':
3841
driver_name = 'mssql+pymssql'
3942
return driver_name
4043

@@ -78,8 +81,7 @@ def run_query(self, query_sql: str) -> list[dict]:
7881
return records
7982

8083
def test_sql(self):
81-
db_type = self.db_type.lower()
82-
if db_type == 'oracle':
84+
if self.db_type in {'oracle', 'oracle11g'}:
8385
return "SELECT 1 FROM DUAL"
8486
else:
8587
return "SELECT 1"

db_query/tools/sql_query.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ parameters:
2525
label:
2626
en_US: Oracle
2727
zh_Hans: Oracle
28+
- value: oracle11g
29+
label:
30+
en_US: Oracle11g
31+
zh_Hans: Oracle11g
2832
- value: postgresql
2933
label:
3034
en_US: PostgreSQL
@@ -38,8 +42,8 @@ parameters:
3842
en_US: Database type
3943
zh_Hans: 数据库类型
4044
human_description:
41-
en_US: Used for selecting the database type, mysql, oracle, postgresql or mssql.
42-
zh_Hans: 用于选择数据库类型,mysql、oracle、postgresql或mssql。
45+
en_US: Used for selecting the database type, mysql, oracle, oracle11g, postgresql or mssql.
46+
zh_Hans: 用于选择数据库类型,mysql、oracle、oracle11g、postgresql或mssql。
4347
form: llm
4448
- name: db_host
4549
type: string

db_query_pre_auth/README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Database Query Tools (Pre-authorization)
1616

1717
数据库查询工具(预授权)
1818

19-
Currently supported database types: mysql, oracle, postgresql, or mssql.
19+
Currently supported database types: mysql, oracle, oracle11g, postgresql, or mssql.
2020

21-
目前支持的数据库类型:mysql、oracle、postgresql、mssql。
21+
目前支持的数据库类型:mysql、oracle、oracle11g、postgresql、mssql。
2222

2323
![db_query_pre_auth](_assets/db_query_pre_auth.png)
2424

@@ -64,7 +64,56 @@ Once this field is added, the Dify platform will allow the installation of all p
6464
添加该字段后,Dify 平台将允许安装所有未在 Dify Marketplace 上架(审核)的插件,可能存在安全隐患。
6565

6666

67-
#### 2. How to install the offline version 如何安装离线版本
67+
#### 2. How to connect to oracle 11g 如何连接Oracle 11g
68+
69+
2.1、下载 oracle11g 的 client,这里下的是 11.2.0.4.0 版本
70+
71+
https://www.oracle.com/database/technologies/instant-client/downloads.html
72+
73+
比如:instantclient-basic-linux.x64-11.2.0.4.0.zip
74+
75+
76+
2.2、上传 oracle 的 client 到宿主机的 dify 的挂载目录
77+
78+
将 instantclient-basic-linux.x64-11.2.0.4.0.zip 解压后的 instantclient_11_2 目录放到 docker/volumes 下面
79+
> 注:需要将 `instantclient_11_2``libclntsh.so.11.1` 改成 `libclntsh.so``libocci.so.11.1` 改成 `libocci.so`
80+
81+
2.3、在 `docker/docker-compose.yml` 中进行配置
82+
```
83+
# 在 plugin_daemon 下,添加一个变量
84+
environment:
85+
......
86+
LD_LIBRARY_PATH: "/root/instantclient_11_2:$LD_LIBRARY_PATH"
87+
```
88+
89+
Red Hat 系(如 CentOS、RHEL)64 位:
90+
```
91+
# 在 plugin_daemon 下,添加三个挂载
92+
volumes:
93+
......
94+
- ./volumes/instantclient_11_2:/root/instantclient_11_2
95+
- /usr/lib64/libaio.so.1.0.1:/usr/lib/x86_64-linux-gnu/libaio.so.1.0.1
96+
- /usr/lib64/libaio.so.1:/usr/lib/x86_64-linux-gnu/libaio.so.1
97+
```
98+
99+
Debian 系(如 Ubuntu)64 位:
100+
```
101+
# 在 plugin_daemon 下,添加三个挂载
102+
volumes:
103+
......
104+
- ./volumes/instantclient_11_2:/root/instantclient_11_2
105+
- /usr/lib/x86_64-linux-gnu/libaio.so.1.0.1:/usr/lib/x86_64-linux-gnu/libaio.so.1.0.1
106+
- /usr/lib/x86_64-linux-gnu/libaio.so.1:/usr/lib/x86_64-linux-gnu/libaio.so.1
107+
```
108+
109+
2.4、重启 plugin_daemon
110+
```shell
111+
docker stop docker-plugin_daemon-1
112+
docker compose up -d plugin_daemon
113+
```
114+
115+
116+
#### 3. How to install the offline version 如何安装离线版本
68117

69118
Scripting tool for downloading Dify plugin package from Dify Marketplace and Github and repackaging [true] offline package (contains dependencies, no need to be connected to the Internet).
70119

db_query_pre_auth/provider/db_query.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ credentials_for_provider:
2929
label:
3030
en_US: Oracle
3131
zh_Hans: Oracle
32+
- value: oracle11g
33+
label:
34+
en_US: Oracle11g
35+
zh_Hans: Oracle11g
3236
- value: postgresql
3337
label:
3438
en_US: PostgreSQL
@@ -42,8 +46,8 @@ credentials_for_provider:
4246
en_US: Database type
4347
zh_Hans: 数据库类型
4448
help:
45-
en_US: Used for selecting the database type, mysql, oracle, postgresql or mssql.
46-
zh_Hans: 用于选择数据库类型,mysql、oracle、postgresql或mssql。
49+
en_US: Used for selecting the database type, mysql, oracle, oracle11g, postgresql or mssql.
50+
zh_Hans: 用于选择数据库类型,mysql、oracle、oracle11g、postgresql或mssql。
4751
db_host:
4852
type: text-input
4953
required: true

db_query_pre_auth/tools/db_util.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from urllib import parse
55
from uuid import UUID
66

7+
import oracledb
78
import pandas as pd
89
from pandas import Timestamp
910
from sqlalchemy import create_engine
@@ -16,25 +17,27 @@ def __init__(self, db_type: str,
1617
host: str, port: Optional[str] = None,
1718
database: Optional[str] = None,
1819
properties: Optional[str] = None) -> None:
19-
self.db_type = db_type
20+
self.db_type = db_type.lower()
2021
self.username = username
2122
self.password = password
2223
self.host = host
2324
self.port = port
2425
self.database = database
2526
self.properties = properties
27+
if self.db_type == 'oracle11g':
28+
# To change from the default python-oracledb Thin mode to Thick mode
29+
oracledb.init_oracle_client()
2630
self.engine = create_engine(self.get_url(), pool_size=100, pool_recycle=36)
2731

2832
def get_driver_name(self):
29-
db_type = self.db_type.lower()
30-
driver_name = db_type
31-
if db_type == 'mysql':
33+
driver_name = self.db_type
34+
if self.db_type == 'mysql':
3235
driver_name = 'mysql+pymysql'
33-
elif db_type == 'oracle':
36+
elif self.db_type in {'oracle', 'oracle11g'}:
3437
driver_name = 'oracle+oracledb'
35-
elif db_type == 'postgresql':
38+
elif self.db_type == 'postgresql':
3639
driver_name = 'postgresql+psycopg2'
37-
elif db_type == 'mssql':
40+
elif self.db_type == 'mssql':
3841
driver_name = 'mssql+pymssql'
3942
return driver_name
4043

@@ -78,8 +81,7 @@ def run_query(self, query_sql: str) -> list[dict]:
7881
return records
7982

8083
def test_sql(self):
81-
db_type = self.db_type.lower()
82-
if db_type == 'oracle':
84+
if self.db_type in {'oracle', 'oracle11g'}:
8385
return "SELECT 1 FROM DUAL"
8486
else:
8587
return "SELECT 1"

0 commit comments

Comments
 (0)