Closed rafiulgits closed 2 years ago
reverted, tinyint
equals int8
, but size 15 will choose tinyint
which will overflow?
but one more issue still happening,
when I define a model like this
ProductID int `gorm:"type:int;not null"`
sql server database migration make it bigint
automatically.
Whereas for type:tinyint
, type:smallint
, type:bigint
are working perfectly.
Can you describe this?
reverted,
tinyint
equalsint8
, but size 15 will choosetinyint
which will overflow?
but size 15 will never come, golang will select 8bit, 16bit, 32bit or 64bit.
If I am wrong then please correct my view.
Thanks @jinzhu
You can set with gorm size tag
On Sun, Feb 20, 2022 at 12:43 PM Rafiul @.***> wrote:
reverted, tinyint equals int8, but size 15 will choose tinyint which will overflow?
but size 15 will never come, golang will select 8bit, 16bit, 32bit or 64bit
— Reply to this email directly, view it on GitHub https://github.com/go-gorm/sqlserver/pull/53#issuecomment-1046162124, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABVO3IMYVZNQUV37FN3L3U4BWPJANCNFSM5O2CXSMQ . You are receiving this because you modified the open/close state.Message ID: @.***>
-- Best regards
Jinzhu github.com/jinzhu
reverted,
tinyint
equalsint8
, but size 15 will choosetinyint
which will overflow?
Could we prevent overflow by using different types based on whether field.DataType
is schema.Int
or schema.Uint
, for example, in #129:
Pull request title integer data type selection by sizing should be fixed
Conventions
Pull request reason Fix sql server integer type selection based on go lang int value memory size
User Case Description
https://github.com/go-gorm/sqlserver/blob/3c1621020dc4503717a93f7e7b9eb38c623aaa12/sqlserver.go#L158
SQL Server datatype selection based on int value data size is not appropriate. Here is the condition
Golang integers
int8 : 1 byte or 8 bits
int16: 2 bytes or 16 bits
int32: 3 bytes or 32 bits
int64
4 bytes or 64 bits`SQL Server integers equivalent
tinyint : int8
smallint : int16
int : int32
biging : int64
The condition should be
)