database/gdb: error rollback statement `begin` for mssql2016, should be `begin transaction`
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 只有mssql 2016以后的版本才有这个问题吗?
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@zromet Does this problem only occur in versions after mssql 2016?
不是,应该是所有的sql.我看了源码, 它应该是直接用mysql的事务处理语句,,没有转换成sqlserver的事务处理语句. database/gdb/gdb_core_transaction.go 中
John Guo @.***> 於 2024年9月12日 週四 下午10:08寫道:
@zromet https://github.com/zromet 只有mssql 2016以后的版本才有这个问题吗?
— Reply to this email directly, view it on GitHub https://github.com/gogf/gf/issues/3710#issuecomment-2346408193, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDORPP5U6JM5H3RJBZPYGTZWGN7NAVCNFSM6AAAAABLPWXSRWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBWGQYDQMJZGM . You are receiving this because you were mentioned.Message ID: @.***>
@zromet 这里可能需要把事务的两个关键字提出来作为接口让每个数据库自己实现,可以参考OrderByRandom的实现:https://github.com/gogf/gf/pull/3794
欢迎提交PR一起参与建设。
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:
https://github.com/gogf/gf/commit/c13004e230afeb209d5b113c30b2fe868530ae09
Welcome to submit PR and participate in the construction.
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。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。
mssql 驱动已经处理了 begin 为 begin transcaton,所以此异常可能是由别的原因引起
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
mssql 驱动已经处理了
begin为begin transcaton,所以此异常可能是由别的原因引起
@zromet 请提供可复现该问题的最小可运行代码。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
The mssql driver has processed
beginasbegin transcaton, so this exception may be caused by other reasons
@zromet Please provide minimal runnable code that reproduces the issue.