Пример #1
0
// Execute is part of the queryservice.QueryServer interface
func (q *Query) Execute(ctx context.Context, request *pb.ExecuteRequest) (response *pb.ExecuteResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callinfo.GRPCCallInfo(ctx)

	reply := new(mproto.QueryResult)
	execErr := q.server.Execute(ctx, &proto.Query{
		Sql:           string(request.Query.Sql),
		BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables),
		SessionId:     request.SessionId,
		TransactionId: request.TransactionId,
	}, reply)
	if execErr != nil {
		return &pb.ExecuteResponse{
			Error: tabletserver.TabletErrorToRPCError(execErr),
		}, nil
	}
	return &pb.ExecuteResponse{
		Result: proto.QueryResultToProto3(reply),
	}, nil
}
Пример #2
0
// StreamExecute is part of the queryservice.QueryServer interface
func (q *Query) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Query_StreamExecuteServer) (err error) {
	defer q.server.HandlePanic(&err)
	ctx := callinfo.GRPCCallInfo(stream.Context())

	seErr := q.server.StreamExecute(ctx, &proto.Query{
		Sql:           string(request.Query.Sql),
		BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables),
		SessionId:     request.SessionId,
	}, func(reply *mproto.QueryResult) error {
		return stream.Send(&pb.StreamExecuteResponse{
			Result: proto.QueryResultToProto3(reply),
		})
	})
	if seErr != nil {
		response := &pb.StreamExecuteResponse{
			Error: tabletserver.TabletErrorToRPCError(seErr),
		}
		if err := stream.Send(response); err != nil {
			return err
		}
	}
	return nil
}