Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
forsaken628 committed Jan 21, 2025
1 parent b095385 commit 1269651
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 149 deletions.
40 changes: 23 additions & 17 deletions columntype.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func (b isNullable) checkNull(s string) bool {
}

type simpleColumnType struct {
dbType string
scanType reflect.Type
isNullable
dbType string
scanType reflect.Type
nullable bool
parseNull bool
}

func (*simpleColumnType) PrecisionScale() (int64, int64, bool) {
Expand All @@ -85,16 +86,20 @@ func (c *simpleColumnType) DatabaseTypeName() string {
return c.dbType
}

func (c *simpleColumnType) Nullable() (bool, bool) {
return c.nullable, true
}

func (c *simpleColumnType) Desc() *TypeDesc {
return &TypeDesc{Name: c.dbType, Nullable: bool(c.isNullable)}
return &TypeDesc{Name: c.dbType, Nullable: c.nullable}
}

func (*simpleColumnType) Length() (int64, bool) {
return 0, false
}

func (c *simpleColumnType) Parse(s string) (driver.Value, error) {
if c.checkNull(s) {
if c.nullable && c.parseNull && s == "NULL" {
return nil, nil
}
return s, nil
Expand Down Expand Up @@ -187,31 +192,32 @@ func NewColumnType(dbType string, opts *DataParserOptions) (ColumnType, error) {
}
desc = desc.Normalize()
nullable := isNullable(desc.Nullable)
parseNull := opts.ParseNull()
switch desc.Name {
case "String":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeString, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeString, nullable: desc.Nullable, parseNull: false}, nil
case "Boolean":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeBool, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeBool, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Int8":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt8, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt8, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Int16":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt16, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt16, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Int32":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt32, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt32, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Int64":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt64, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeInt64, nullable: desc.Nullable, parseNull: parseNull}, nil
case "UInt8":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt8, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt8, nullable: desc.Nullable, parseNull: parseNull}, nil
case "UInt16":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt16, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt16, nullable: desc.Nullable, parseNull: parseNull}, nil
case "UInt32":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt32, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt32, nullable: desc.Nullable, parseNull: parseNull}, nil
case "UInt64":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt64, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeUInt64, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Float32":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeFloat32, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeFloat32, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Float64":
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeFloat64, isNullable: nullable}, nil
return &simpleColumnType{dbType: nullable.wrapName(desc.Name), scanType: reflectTypeFloat64, nullable: desc.Nullable, parseNull: parseNull}, nil
case "Timestamp":
return &timestampColumnType{isNullable: nullable}, nil
case "Date":
Expand Down
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (dc *DatabendConn) BeginTx(
}

func (dc *DatabendConn) DataParserOptions() *DataParserOptions {
return nil
return &dc.cfg.DataParserOptions
}

func (dc *DatabendConn) cleanup() {
Expand Down
1 change: 1 addition & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Config struct {
// databend version should >= v1.2.345-nightly
EmptyFieldAs string
EnableOpenTelemetry bool
DataParserOptions DataParserOptions
}

// NewConfig creates a new config with default values
Expand Down
Loading

0 comments on commit 1269651

Please sign in to comment.