go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

converting driver.Value type []uint8 ("\x00") to a uint8: invalid syntax

Open weiailuxueqi opened this issue 3 years ago • 4 comments

Describe the bug Dear brothers, is there a comparison relationship between the data types generated by the database and GO-Zero? Now I have A problem. There is A table A in the mysql database with A bit(1) type field. However, after generating the data model by GoCTL, it is found that the generated field type is byte. SQL: Scan error on column index 15, name "delete_flag": Converting driver.Value type [] Uint8 ("\x00") to a uint8: invalid syntax ". After that, I set this field of database table A to Tinyint (1). After being generated by GOCTL, the field type of the model is INT64. May I ask which database type can make the fields of the model generate bool type?

BUG中文描述 各位大兄弟,请问有没有数据库与go-zero生成的数据类型的对照关系? 因为我现在遇到一个问题,mysql数据库中有一张表A的有一个bit(1)类型的字段,但是通过goctl生成数据模型后,发现生成的字段类型为byte类型,这是为何? 然后程序运行出现错误“sql: Scan error on column index 15, name "delete_flag": converting driver.Value type []uint8 ("\x00") to a uint8: invalid syntax”。 而后,我又将数据库表A的这个字段设置为tinyint(1),通过goctl生成后,模型的字段类型为int64,请问有什么数据库类型会让模型的字段生成bool类型?

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

    
    

CREATE TABLE sys_user ( user_id bigint NOT NULL AUTO_INCREMENT COMMENT '用户id', user_name varchar(256) NOT NULL COMMENT '用户名', delete_flag bit(1) NOT NULL COMMENT '删除标识', PRIMARY KEY (user_id) ) ENGINE=InnoDB COMMENT='系统用户';


```go

    SysUser struct {
		UserId        int64         `db:"user_id"`         // 用户id
		UserName      string        `db:"user_name"`       // 用户名
		DeleteFlag    byte          `db:"delete_flag"`     // 删除标识
	}

  1. The error is

    
    sql: Scan error on column index 15, name "delete_flag": converting driver.Value type []uint8 ("\x00") to a uint8: invalid syntax
    
    

Expected behavior Theoretically, bit(1) data should be treated as bool.

Screenshots image image

Environments (please complete the following information):

  • OS: [e.g. mac os]
  • go-zero version [e.g. 1.4.0]
  • goctl version [e.g. 1.4.0]

More description Add any other context about the problem here.

weiailuxueqi avatar Aug 15 '22 09:08 weiailuxueqi

image image 为何go-zero里头将数据类型,全部定义成int64?实际上是可以根据go的那套处理的。

weiailuxueqi avatar Aug 16 '22 05:08 weiailuxueqi

看了下源码,并没有根据column的 dbtype(长度) 的长度来动态区分数据类型,而是硬编码map的形式处理的映射类型。 请问为何所有整形都要统一处理成int64呢? image

weiailuxueqi avatar Aug 16 '22 06:08 weiailuxueqi

我将会按照 go-sql-driver 的数据类型关系去处理

kesonan avatar Aug 18 '22 07:08 kesonan

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I will deal with the data type relationship of go-sql-driver

Issues-translate-bot avatar Aug 18 '22 07:08 Issues-translate-bot

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 19 '23 01:08 github-actions[bot]