github.com/matrixorigin/matrixone@v1.2.0/pkg/frontend/resp_client.go (about)

     1  // Copyright 2021 - 2024 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package frontend
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/common/moerr"
    19  	"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
    20  )
    21  
    22  func setResponse(ses *Session, isLastStmt bool, rspLen uint64) *Response {
    23  	return ses.SetNewResponse(OkResponse, rspLen, int(COM_QUERY), "", isLastStmt)
    24  }
    25  
    26  // response the client
    27  func respClientWhenSuccess(ses *Session,
    28  	execCtx *ExecCtx) (err error) {
    29  	if execCtx.skipRespClient {
    30  		return nil
    31  	}
    32  	err = respClientWithoutFlush(ses, execCtx)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	err = ses.GetMysqlProtocol().Flush()
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	if ses.GetQueryInExecute() {
    43  		logStatementStatus(execCtx.reqCtx, ses, execCtx.stmt, success, nil)
    44  	} else {
    45  		logStatementStatus(execCtx.reqCtx, ses, execCtx.stmt, fail, moerr.NewInternalError(execCtx.reqCtx, "query is killed"))
    46  	}
    47  	return err
    48  }
    49  
    50  func respClientWithoutFlush(ses *Session,
    51  	execCtx *ExecCtx) (err error) {
    52  	if execCtx.skipRespClient {
    53  		return nil
    54  	}
    55  	switch execCtx.stmt.StmtKind().RespType() {
    56  	case tree.RESP_STREAM_RESULT_ROW:
    57  		err = respStreamResultRow(ses, execCtx)
    58  	case tree.RESP_PREBUILD_RESULT_ROW:
    59  		err = respPrebuildResultRow(ses, execCtx)
    60  	case tree.RESP_MIXED_RESULT_ROW:
    61  		err = respMixedResultRow(ses, execCtx)
    62  	case tree.RESP_NOTHING:
    63  	case tree.RESP_BY_SITUATION:
    64  	case tree.RESP_STATUS:
    65  		err = respStatus(ses, execCtx)
    66  	}
    67  	return err
    68  }