Browse Source

修改事务bug

yjp 11 months ago
parent
commit
34328c983d
3 changed files with 46 additions and 7 deletions
  1. 26 7
      grpc_client/v1/response/sql.pb.go
  2. 9 0
      sdk/sdk.go
  3. 11 0
      sdk/transaction.go

+ 26 - 7
grpc_client/v1/response/sql.pb.go

@@ -25,7 +25,9 @@ type TransactionResponse struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Results string `protobuf:"bytes,1,opt,name=Results,proto3" json:"Results,omitempty"`
+	Success bool   `protobuf:"varint,1,opt,name=Success,proto3" json:"Success,omitempty"`
+	Msg     string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"`
+	Results string `protobuf:"bytes,3,opt,name=Results,proto3" json:"Results,omitempty"`
 }
 
 func (x *TransactionResponse) Reset() {
@@ -60,6 +62,20 @@ func (*TransactionResponse) Descriptor() ([]byte, []int) {
 	return file_v1_response_sql_proto_rawDescGZIP(), []int{0}
 }
 
+func (x *TransactionResponse) GetSuccess() bool {
+	if x != nil {
+		return x.Success
+	}
+	return false
+}
+
+func (x *TransactionResponse) GetMsg() string {
+	if x != nil {
+		return x.Msg
+	}
+	return ""
+}
+
 func (x *TransactionResponse) GetResults() string {
 	if x != nil {
 		return x.Results
@@ -72,12 +88,15 @@ var File_v1_response_sql_proto protoreflect.FileDescriptor
 var file_v1_response_sql_proto_rawDesc = []byte{
 	0x0a, 0x15, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2f, 0x73, 0x71,
 	0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
-	0x65, 0x22, 0x2f, 0x0a, 0x13, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
-	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x75,
-	0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c,
-	0x74, 0x73, 0x42, 0x20, 0x5a, 0x1e, 0x64, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70,
-	0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70,
-	0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x65, 0x22, 0x5b, 0x0a, 0x13, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
+	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63,
+	0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65,
+	0x73, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x03, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18,
+	0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x42, 0x20,
+	0x5a, 0x1e, 0x64, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70,
+	0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
+	0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 9 - 0
sdk/sdk.go

@@ -104,6 +104,15 @@ func (s *SDK) Transaction(txFunc TxFunc) error {
 		return err
 	}
 
+	resp, err := stream.Recv()
+	if err != nil {
+		return err
+	}
+
+	if !resp.Success {
+		return errors.New(resp.Msg)
+	}
+
 	err = txFunc(&Transaction{
 		stream: stream,
 	})

+ 11 - 0
sdk/transaction.go

@@ -2,6 +2,7 @@ package sdk
 
 import (
 	"encoding/json"
+	"errors"
 	v1 "git.sxidc.com/service-supports/ds-sdk/grpc_client/v1"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client/v1/request"
 )
@@ -49,6 +50,11 @@ func (tx *Transaction) ExecuteRawSql(sql string, executeParams map[string]any) (
 		return nil, retErr
 	}
 
+	if !resp.Success {
+		retErr = errors.New(resp.Msg)
+		return nil, retErr
+	}
+
 	tableRows := make([]map[string]any, 0)
 	err = json.Unmarshal([]byte(resp.Results), &tableRows)
 	if err != nil {
@@ -96,6 +102,11 @@ func (tx *Transaction) ExecuteSql(name string, executeParams map[string]any) ([]
 		return nil, retErr
 	}
 
+	if !resp.Success {
+		retErr = errors.New(resp.Msg)
+		return nil, retErr
+	}
+
 	tableRows := make([]map[string]any, 0)
 	err = json.Unmarshal([]byte(resp.Results), &tableRows)
 	if err != nil {