yunqian-c9 commented on issue #12759:
URL: 
https://github.com/apache/shardingsphere/issues/12759#issuecomment-939647924


   @strongduanmu 
   
   我抓包查看了 **sqlalchemy** 在执行业务代码时,向 **mysql** 发送的语句。**sqlalchemy** 是通过设置 
`autocommit = 0` 让当前会话保持事务运行的,在对接原生MYSQL时,是没问题的,全部语句都会在 **commit** 
时提交,**rollback** 时回退。但是 **shardingsphere** 在碰到 **rollback** 
时,之后的SQL语句即便还在同一个会话中,都会重新变为自动提交。以下为测试结果:
   _I took a look at the statements that SQLAlchemy sent to mysql when 
executing business code. Sqlalchemy set autocommit = 0 to keep the current 
session running transactionally. This is not a problem when connecting to 
native MYSQL. All statements will be committed at COMMIT and rollback. However, 
when ShardingSphere encounters ROLLBACK, subsequent SQL statements will revert 
to auto-commit even if they are still in the same session. The test results are 
as follows:_
   
   **sqlalchemy** 会在执行业务语句时,会在上下文中执行 **rollback** 
语句,我尝试去找有没有相关配置可以关闭这个行为,但没有找到,除非重写相关代码:
   _Sqlalchemy will execute a ROLLBACK statement in the context of a business 
statement. I tried to find a configuration to turn this behavior off, but could 
not find it unless I overwrote the code:_
   
   
![1633918120(1)](https://user-images.githubusercontent.com/30698152/136726824-9159e8d6-f487-49a8-851e-abaf5c6ad81b.jpg)
   
   **sqlalchemy 源码:**
   _Sqlalchemy source_
   
   
![Snipaste_2021-10-11_10-04-28](https://user-images.githubusercontent.com/30698152/136726840-b3d85ac8-5035-49f2-aca7-82893751d3b7.png)
   
   **Mysql 测试 autocommit 结果:**
   _Mysql tests autocommit results_
   
   
![Snipaste_2021-10-11_10-13-14](https://user-images.githubusercontent.com/30698152/136726972-c5ded11e-58c5-4b04-9ee7-f0ef1b1e077b.png)
   
   **shardingsphere 测试 autocommit 结果:**
   _Shardingsphere  tests autocommit results_
   
   
![Snipaste_2021-10-11_10-15-53](https://user-images.githubusercontent.com/30698152/136727014-96e82fb4-25ae-49de-b983-8d285164ae96.png)
   
   
![Snipaste_2021-10-11_10-25-18](https://user-images.githubusercontent.com/30698152/136727035-ed60d0f5-7199-4f90-aa36-a99a784cff5c.png)
   
   
   另外我这边尝试过在命令行测试 begin开启事务,但我这边必须要 commit 后才能看到插入的数据,跟您那边不一致,请问是配置问题么?
   _In addition, I have tried to start the transaction with begin in the 
command line test, but I can only see the inserted data after COMMIT, which is 
inconsistent with yours. Is there a configuration problem?_
   
   
![begin](https://user-images.githubusercontent.com/30698152/136727179-dbe0c157-c319-4b49-8a5c-35dbbe46ec5c.png)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to