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

mssql: weird errors when inserting data #5

Closed
GoogleCodeExporter opened this issue Jun 15, 2015 · 4 comments
Closed

mssql: weird errors when inserting data #5

GoogleCodeExporter opened this issue Jun 15, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

I'm using similar code with multiple databases to test insert speed with 
different styles and today I tried odbc. See 
http://play.golang.org/p/dDXXXHmbt5.

For some reason I sometimes see very strange errors with odbc, e.g.:

i=36127: SQLExecute: {23000} [Microsoft][ODBC SQL Server Driver][SQL 
Server]Violation of PRIMARY KEY constraint 'PK__data__3213E83FE4DDA2C7'. Cannot 
insert duplicate key in object 'dbo.data'. The duplicate key value is (36202).
{01000} [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been 
terminated.

i=60976: SQLExecute: {23000} [Microsoft][ODBC SQL Server Driver][SQL 
Server]Violation of PRIMARY KEY constraint 'PK__data__3213E83FE4DDA2C7'. Cannot 
insert duplicate key in object 'dbo.data'. The duplicate key value is (1).
{01000} [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been 
terminated.

Notice that the value sql server complains does not match the value my program 
is using. Another common error is:

i=28339: SQLExecute: {22003} [Microsoft][SQL Server Native Client 11.0]Numeric 
value out of range

i=36229: SQLExecute: {22003} [Microsoft][ODBC SQL Server 
Driver]Числовое значение выходит за пределы 
допустимого диапазона

Russian text also means "The number value is out of range". It seems like maybe 
there's a race in odbc somewhere? Looks almost like underlying ODBC statements 
are sometimes used from another goroutine entirely...

Original issue reported on code.google.com by sna...@gmail.com on 26 Apr 2013 at 4:47

@GoogleCodeExporter
Copy link
Author

OK, I found the problem! In param.go, BindValue assigns values to Data to keep 
it from being GCed, but it doesn't assign values it actually should. For 
example in int64 case it assigns p.Data = d (a copy of int64) when buf is 
pointing to the address of int64. Because of this nothing stops GC from garbage 
collecting the heap int64, so by the time SQLExecute is called all sorts of 
garbage may happen to be there.

Original comment by sna...@gmail.com on 26 Apr 2013 at 5:15

@GoogleCodeExporter
Copy link
Author

I am surprised it worked before! Thank you. Do you want to send the fix?

Alex

Original comment by alex.bra...@gmail.com on 26 Apr 2013 at 5:36

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

https://codereview.appspot.com/9010043/

Original comment by alex.bra...@gmail.com on 29 Apr 2013 at 7:27

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision 62682477fd4e.

Original comment by alex.bra...@gmail.com on 3 May 2013 at 1:58

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant