Hi,

Did you get an answer to your question?

Dave

-----Original Message-----
From: Song Hao-Lin <[email protected]> 
Sent: Monday, January 21, 2019 3:19 AM
To: [email protected]
Subject: One question about the code of mxosrvr


Hi all

I found that the function GETMXCSWARNINGORERROR, which used to set warnings or 
errors in mxosrvr, could only record one warning or error during one client 
request.
If you call the function twice , it will remove the message which is recorded 
in the first time(by bzero(WarningOrError,sizeof(WarningOrError))),while errors 
or warnings from sql engine could be recorded by SRVR::GETSQLWARNINGORERROR2 no 
matter how many they are. If I make a mistake, please let me know.

The function GETMXCSWARNINGORERROR is in the file 
core/conn/odbc/src/odbc/nsksrvrcore/srvrcommon.cpp.
I want to modify the related code and suggestions are welcome. 


// DO NOT call this function using pSrvrStmt->sqlWarningOrErrorLength and 
pSrvrStmt->sqlWarningOrError, // Since the WarningOrError is static and 
pSrvrStmt->sqlWarningOrError will deallocate this memory.
extern "C" void GETMXCSWARNINGORERROR(
/* In */ Int32 sqlcode
, /* In */ char *sqlState
, /* In */ char *msg_buf
, /* Out */ Int32 *MXCSWarningOrErrorLength , /* Out */ BYTE 
*&MXCSWarningOrError) {
    Int32 total_conds = 1;
    Int32 buf_len;
    Int32 curr_cond = 1;
    Int32 msg_buf_len = strlen(msg_buf)+1;
    Int32 time_and_msg_buf_len = 0;
    Int32 msg_total_len = 0;
    Int32 rowId = 0; // use this for rowset recovery.
    char tsqlState[6];
    static BYTE WarningOrError[1024];
    char strNow[TIMEBUFSIZE + 1];
    char* time_and_msg_buf = NULL;
    memset(tsqlState,0,sizeof(tsqlState));
    memcpy(tsqlState,sqlState,sizeof(tsqlState)-1);
    
    bzero(WarningOrError,sizeof(WarningOrError));
    *MXCSWarningOrErrorLength = 0;
    MXCSWarningOrError = WarningOrError; // Size of internally generated 
message should be enough
    *(Int32 *)(MXCSWarningOrError+msg_total_len) = total_conds;
    msg_total_len += sizeof(total_conds);
    *(Int32 *)(MXCSWarningOrError+msg_total_len) = rowId;
    msg_total_len += sizeof(rowId);
    *(Int32 *)(MXCSWarningOrError+msg_total_len) = sqlcode;
    msg_total_len += sizeof(sqlcode);
    time_and_msg_buf_len = msg_buf_len + TIMEBUFSIZE;
    *(Int32 *)(MXCSWarningOrError+msg_total_len) = time_and_msg_buf_len;
    msg_total_len += sizeof(time_and_msg_buf_len);
    //Get the timetsamp
    time_and_msg_buf = new char[time_and_msg_buf_len];
    strncpy(time_and_msg_buf, msg_buf, msg_buf_len);
    time_t now = time(NULL);
    bzero(strNow, sizeof(strNow));
    strftime(strNow, sizeof(strNow), " [%Y-%m-%d %H:%M:%S]", localtime(&now));
    strcat(time_and_msg_buf, strNow);
    memcpy(MXCSWarningOrError+msg_total_len, time_and_msg_buf, 
time_and_msg_buf_len);
    msg_total_len += time_and_msg_buf_len;
    delete time_and_msg_buf;
    memcpy(MXCSWarningOrError+msg_total_len, tsqlState, sizeof(tsqlState));
    msg_total_len += sizeof(tsqlState);
    *MXCSWarningOrErrorLength = msg_total_len;
    return;
}

Reply via email to