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

uint8 in Golang should correspond to tinyint in SQL Server #128

Open
iTanken opened this issue Mar 7, 2024 · 0 comments
Open

uint8 in Golang should correspond to tinyint in SQL Server #128

iTanken opened this issue Mar 7, 2024 · 0 comments

Comments

@iTanken
Copy link
Contributor

iTanken commented Mar 7, 2024

sqlserver/sqlserver.go

Lines 188 to 202 in ef8f762

case schema.Int, schema.Uint:
var sqlType string
switch {
case field.Size < 16:
sqlType = "smallint"
case field.Size < 31:
sqlType = "int"
default:
sqlType = "bigint"
}
if field.AutoIncrement {
return sqlType + " IDENTITY(1,1)"
}
return sqlType

Because in SQL Server, the range of values for the tinyint type is from 0 to 255, which exactly matches the range of uint8, so when field.Size < 16 and field.DataType == schema.Uint, should sqlType be tinyint? Like this:

 case schema.Int, schema.Uint:
 	var sqlType string
 	switch {
 	case field.Size < 16:
		if field.DataType == schema.Uint {
			sqlType = "tinyint"
		} else {
			sqlType = "smallint"
		}
 	case field.Size < 31:
 		sqlType = "int"
 	default:
 		sqlType = "bigint"
 	}
  
 	if field.AutoIncrement {
 		return sqlType + " IDENTITY(1,1)"
 	}
 	return sqlType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant