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

column: Trace more errors #97

Merged
merged 1 commit into from
Sep 10, 2015
Merged
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
25 changes: 17 additions & 8 deletions column/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ func (c *Col) CastValue(ctx context.Context, val interface{}) (casted interface{
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeYear, mysql.TypeBit:
intVal, errCode := c.normalizeIntegerValue(val)
if errCode == errCodeType {
casted = intVal
err = c.TypeError(val)
return
return intVal, errors.Trace(err)
}
return c.castIntegerValue(intVal, errCode)
case mysql.TypeFloat, mysql.TypeDouble:
Expand All @@ -153,48 +152,56 @@ func (c *Col) CastValue(ctx context.Context, val interface{}) (casted interface{
casted, err = mysql.ParseTimeFromNum(v, c.Tp, c.Decimal)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
case string:
casted, err = mysql.ParseTime(v, c.Tp, c.Decimal)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
case mysql.Time:
var t mysql.Time
t, err = v.Convert(c.Tp)
if err != nil {
err = newParseColError(err, c)
return
return casted, errors.Trace(err)
}
casted, err = t.RoundFrac(c.Decimal)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
default:
err = c.TypeError(val)
return casted, errors.Trace(err)
}
case mysql.TypeDuration:
switch v := val.(type) {
case string:
casted, err = mysql.ParseDuration(v, c.Decimal)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
case mysql.Time:
var t mysql.Duration
t, err = v.ConvertToDuration()
if err != nil {
err = newParseColError(err, c)
return
return casted, errors.Trace(err)
}
casted, err = t.RoundFrac(c.Decimal)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
case mysql.Duration:
casted, err = v.RoundFrac(c.Decimal)
return casted, errors.Trace(err)
default:
err = c.TypeError(val)
return casted, errors.Trace(err)
}
case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString:
strV := ""
Expand Down Expand Up @@ -222,6 +229,7 @@ func (c *Col) CastValue(ctx context.Context, val interface{}) (casted interface{
casted, err = mysql.ParseDecimal(v)
if err != nil {
err = newParseColError(err, c)
return casted, errors.Trace(err)
}
case int8:
casted = mysql.NewDecimalFromInt(int64(v), 0)
Expand Down Expand Up @@ -252,6 +260,7 @@ func (c *Col) CastValue(ctx context.Context, val interface{}) (casted interface{
}
default:
err = c.TypeError(val)
return casted, errors.Trace(err)
}
return
}
Expand Down Expand Up @@ -539,10 +548,10 @@ func (c *Col) castFloatValue(x interface{}) (casted interface{}, err error) {
v = strings.Trim(v, " \t\r\n")
fval, err = strconv.ParseFloat(v, 64)
if err != nil {
return float64(0), c.TypeError(x)
return float64(0), errors.Trace(c.TypeError(x))
}
default:
return nil, c.TypeError(x)
return nil, errors.Trace(c.TypeError(x))
}
switch c.Tp {
case mysql.TypeFloat:
Expand All @@ -564,10 +573,10 @@ func CastValues(ctx context.Context, rec []interface{}, cols []*Col) (err error)
for _, c := range cols {
rec[c.Offset], err = c.CastValue(ctx, rec[c.Offset])
if err != nil {
return
return errors.Trace(err)
}
}
return
return nil
}

// ColDesc describes column information like MySQL desc and show columns do.
Expand Down
2 changes: 1 addition & 1 deletion stmt/stmts/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (s *SelectStmt) Plan(ctx context.Context) (plan.Plan, error) {

// Exec implements the stmt.Statement Exec interface.
func (s *SelectStmt) Exec(ctx context.Context) (rs rset.Recordset, err error) {
log.Info("SelectStmt trx:")
log.Info("Exec :", s.OriginText())
r, err := s.Plan(ctx)
if err != nil {
return nil, err
Expand Down