|
@@ -128,81 +128,88 @@ func insertWalk(sql string) (*insertClause, error) {
|
|
|
|
|
|
rowsWalker := &walk.AstWalker{Fn: func(ctx interface{}, node interface{}) (stop bool) {
|
|
|
switch rowsNode := node.(type) {
|
|
|
- case *tree.FuncExpr:
|
|
|
-
|
|
|
- value, kind, err := evaluateFuncExpr(rowsNode, nil, &funcStringParams)
|
|
|
- if err != nil {
|
|
|
- rowsWalkFuncErr = err
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: kind,
|
|
|
- value: value,
|
|
|
- })
|
|
|
- case *tree.DBool:
|
|
|
-
|
|
|
- stringValue := rowsNode.String()
|
|
|
- if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
- if stringValue == "false" {
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: clauseTableRowValueKindBool,
|
|
|
- value: false,
|
|
|
- })
|
|
|
- } else if stringValue == "true" {
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: clauseTableRowValueKindBool,
|
|
|
- value: true,
|
|
|
- })
|
|
|
- } else {
|
|
|
- rowsWalkFuncErr = errors.New("不支持的bool值")
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- case *tree.StrVal:
|
|
|
-
|
|
|
- stringValue := rowsNode.String()
|
|
|
- if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: clauseTableRowValueKindString,
|
|
|
- value: rowsNode.RawString(),
|
|
|
- })
|
|
|
- }
|
|
|
- case *tree.NumVal:
|
|
|
-
|
|
|
- stringValue := rowsNode.String()
|
|
|
- if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
- numKind := rowsNode.Kind()
|
|
|
- if numKind == constant.Int {
|
|
|
- valueUint64, err := strconv.ParseUint(rowsNode.String(), 10, 64)
|
|
|
- if err != nil {
|
|
|
- rowsWalkFuncErr = err
|
|
|
+ case *tree.ValuesClause:
|
|
|
+ for _, row := range rowsNode.Rows {
|
|
|
+ for _, column := range row {
|
|
|
+ switch realColumn := column.(type) {
|
|
|
+ case *tree.FuncExpr:
|
|
|
+
|
|
|
+ value, kind, err := evaluateFuncExpr(realColumn, nil, &funcStringParams)
|
|
|
+ if err != nil {
|
|
|
+ rowsWalkFuncErr = err
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: kind,
|
|
|
+ value: value,
|
|
|
+ })
|
|
|
+ case *tree.DBool:
|
|
|
+
|
|
|
+ stringValue := realColumn.String()
|
|
|
+ if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
+ if stringValue == "false" {
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: clauseTableRowValueKindBool,
|
|
|
+ value: false,
|
|
|
+ })
|
|
|
+ } else if stringValue == "true" {
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: clauseTableRowValueKindBool,
|
|
|
+ value: true,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ rowsWalkFuncErr = errors.New("不支持的bool值")
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case *tree.StrVal:
|
|
|
+
|
|
|
+ stringValue := realColumn.String()
|
|
|
+ if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: clauseTableRowValueKindString,
|
|
|
+ value: realColumn.RawString(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ case *tree.NumVal:
|
|
|
+
|
|
|
+ stringValue := realColumn.String()
|
|
|
+ if !canSkipValueInThisContext(&funcStringParams, stringValue) {
|
|
|
+ numKind := realColumn.Kind()
|
|
|
+ if numKind == constant.Int {
|
|
|
+ valueUint64, err := strconv.ParseUint(realColumn.String(), 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ rowsWalkFuncErr = err
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: clauseTableRowValueKindUint64,
|
|
|
+ value: valueUint64,
|
|
|
+ })
|
|
|
+ } else if numKind == constant.Float {
|
|
|
+ valueFloat64, err := strconv.ParseFloat(realColumn.String(), 64)
|
|
|
+ if err != nil {
|
|
|
+ rowsWalkFuncErr = err
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ values = append(values, clauseTableRowValue{
|
|
|
+ kind: clauseTableRowValueKindFloat64,
|
|
|
+ value: valueFloat64,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ rowsWalkFuncErr = errors.New("不支持的数值类型")
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case *tree.UnresolvedName:
|
|
|
+ rowsWalkFuncErr = errors.New("存在无法解析的名字,是否应该使用单引号")
|
|
|
return true
|
|
|
}
|
|
|
-
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: clauseTableRowValueKindUint64,
|
|
|
- value: valueUint64,
|
|
|
- })
|
|
|
- } else if numKind == constant.Float {
|
|
|
- valueFloat64, err := strconv.ParseFloat(rowsNode.String(), 64)
|
|
|
- if err != nil {
|
|
|
- rowsWalkFuncErr = err
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- values = append(values, clauseTableRowValue{
|
|
|
- kind: clauseTableRowValueKindFloat64,
|
|
|
- value: valueFloat64,
|
|
|
- })
|
|
|
- } else {
|
|
|
- rowsWalkFuncErr = errors.New("不支持的数值类型")
|
|
|
- return true
|
|
|
}
|
|
|
}
|
|
|
- case *tree.UnresolvedName:
|
|
|
- rowsWalkFuncErr = errors.New("存在无法解析的名字,是否应该使用单引号")
|
|
|
- return true
|
|
|
}
|
|
|
|
|
|
return false
|