{"action":"created","issue":{"url":"https://api.github.com/repos/siddontang/go-mysql/issues/26","labels_url":"https://api.github.com/repos/siddontang/go-mysql/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/siddontang/go-mysql/issues/26/comments","events_url":"https://api.github.com/repos/siddontang/go-mysql/issues/26/events","html_url":"https://github.com/siddontang/go-mysql/issues/26","id":125520811,"number":26,"title":"Getting unsigned values for INT column","user":{"login":"karmakaze","id":318225,"avatar_url":"https://avatars.githubusercontent.com/u/318225?v=3","gravatar_id":"","url":"https://api.github.com/users/karmakaze","html_url":"https://github.com/karmakaze","followers_url":"https://api.github.com/users/karmakaze/followers","following_url":"https://api.github.com/users/karmakaze/following{/other_user}","gists_url":"https://api.github.com/users/karmakaze/gists{/gist_id}","starred_url":"https://api.github.com/users/karmakaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karmakaze/subscriptions","organizations_url":"https://api.github.com/users/karmakaze/orgs","repos_url":"https://api.github.com/users/karmakaze/repos","events_url":"https://api.github.com/users/karmakaze/events{/privacy}","received_events_url":"https://api.github.com/users/karmakaze/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-08T01:12:29Z","updated_at":"2016-01-08T04:04:03Z","closed_at":null,"body":"Set up to use row-format replication from MySQL 5.6.5, I'm getting large positive values in place of small negative ones for a column defined as INT which should be 32-bit signed. Here's a part of the debug log:\r\n```\r\n2016/01/07 20:04:27 [DEBUG] === UpdateRowsEventV2 ===\r\nDate: 2016-01-07 15:48:58\r\nLog position: 1007\r\nEvent size: 72\r\nTableID: 74\r\nFlags: 1\r\nColumn count: 4\r\nValues:\r\n--\r\n0:566\r\n1:2379\r\n2:4294967295\r\n3:\"2016-01-07 15:44:32\"\r\n--\r\n0:566\r\n1:2379\r\n2:4294967294\r\n3:\"2016-01-07 15:44:32\"\r\n```\r\nThe column '2' value was changed from -1 (received as 4294967295) to -2 (received as 4294967294).\r\nI looked at the TableMapEvent for this table and didn't see anywhere that an unsigned 'meta' bit was set.\r\n\r\nI even changed the schema of column '1' to be unsigned and I still didn't see any unsigned 'meta' bit in the debug output. There's a lot of binary data and it's possible I missed it, but the first case of an INT field -1 => -2 being reported as 4294967295 => 4294967294 stands."},"comment":{"url":"https://api.github.com/repos/siddontang/go-mysql/issues/comments/169887516","html_url":"https://github.com/siddontang/go-mysql/issues/26#issuecomment-169887516","issue_url":"https://api.github.com/repos/siddontang/go-mysql/issues/26","id":169887516,"user":{"login":"karmakaze","id":318225,"avatar_url":"https://avatars.githubusercontent.com/u/318225?v=3","gravatar_id":"","url":"https://api.github.com/users/karmakaze","html_url":"https://github.com/karmakaze","followers_url":"https://api.github.com/users/karmakaze/followers","following_url":"https://api.github.com/users/karmakaze/following{/other_user}","gists_url":"https://api.github.com/users/karmakaze/gists{/gist_id}","starred_url":"https://api.github.com/users/karmakaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karmakaze/subscriptions","organizations_url":"https://api.github.com/users/karmakaze/orgs","repos_url":"https://api.github.com/users/karmakaze/repos","events_url":"https://api.github.com/users/karmakaze/events{/privacy}","received_events_url":"https://api.github.com/users/karmakaze/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T04:04:03Z","updated_at":"2016-01-08T04:04:03Z","body":"I think what's going on here is with binary replication the 'bits' are meant to be transferred and applied, as signed/unsigned have the same bit pattern, no problem. What the library is doing is being helpful returning int64 for all integral types to reduce the number of type cases to handle. Where this goes off is widening an 8, 16, 24, or 32 signed value.\r\n\r\ne.g. `return int64(binary.LittleEndian.Uint32(data))` will return values like 4294967295 for -1.\r\n\r\nI tested some changes in a fork to always sign-extend while widening (even for the INT24 case to int32 then int64). This worked much better.\r\n\r\nI continued on to then return the various int8 thru int64 interface{} types meaning the user will need to expect these. The advantage is that there's no possibility of data mangling (-1 -> 4294967295) and if you want the unsigned version a cast will convert.\r\n\r\nI'll see about making a Pull Request to see this. My branch has import package renaming (not yet using Go 1.5 vendor'ing feature) that needs to be tidied before I do so.\r\n\r\nNote: There might be a similar issue with date handling for (negative) dates before Jan. 1, 1970, but I didn't really look into that."}}