```
refactor(db): 优化事务错误状态管理 - 添加 txFailed 指针字段用于跟踪事务内SQL执行状态 - 确保事务错误状态在 HoTimeDB 实例间正确共享 - 当事务内SQL出错时强制回滚以维护数据一致性 ```
This commit is contained in:
@@ -38,6 +38,7 @@ type HoTimeDB struct {
|
|||||||
testMu *sync.Mutex // 保护 testTx 单连接不被并发访问
|
testMu *sync.Mutex // 保护 testTx 单连接不被并发访问
|
||||||
testLogBuf *bytes.Buffer // 测试模式:SQL 日志写入此 buffer 而非直接打印,失败时才输出
|
testLogBuf *bytes.Buffer // 测试模式:SQL 日志写入此 buffer 而非直接打印,失败时才输出
|
||||||
testLogBufMu sync.Mutex // 保护 testLogBuf 并发写入
|
testLogBufMu sync.Mutex // 保护 testLogBuf 并发写入
|
||||||
|
txFailed *bool // 事务内是否有SQL出错,出错则事务必须回滚(指针确保按值传递 HoTimeDB 时状态共享)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConnect 设置数据库配置连接
|
// SetConnect 设置数据库配置连接
|
||||||
|
|||||||
Reference in New Issue
Block a user