Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用oracle数据库的在线查询报错 bind variables are not supported in DDL statements #2252

Closed
leon1208 opened this issue Aug 22, 2023 · 12 comments · Fixed by tonyhu214/Archery#1 or #2266

Comments

@leon1208
Copy link

重现步骤

1.选择在线查询
2.选择一个oracle实例
3.选择任何一个schema报错

预期外的结果

cx_Oracle.DatabaseError: DPI-1059: bind variables are not supported in DDL statements
ALTER SESSION SET CURRENT_SCHEMA = 'xxxx' 属于DDL语句,不支持bind variables

日志文本

No response

版本

1.10.0

部署方式

Docker

是否还有其他可以辅助定位问题的信息?比如数据库版本等

oracle.py中的594和673行

@LeoQuote
Copy link
Collaborator

如果知道修正方式的话, 欢迎 pr

@SoHuDrgon
Copy link

俺也遇到了,求大佬解决一下!

@SoHuDrgon
Copy link

我把oracle.py中的594和673行的配置改成下面的:
" ALTER SESSION SET CURRENT_SCHEMA = my_db_name "
我就能查了,不知道啥原理!啊哈哈哈哈!

@tonyhu214
Copy link
Contributor

tonyhu214 commented Aug 24, 2023

@SoHuDrgon @leon1208 @LeoQuote 我们可以使用connection.current_schema=db_name代替 cursor.execute(f' ALTER SESSION SET CURRENT_SCHEMA = "{db_name}" ')

tonyhu214 added a commit to tonyhu214/Archery that referenced this issue Aug 24, 2023
使用connection.current_schema=db_name代替 cursor.execute(f' ALTER SESSION SET CURRENT_SCHEMA = "{db_name}" ')
参考 https://cx-oracle.readthedocs.io/en/latest/api_manual/connection.html?highlight=CURRENT_SCHEMA#Connection.current_schema
但是仅自测 cx-oracle 7.3.0 版本
@SoHuDrgon
Copy link

@tonyhu214 不行啊大佬,改了还是报错!
截屏2023-08-24 11 28 01
下面是报错:
截屏2023-08-24 11 27 33
注释的就可以运行!

tonyhu214 added a commit to tonyhu214/Archery that referenced this issue Aug 24, 2023
@tonyhu214
Copy link
Contributor

@SoHuDrgon oracle.py 文件里面有2行该内容

tonyhu214 added a commit to tonyhu214/Archery that referenced this issue Aug 24, 2023
@tonyhu214 tonyhu214 mentioned this issue Aug 24, 2023
@SoHuDrgon
Copy link

@tonyhu214 对啊,我两个都改了的,但是还是不行的。
截屏2023-08-25 14 24 49
截屏2023-08-25 14 25 14
这我肯定不是骗你的啊!
截屏2023-08-25 14 26 24

@SoHuDrgon
Copy link

@tonyhu214 我使用archery 1.9.1和1.10.0两个镜像测试都是不能查询的。

@tonyhu214
Copy link
Contributor

@SoHuDrgon docker 部署的吗?docker部署的话需要重启容器生效。如果不是docker部署,或许可能是cx-Oracle包的版本问题。pip list installed 看下版本。我的是7.3.0的

@SoHuDrgon
Copy link

好了,谢谢大佬!

LeoQuote pushed a commit that referenced this issue Aug 28, 2023
* fixed #2252

fix #2252

* Update oracle.py

* Update oracle.py

* Update oracle.py

* Update sql_utils.py

* Update oracle.py

fix #2262

* Update oracle.py

* Update oracle.py

* Update sql_utils.py

* Update sql_utils.py

* Update sql_utils.py

* Update oracle.py

* Update oracle.py

* Update oracle.py

* Update oracle.py
@hsjz81
Copy link

hsjz81 commented Jan 23, 2024

Archery-1.10.0报错解决

1、django对应错误
[2024-01-22 18:21:05,903][Thread-5203:140229134350080][task_id:default][oracle.py:700][WARNING]- Oracle 语句执行报错,语句:SELECT table_name
FROM all_tables
WHERE nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
AND OWNER = :db_name AND IOT_NAME IS NULL
AND DURATION IS NULL order by table_name,错误信息Traceback (most recent call last):
File "/app/Archery-1.10.0/sql/engines/oracle.py", line 672, in query
cursor.execute(
cx_Oracle.DatabaseError: DPI-1059: bind variables are not supported in DDL statements

2024-01-22 18:21:05,903 - default - WARNING - Oracle 语句执行报错,语句:SELECT table_name
FROM all_tables
WHERE nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
AND OWNER = :db_name AND IOT_NAME IS NULL
AND DURATION IS NULL order by table_name,错误信息Traceback (most recent call last):
File "/app/Archery-1.10.0/sql/engines/oracle.py", line 672, in query
cursor.execute(
cx_Oracle.DatabaseError: DPI-1059: bind variables are not supported in DDL statements

2、修改Archery-1.10.0/sql/engines/oracle.py
注释掉
cursor.execute(
f" ALTER SESSION SET CURRENT_SCHEMA = :db_name ",
{"db_name": db_name},
)
增加conn.current_schema=db_name
测试验证问题已解决,感谢楼上大侠

具体行数位置

586 def explain_check(self, db_name=None, sql="", close_conn=False):
587 # 使用explain进行支持的SQL语法审核,连接需不中断,防止数据库不断fork进程的大批量消耗
588 result = {"msg": "", "rows": 0}
589 try:
590 conn = self.get_connection()
591 cursor = conn.cursor()
592 if db_name:
593 #cursor.execute(
594 # f" ALTER SESSION SET CURRENT_SCHEMA = :db_name ",
595 # {"db_name": db_name},
596 #)
597 #解决cx_Oracle.DatabaseError: DPI-1059: bind variables are not supported in DDL statements报错
conn.current_schema=db_name

658 def query(
659 self,
660 db_name=None,
661 sql="",
662 limit_num=0,
663 close_conn=True,
664 parameters=None,
665 **kwargs,
666 ):
667 """返回 ResultSet"""
668 result_set = ResultSet(full_sql=sql)
669 try:
670 conn = self.get_connection()
671 cursor = conn.cursor()
672 if db_name:
673 #cursor.execute(
674 # " ALTER SESSION SET CURRENT_SCHEMA = :db_name ",
675 # {"db_name": db_name},
676 #)
677 #解决cx_Oracle.DatabaseError: DPI-1059: bind variables are not supported in DDL statements报错
678 conn.current_schema=db_name
679 sql = sql.rstrip(";")

@xkyang1
Copy link

xkyang1 commented Mar 13, 2024

good !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants