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

database/gdb: error rollback statement begin for mssql2016, should be begin transaction #3710

Open
zromet opened this issue Jul 26, 2024 · 10 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted need more details

Comments

@zromet
Copy link

zromet commented Jul 26, 2024

Go version

go 1.22

GoFrame version

2.7.2

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

语句示例:

 err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
	_, err := tx.Ctx(ctx).Insert("TEST", g.Map{"key": "500.00"})
	return err
})

如插入数据不符表规则(key字段定义为int)时:
控制台报错 Error: mssql: 在将 nvarchar 值 '500.00' 转换成数据类型 int 时失败。 (这是期望报错)
除这以外 又报错 Error: mssql: ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。(非期望报错)
此时返回前端的err 为 第二条(非期望报错),

数据库为SQL2016 它的事务定义开始为 BEGIN TRANSACTION 而非mysql 的 BEGIN

What did you see happen?

事务中 插入语句报错

What did you expect to see?

返回报错 Error: mssql: 在将 nvarchar 值 '500.00' 转换成数据类型 int 时失败

@zromet zromet added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jul 26, 2024
@gqcn
Copy link
Member

gqcn commented Sep 12, 2024

@zromet 只有mssql 2016以后的版本才有这个问题吗?

@gqcn gqcn changed the title os/gtime: 使用MSSQL处理事务回滚时报错ROLLBACK: mssql: ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。 database/gdb: error rollback statement begin for mssql2016, should be begin transaction Sep 12, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@zromet Does this problem only occur in versions after mssql 2016?

@zromet
Copy link
Author

zromet commented Sep 15, 2024 via email

@gqcn
Copy link
Member

gqcn commented Sep 25, 2024

@zromet 这里可能需要把事务的两个关键字提出来作为接口让每个数据库自己实现,可以参考OrderByRandom的实现:#3794

欢迎提交PR一起参与建设。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@zromet It may be necessary to propose the two keywords of the transaction as an interface for each database to implement itself. You can refer to the implementation of OrderByRandom:
c13004e

Welcome to submit PR and participate in the construction.

Copy link

Hello @zromet. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @zromet。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

@oldme-git oldme-git assigned gqcn and oldme-git and unassigned gqcn and oldme-git Sep 26, 2024
@oldme-git
Copy link
Member

mssql 驱动已经处理了 beginbegin transcaton,所以此异常可能是由别的原因引起

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The mssql driver has processed begin as begin transcaton, so this exception may be caused by other reasons

@gqcn
Copy link
Member

gqcn commented Oct 5, 2024

mssql 驱动已经处理了 beginbegin transcaton,所以此异常可能是由别的原因引起

@zromet 请提供可复现该问题的最小可运行代码。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The mssql driver has processed begin as begin transcaton, so this exception may be caused by other reasons

@zromet Please provide minimal runnable code that reproduces the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted need more details
Projects
None yet
Development

No branches or pull requests

4 participants