As of this recent commit to https://github.com/denisenkom/go-mssqldb/commit/44cdfe8d8ba9a7322b38cd8fbb0f2cb445e65a69 LastInsertID is no longer supported when using Go 1.0 and later.
Since the GORM mssql dialect depends on go-mssqldb, this causing some issues when using the .Create() ORM method, e.g.:
if newObj := tx.Create(&fakeRecord).Error; err != nil {
app.log.Error("Error creating record: ", newObj.Error)
tx.Rollback()
}
The following error (from go-mssqldb) is logged:
LastInsertId is not supported. Please use the OUTPUT clause or add
select ID = convert(bigint, SCOPE_IDENTITY())to the end of your query.
Perhaps this is something that can be patched using LastInsertIDReturningSuffix?
Hi
Im facing the same issue. For now i manually changed the go-mssqldb package code (downloaded from this commit https://github.com/denisenkom/go-mssqldb/tree/db2462fef53bd29c619fe40f73cbfcc12be79d9f).
Should be a temporary fix until it is patched.
Cheers
@tentone Can you please show what changes you made?
Thanks
I havent changed anything code wise. Just rolled bad manually the package.
You can achieve this by installing dependencies using "go get" as usuall and then go the gopath and replace the go-mssqldb code with the one you downloaded from the link above.
Run "go get" on the go-msqldb directory and youre good to go. This is not a fix its just a temporary workaround.
You can now force that specific version of the mssql driver using golang's new modules dependency manager. Just came out with Go 1.13 Just update to 1.13, add a go.mod file and stick this in there
module (insertprojectpathhere)
go 1.13
require (
github.com/denisenkom/go-mssqldb v0.0.0-20190806190131-db2462fef53b
)
Most helpful comment
I havent changed anything code wise. Just rolled bad manually the package.
You can achieve this by installing dependencies using "go get" as usuall and then go the gopath and replace the go-mssqldb code with the one you downloaded from the link above.
Run "go get" on the go-msqldb directory and youre good to go. This is not a fix its just a temporary workaround.