Open Fank opened 6 years ago
BTW Because i received There is no generated identity value
multiple times, hope this will fix this.
We went over this before in a PR ( https://github.com/denisenkom/go-mssqldb/pull/246#issuecomment-292509157 ). Yes, APIs have this Last insert concept. But it just doesn't map well to SQL Server. I would highly recommend not using it.
In Go1.10 on a recent version of this driver it may be impossible now that we have a sane connection reset policy in place.
You should disable this func (return only error) so people will stop using it, because currently it does work at all.
I've updated the README. https://github.com/denisenkom/go-mssqldb/blob/master/README.md#important-notes .
Fair point. I'll do that soon.
@denisenkom Thoughts?
I vote for disabling of Result.LastInsertId. Is there a way to mark this method as deprecated? I would keep it as deprecated for about a year and then remove, to avoid breaking users without notice.
I just blew half a day on this so I vote for always throwing an error as well.
Let's at least emit an error for go1.10+.
I would recommend something like this, as error text:
Due a context issue T-SQL does not support LastInsertId
.
You should use SCOPE_IDENTITY()
, an example can be found here (godoc link, with example)
https://github.com/denisenkom/go-mssqldb/blob/master/mssql.go#L777
https://docs.microsoft.com/en-us/sql/t-sql/functions/scope-identity-transact-sql
SCOPE_IDENTITY
is not affected by trigger on the table.