Skip to content

Commit

Permalink
when the shard key of insert sql is null,return error message
Browse files Browse the repository at this point in the history
  • Loading branch information
flike committed Jun 24, 2017
1 parent d6009de commit 495b4aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ var (
ErrSlaveNotExist = errors.New("slave has not exist")
ErrBlackSqlExist = errors.New("black sql has exist")
ErrBlackSqlNotExist = errors.New("black sql has not exist")
ErrInsertTooComplex = errors.New("insert is too complex")
ErrSQLNULL = errors.New("sql is null")
)
4 changes: 2 additions & 2 deletions core/hack/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hack

const (
Version = "2017-04-25 19:26:47 +0800 @8b29b42"
Compile = "2017-05-03 19:55:36 +0800 by go version go1.8 darwin/amd64"
Version = "2017-05-17 08:48:07 +0800 @d6009de"
Compile = "2017-06-24 14:13:32 +0800 by go version go1.8.3 darwin/amd64"
)
9 changes: 5 additions & 4 deletions proxy/router/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,21 @@ func (plan *Plan) calRouteIndexs() error {
}
}

func (plan *Plan) checkValuesType(vals sqlparser.Values) sqlparser.Values {
func (plan *Plan) checkValuesType(vals sqlparser.Values) (sqlparser.Values, error) {
// Analyze first value of every item in the list
for i := 0; i < len(vals); i++ {
switch tuple := vals[i].(type) {
case sqlparser.ValTuple:
result := plan.getValueType(tuple[0])
if result != VALUE_NODE {
panic(sqlparser.NewParserError("insert is too complex"))
return nil, errors.ErrInsertTooComplex
}
default:
panic(sqlparser.NewParserError("insert is too complex"))
//panic(sqlparser.NewParserError("insert is too complex"))
return nil, errors.ErrInsertTooComplex
}
}
return vals
return vals, nil
}

/*返回valExpr表达式对应的类型*/
Expand Down
12 changes: 10 additions & 2 deletions proxy/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ func (r *Router) buildInsertPlan(db string, statement sqlparser.Statement) (*Pla
}
}

plan.Criteria = plan.checkValuesType(stmt.Rows.(sqlparser.Values))
plan.Criteria, err = plan.checkValuesType(stmt.Rows.(sqlparser.Values))
if err != nil {
golog.Error("router", "buildInsertPlan", err.Error(), 0, "sql", sqlparser.String(statement))
return nil, err
}

err = plan.calRouteIndexs()
if err != nil {
Expand Down Expand Up @@ -494,7 +498,11 @@ func (r *Router) buildReplacePlan(db string, statement sqlparser.Statement) (*Pl
return nil, err
}

plan.Criteria = plan.checkValuesType(stmt.Rows.(sqlparser.Values))
plan.Criteria, err = plan.checkValuesType(stmt.Rows.(sqlparser.Values))
if err != nil {
golog.Error("router", "buildReplacePlan", err.Error(), 0, "sql", sqlparser.String(statement))
return nil, err
}

err = plan.calRouteIndexs()
if err != nil {
Expand Down

0 comments on commit 495b4aa

Please sign in to comment.