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

Support decimal for sql execution. #986

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions decimal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mysql

type Decimal interface {
DecimalString() string
}
15 changes: 15 additions & 0 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,21 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
}
}

case Decimal:
paramTypes[i+i] = byte(fieldTypeNewDecimal)
paramTypes[i+i+1] = 0x00

if len(v.DecimalString()) < longDataSize {
paramValues = appendLengthEncodedInteger(paramValues,
uint64(len(v.DecimalString())),
)
paramValues = append(paramValues, v.DecimalString()...)
} else {
if err := stmt.writeCommandLongData(i, []byte(v.DecimalString())); err != nil {
return err
}
}

case time.Time:
paramTypes[i+i] = byte(fieldTypeString)
paramTypes[i+i+1] = 0x00
Expand Down
4 changes: 4 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
return v, nil
}

if _, ok := v.(Decimal); ok {
return v, nil
}

if vr, ok := v.(driver.Valuer); ok {
sv, err := callValuerValue(vr)
if err != nil {
Expand Down