[TDR List Table][C++ SDK] Get All Elements from a List
1. Interface Description
Get all records from a single key in a List table (example path: examples/tcaplus/C++_tdr1.0_asyncmode_list_simpletable/SingleOperation/listgetall)
Note:
- Setting TcaplusServiceRequest:: SetMultiResponseFlag() allows packet splitting, otherwise, if the response packet exceeds 256 KB, it will lose packets
- Package splitting will be triggered when the response package exceeds 256 KB. However, it needs to ensure that packet splitting will not split a single record (no matter how large the record is). For example, the three records of the response package are 10 KB, 251 KB, and 1 MB, which will be returned in two packages, namely (10 KB, 251 KB) and (1 MB); Call TcaplusServiceResponse:: HaveMoreResPkgs() to determine whether there is another package
2. Version Requirements
This interface is provided in all versions without special requirements.
3. Preparations
Refer to Preparation document to complete the preparation before using this interface, create the following TDR List table, and use the TDR tool to convert the XML table into C++ code.
<?xml version="1.0" encoding="GBK" standalone="yes" ?>
<metalib name="tcaplus_tb" tagsetversion="1" version="1">
<struct name="following_action_list" version="1" primarykey="game,myuin">
<entry name="game" type="uint64" defaultvalue="0" desc="game ID" />
<entry name="myuin" type="uint32" desc="QQ number"/>
<entry name="actiontype" type="uint8" defaultvalue="0" desc="1 - share pictures, 2 - like pictures, 3 - comment on pictures"/>
<entry name="uin2" type="uint32" desc="follower's QQ number"/>
<entry name="nick2" type="string" size="128" desc="follower's nickname"/>
<entry name="sex" type="uint8" defaultvalue="0" desc="follower's sex: male 0 female 1"/>
<entry name="pid" type="string" size="33" desc="picture ID operated by follower"/>
<entry name="time" type="uint32" desc="time"/>
<entry name="content" type="string" size="1024" desc="update content"/>
</struct>
</metalib>
Get the following information after the preparation. These details will be used by the SDK:
- Directory server address list
- App ID
- App access password
- Game zone ID
- Table name
4. Example Code
4.1 Example Code for Asynchronous Call
Basic execution process of example code:
- Define table configuration parameters
- Create a log handle;
- Create a client;
- Send a request;
- Process the response;
- Destroy the client.
- Asynchronous framework;
Steps 1,2,3,6,7 are common codes for all examples. Focus on steps 4 and 5, which are sending a request and processing the response
4.1.1 Define table configuration parameters (code path: examples/tcaplus/C++_common_for_tdr1.0/common.h)
It mainly sets the configuration parameters of the table, which are located in the header of the code file
// Tcapdir address of the target app
static const char DIR_URL_ARRAY[][TCAPLUS_MAX_STRING_LENGTH] =
{
"tcp://10.191.***.99:9999",
"tcp://10.191.***.88:9999"
};
// Number of tcapdir addresses of the target app
static const int32_t DIR_URL_COUNT = 2;
// Set ID of the target app
static const int32_t APP_ID = 3;
// Table group ID of the target app
static const int32_t ZONE_ID = 1;
// App password of the target app
static const char * SIGNATURE = "*******";
// Table name of the target app PLAYERONLINECNT
static const char * TABLE_NAME = "PLAYERONLINECNT";
4.1.2 Create a log handle (code path: examples/tcaplus/C++_common_for_tdr1.0/common.h)
Create a log handle through the log configuration file tlogconf.xml for SDK log printing
//Tcaplus service log class
TcaplusService::TLogger* g_pstTlogger;
LPTLOGCATEGORYINST g_pstLogHandler;
LPTLOGCTX g_pstLogCtx;
int32_t InitLog()
{
// Absolute path to the log configuration file
const char* sLogConfFile = "tlogconf.xml";
// Log class name
const char* sCategoryName = "mytest";
//Use the configuration file to initialize a log handle
g_pstLogCtx = tlog_init_from_file(sLogConfFile);
if (NULL == g_pstLogCtx)
{
fprintf(stderr, "tlog_init_from_file failed.\n");
return -1;
}
// Get the log class
g_pstLogHandler = tlog_get_category(g_pstLogCtx, sCategoryName);
if (NULL == g_pstLogHandler)
{
fprintf(stderr, "tlog_get_category(mytest) failed.\n");
return -2;
}
// Initialize the log handle
g_pstTlogger = new TcaplusService::TLogger(g_pstLogHandler);
if (NULL == g_pstTlogger)
{
fprintf(stderr, "TcaplusService::TLogger failed.\n");
return -3;
}
return 0;`
}
4.1.3 Create a SDK client (code path: examples/tcaplus/C++_common_for_tdr1.0/common.h)
Create a Tcaplus client through this code. This client can only be used by a single thread. The multithreading model can initialize a client instance on each thread
//Main client class of the Tcaplus service API
TcaplusService::TcaplusServer g_stTcapSvr;
//Meta information of the table
extern unsigned char g_szMetalib_tcaplus_tb[];
LPTDRMETA g_szTableMeta = NULL;
int32_t InitServiceAPI()
{
// Initialization
int32_t iRet = g_stTcapSvr.Init(g_pstTlogger, /*module_id*/0, /*app id*/APP_ID, /*zone id*/ZONE_ID, /*signature*/SIGNATURE);
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.Init failed, iRet: %d.", iRet);
return iRet;
}
// Add a directory server
for (int32_t i = 0; i< DIR_URL_COUNT; i++)
{
iRet = g_stTcapSvr.AddDirServerAddress(DIR_URL_ARRAY[i]);
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.AddDirServerAddress(%s) failed, iRet: %d.", DIR_URL_ARRAY[i], iRet);
return iRet;
}
}
// Get the meta description of the table
g_szTableMeta = tdr_get_meta_by_name((LPTDRMETALIB)g_szMetalib_tcaplus_tb, TABLE_NAME);
if(NULL == g_szTableMeta)
{
tlog_error(g_pstLogHandler, 0, 0,"tdr_get_meta_by_name(%s) failed.", TABLE_NAME);
return -1;
}
// Register a database table with a 10-second timeout (connect to the dir server, authenticate, and obtain table paths).
iRet = g_stTcapSvr.RegistTable(TABLE_NAME, g_szTableMeta, /*timeout_ms*/10000);
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.RegistTable(%s) failed, iRet: %d.", TABLE_NAME, iRet);
return iRet;
}
// Connect to all tcaplus proxy servers corresponding to the table
iRet = g_stTcapSvr.ConnectAll(/*timeout_ms*/10000, 0);
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.ConnectAll failed, iRet: %d.", iRet);
return iRet;
}
return 0;
}
4.1.4 Send a request (code path: examples/tcaplus/C++_tdr1.0_asyncmode_list_simpletable/SingleOperation/listgetall/main.cpp)
Create a request, add a record, and send a request by the client
/*
User buffer, which is carried back by the res
User buffer is defined by the user, and the maximum buffer space has been defined in tcaplus_protocol_cs.xml
Maximum buffer space is TCAPLUS_MAX_USERBUFF_LEN=1024 bytes
*/
typedef struct
{
char m_szUserMessage[128];
int32_t m_dwMagicNo;
//...
}TB_USERBUFFER;
int32_t SendListGetAllRequest(int32_t dwKey)
{
// Request object class
TcaplusService::TcaplusServiceRequest* pstRequest = g_stTcapSvr.GetRequest(TABLE_NAME);
if (NULL == pstRequest)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.GetRequest(%s) failed.", TABLE_NAME);
return -1;
}
int32_t iRet = pstRequest->Init(TCAPLUS_API_LIST_GETALL_REQ, NULL, 0, 0, 0, 0);
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "pstRequest->Init(TCAPLUS_API_LIST_GETALL_REQ) failed, iRet: %d.", iRet);
return iRet;
}
// Set user-defined data. This sample assigns m_dwMagicNo as the current request's dwKey and associates it with g_mapKeyTime for timeout control. m_szUserMessage is defined by the user.
TB_USERBUFFER stUserBuffer;
stUserBuffer.m_dwMagicNo = dwKey;
snprintf(stUserBuffer.m_szUserMessage, sizeof(stUserBuffer.m_szUserMessage), "%s", "user defined message");
pstRequest->SetUserBuff((const char*)&stUserBuffer, sizeof(stUserBuffer));
// Set the asynchronous transaction ID. In this sample, the ullAsyncID is set to 2. When using it, please refer to the actual situation. It is mainly used for the control of asynchronous concurrent packages
uint64_t ullAsyncID = 2;
pstRequest->SetAsyncID(ullAsyncID);
/**
@brief: add a record to the request.
@param [IN] index: used for List operations, and it is usually >=0, indicating the Index(not subscript) of the Record in the List.
It is used for TCAPLUS_API_LIST_ADDAFTER_REQ in the List table. The index can take the command number of TCAPLUS_API_LIST_PRE_FIRST_INDEX or TCAPLUS_API_LIST_LAST_INDEX.
Index is the secondary key, and tcaplus automatically maintains its uniqueness. For the newly inserted record, the index will increase.
When cmd is TCAPLUS_API_LIST_ADDAFTER_REQ, it means that the record is inserted after the record containing the index (implicit constraint: the record containing the index must already exist);
The index also supports the following special values:
TCAPLUS_API_LIST_PRE_FIRST_INDEX: it means that the new element is inserted before the first element
TCAPLUS_API_LIST_LAST_INDEX: it means that the new element is inserted after the last element
For Generic operations, the index is meaningless and will be ignored.
*/
// The LISTGETALL command can fetch all records under a key without setting the index value.
TcaplusService::TcaplusServiceRecord* pstRecord = pstRequest->AddRecord();
if (NULL == pstRecord)
{
tlog_error(g_pstLogHandler, 0, 0, "pstRequest->AddRecord() failed.");
return -1;
}
// Set the key
FOLLOWING_ACTION_LIST tagfollowing_action_list;
memset(&tagfollowing_action_list, 0, sizeof(tagfollowing_action_list));
tagfollowing_action_list.ullGame = dwKey;
tagfollowing_action_list.dwMyuin = 123456789;
iRet = pstRecord->SetData(&tagfollowing_action_list, sizeof(tagfollowing_action_list));
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "pstRequest->SetFieldNames failed, iRet: %d.", iRet);
return iRet;
}
// Send a request message package
iRet = g_stTcapSvr.SendRequest(pstRequest);
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stTcapSvr.SendRequest failed, iRet: %d.", iRet);
return iRet;
}
return 0;
}
4.1.5 Process the response (code path: examples/tcaplus/C++_tdr1.0_asyncmode_list_simpletable/SingleOperation/listgetall/main.cpp)
Process the response, judge the return value of the response for response processing, and obtain records from the response if it is returned successfully
// Response processing function
int32_t HandleResponse(TB_USERBUFFER *pstUserBuffer, TcaplusServiceResponse* pstTcapRspRcved)
{
if(NULL == pstTcapRspRcved || NULL == pstUserBuffer)
{
tlog_error(g_pstLogHandler, 0, 0, "NULL == pstTcapRspRcved || NULL == pstUserBuffer");
return -1;
}
// Users can get the returned information through interfaces such as GetResult. For other interfaces, see the header file
const char* pszTableName = pstTcapRspRcved->GetTableName();
int32_t dwCmd = pstTcapRspRcved->GetCmd();
int32_t dwResult = pstTcapRspRcved->GetResult();
// Operation failure
if( 0 != dwResult)
{
tlog_error(g_pstLogHandler, 0, 0, "GetResult is not zero. dwResult: %d .", dwResult);
// The record does not exist
if (TcaplusService::ERR_RECORD_NOT_EXIST == dwResult)
{
tlog_error(g_pstLogHandler, 0, 0, "The TimeStamp = [%d] GameSvrID = [mysvrid], record is not exist. ", pstUserBuffer->m_dwMagicNo);
}
if (TcaplusService::ERR_TIME_OUT == dwResult)
{
HandleTimeoutResponse(pstUserBuffer->m_dwMagicNo);
}
if (TcaplusService::ERR_RECORD_EXIST == dwResult)
{
tlog_error(g_pstLogHandler, 0, 0, "key = [%d] record is exist. ", pstUserBuffer->m_dwMagicNo);
}
return -2;
}
// Process the response package, and we need to split the package according to the response package
return HandleList(pstTcapRspRcved);
}
// Timeout processing function
int32_t HandleTimeoutResponse(int32_t dwKey)
{
tlog_error(g_pstLogHandler, 0, 0, "The TimeStamp = [%d] GameSvrID = [mysvrid], response is timeout. ", dwKey);
//Other logics for processing timeout
return 0;
}
//Process the response message form the List
int32_t HandleList(TcaplusServiceResponse* pstTcapRspRcved)
{
if(NULL == pstTcapRspRcved)
{
return -1;
}
// Number of records contained in a res package
int32_t dwRecordCount = pstTcapRspRcved->GetRecordCount();//Get the number of records in the result
const TcaplusServiceRecord * pstTcapRecord = NULL;
int32_t dwCount = 0;
// Loop to get the number of records
while(dwCount++ < dwRecordCount)
{
int32_t iRet = pstTcapRspRcved->FetchRecord(pstTcapRecord);
if(0 != iRet || NULL == pstTcapRecord)
{
printf( "FetchRecord failed, iRet: %d \n", iRet);
tlog_error(g_pstLogHandler, 0, 0, "FetchRecord failed, iRet: %d.", iRet);
continue;
}
FOLLOWING_ACTION_LIST tagfollowing_action_list;
memset(&tagfollowing_action_list, 0, sizeof(tagfollowing_action_list));
// Get record data based on the TDR description
iRet = pstTcapRecord->GetData(&tagfollowing_action_list, sizeof(tagfollowing_action_list));
if(0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "GetData() failed, iRet:%d\n",iRet);
}
printf("----------Total record num %d ,the [%d] record is:\n", dwRecordCount, dwCount);
printf("ullGame: %d \n", tagfollowing_action_list.ullGame);
printf("dwMyuin: %d \n", tagfollowing_action_list.dwMyuin);
printf("bActiontype: %d \n", tagfollowing_action_list.bActiontype);
printf("dwUin2: %d \n", tagfollowing_action_list.dwUin2);
printf("szNick2: %s \n", tagfollowing_action_list.szNick2);
printf("bSex: %d \n", tagfollowing_action_list.bSex);
printf("szPid: %s \n", tagfollowing_action_list.szPid);
printf("dwTime: %d \n", tagfollowing_action_list.dwTime);
printf("szContent: %s \n", tagfollowing_action_list.szContent);
}
return 0;
}
4.1.6 Destroy the client (code path: examples/tcaplus/C++_common_for_tdr1.0/common.h)
When the process exits, first call the Fini function of the client, destroy the client, and then destroy the log handle to prevent the log coredump when the client exits
void Finish()
{
//Destroy the client first
g_stTcapSvr.Fini();
tlog_info(g_pstLogHandler, 0, 0, "mytest finish!");
//Then destroy the log handle
delete g_pstTlogger;
g_pstTlogger = NULL;
tlog_fini_ctx(&g_pstLogCtx);
}
4.1.7 Example asynchronous framework (code path: examples/tcaplus/C++_common_for_tdr1.0/common.h)
The proc main framework calls the corresponding functions to send requests, receive responses, and handle timeouts by implementing the three function pointers of the callback function. All examples of this framework are common
// Function callback mechanism
struct tagCallbackFunctions
{
// Send a request
int (*pfnSendRequest)(int32_t key);
// Receive the response
int (*pfnHandResponse)(TB_USERBUFFER* pstUserBuffer, TcaplusServiceResponse* pstTcapRspRcved);
// Timeout processing
int (*pfnHandTimeOutResponse)(int32_t dwKey);
};
typedef struct tagCallbackFunctions CALLBACK_FUNCTIONS;
CALLBACK_FUNCTIONS g_stCallbackFunctions;
int32_t main(int32_t argc, char *argv[])
{
int32_t iRet = 0;
// Initialization
iRet = Init();
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "Init failed, iRet: %d, please check the mytest.log for detail. ", iRet);
return iRet;
}
// Now set the callback function
g_stCallbackFunctions.pfnSendRequest = SendListGetAllRequest;
g_stCallbackFunctions.pfnHandResponse = HandleResponse;
g_stCallbackFunctions.pfnHandTimeOutResponse = HandleTimeoutResponse;
// Processing logics
iRet = Proc();
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "Mytest failed, iRet: %d, please check the mytest.log for detail. ", iRet);
}
// Clean up the environment
Finish();
return iRet;
}
int32_t Init()
{
int32_t iRet = 0;
// Initialize the log
iRet = InitLog();
if (0 != iRet)
{
return iRet;
}
// Initialize the client
iRet = InitServiceAPI();
if (0 != iRet)
{
return iRet;
}
return iRet;
}
#define TIME_MS_PER_SEC 1000
static int TOTAL_SEND_RECV_NUM = 5; // Number of loops to send requests, which can be changed to send multiple requests.
#define TCAPLUS_TIMEOUT_MS 10 * TIME_MS_PER_SEC // Timeout of receiving a res package after sending a req, in milliseconds
#define TCAPLUS_SLEEEP_US 1000 // Waiting time of a proc loop, in microseconds
std::map<int32_t,struct timeval> g_mapKeyTime; // The Map binary is the Key and time of sending data
// Asynchronous main processing framework
int32_t Proc()
{
int32_t iRet = 0;
// The variable iSendRequestCount used in this sample is to control the number of packages
int32_t iSendRequestCount = 0;
while(true)
{
int32_t iKey = iSendRequestCount;
// Send multiple requests asynchronously
if (iSendRequestCount < TOTAL_SEND_RECV_NUM)
{
if(NULL == g_stCallbackFunctions.pfnSendRequest)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stCallbackFunctions.pfnSendRequest is NULL, so will finish example.");
break;
}
iRet = (*g_stCallbackFunctions.pfnSendRequest)(iKey);
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "SendRequest failed, iRet: %d .", iRet);
break;
}
// Add a timestamp for timeout judgment
struct timeval now = {0};
gettimeofday(&now, NULL);
g_mapKeyTime[iKey] = now;
iSendRequestCount++;
}
// Receive and process packages
iRet = RecvPackage();
if (0 != iRet)
{
tlog_error(g_pstLogHandler, 0, 0, "RecvPackage failed, iRet: %d .", iRet);
break;
}
// Judge whether the returned packages corresponding to the sent requests have timed out. If the time for receiving a response package is longer than TIME_MS_PER_SEC, it indicates a timeout. Remove this key from g_mapKeyTime.
struct timeval now = { 0 };
gettimeofday(&now, NULL);
std::map<int32_t, struct timeval>::iterator iter;
for (iter = g_mapKeyTime.begin(); iter != g_mapKeyTime.end();)
{
int32_t iTotalUseTime = now.tv_sec * TIME_MS_PER_SEC + now.tv_usec / TIME_MS_PER_SEC - iter->second.tv_sec * TIME_MS_PER_SEC - iter->second.tv_usec / TIME_MS_PER_SEC;
if (iTotalUseTime > TCAPLUS_TIMEOUT_MS)
{
tlog_debug(g_pstLogHandler, 0, 0, "RecvPackage timeout, key is %d iTotalUseTime = %d ", iter->first, iTotalUseTime);
// Timeout processing
(*g_stCallbackFunctions.pfnHandTimeOutResponse)(iter->first);
g_mapKeyTime.erase(iter++);
}
else
{
iter++;
}
}
// If all packages have been sent and processed, break out of the loop and end Proc()
if (iSendRequestCount == TOTAL_SEND_RECV_NUM && 0 == g_mapKeyTime.size())
{
tlog_info(g_pstLogHandler, 0, 0, "All response is handle , so this test will finish. for more detail to read mytest.log!");
break;
}
// Other tasks...
usleep(TCAPLUS_SLEEEP_US);
}
return iRet;
}
#define MAX_HANDLE_COUNTER_ONBUSY 1000
// Receive response packages
int32_t RecvPackage()
{
uint32_t dwHandleCnter = 0;
uint32_t dwMaxHandleCnter = MAX_HANDLE_COUNTER_ONBUSY;
// The loop of receiving packages will be terminated when the number of loop times reaches MAX_HANDLE_COUNTER_ONBUSY and the response package TOTAL_SEND_RECV_NUM is still not received.
// Loop as many times as possible to prevent the Api local cache from becoming too full due to the accumulation of too many packages in the local area without processing, resulting in the proxy being unable to send the packages to Api and package loss.
while (dwHandleCnter++ < dwMaxHandleCnter)
{
// The response pointer returned by this warning function is globally shared, so do not call response -> Destruct or delete response manually after use.
TcaplusServiceResponse* pstTcapRspRcved = NULL;
// Receive response packages
int32_t iRet = g_stTcapSvr.RecvResponse(pstTcapRspRcved);
if (iRet < 0)
{
//If it failed, print the corresponding error code.
tlog_debug(g_pstLogHandler, 0, 0, "g_stTcapSvr.RecvResponse failed, iRet: %d.", iRet);
}
else
{
// If iRet == 1 is successful, it means a complete response package is received, and the output parameter response is a non-NULL pointer.
if(1 == iRet && NULL != pstTcapRspRcved)
{
TB_USERBUFFER *pstUserBuffer = NULL;
const char *sTmpUserBuffer = NULL;
size_t iTmpUserBuffSize;
// Get user-defined data. If UserBuff is set for the request package, the response package must have UserBuff; otherwise, an error will occur.
sTmpUserBuffer = pstTcapRspRcved->GetUserBuff(&iTmpUserBuffSize);
if(NULL == sTmpUserBuffer)
{
tlog_error(g_pstLogHandler, 0, 0, "GetUserBuff failed ! ");
continue;
}
pstUserBuffer = (TB_USERBUFFER*)sTmpUserBuffer;
if(NULL == pstUserBuffer)
{
tlog_error(g_pstLogHandler, 0, 0, "GetUserBuff failed ! ");
continue;
}
// Find whether there is a record corresponding to the key on the map. If yes, it indicates that the current key request has not timed out; otherwise, it means timeout. Enter different logic respectively.
int32_t dwKey = pstUserBuffer->m_dwMagicNo;
std::map<int32_t, struct timeval>::iterator it;
it = g_mapKeyTime.find(dwKey);
if (it != g_mapKeyTime.end())
{
if(NULL == g_stCallbackFunctions.pfnHandResponse)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stCallbackFunctions.pfnHandResponse is NULL, so will skip this package.");
}
else
{
// Delete the record of the key corresponding to the Map
g_mapKeyTime.erase(dwKey);
// Process the response package
(*g_stCallbackFunctions.pfnHandResponse)(pstUserBuffer, pstTcapRspRcved);
}
}
else
{
if(NULL == g_stCallbackFunctions.pfnHandTimeOutResponse)
{
tlog_error(g_pstLogHandler, 0, 0, "g_stCallbackFunctions.pfnHandTimeOutResponse is NULL, so will skip this package.");
}
else
{
tlog_error(g_pstLogHandler, 0, 0, "This Key = [%d] is time out, so don't handle it!", dwKey);
}
}
}
else
{
// If IRet == 0 is successful, it means a complete response package is not received.
tlog_debug(g_pstLogHandler, 0, 0, "this loop not recieve a complete package!");
break;
}
}
}
return 0;
}
5. Method Description in Request Object
Note: Other methods of the request object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.
/**
@brief: reset request data for next request preparation
@param [IN] cmd: request operation type. For details, see \link TCaplusApiCmds \endlink
@param [IN] user_buffer: user-defined message buffer, which is carried to the server as asynchronous message, and returned as is when returning the package
@param [IN] buffer_data_size: data size in the user-defined buffer. The maximum supported length is 1024
@param [IN] async_id: asynchronous transaction ID corresponding to the request. Tcaplus will bring its value back through the response message corresponding to the request unchanged
@param [IN] seq: request message serial number. Currently, tcaplus does not increase 1 to request message serial number on the Service Api side, nor does it process this message sequence number on the server side. Instead, it will bring its value back through the response message corresponding to the request unchanged
@param [IN] result_flag: result flag. The meaning of this parameter is the same as that of the parameter "IN char result_flag" in "int SetResultFlag (IN char result_flag)".
@retval 0 setting successful
@retval < 0 failed and returned the corresponding error code.
@note: the maximum length of user-defined data stored in the user_buffer parameter is 1024
*/
int Init(IN TCaplusApiCmds cmd,
IN const char* user_buffer = NULL, IN const size_t buffer_data_size = 0, IN uint64_t async_id = 0,
IN int32_t seq = 0, IN char result_flag = 0);
/**
@brief: get the request operation type
@retval TCAPLUS_API_INVALID_REQ: return invalid command number when not initialized.
@retval \link TCaplusApiCmds \endlink
*/
TCaplusApiCmds GetCmd() const;
/**
@brief: get the table name of the request operation
@param [OUT] table_name_size: If the table_name_size is not NULL, write the table name length to its specified position.
@retval NULL: return NULL when the TcaplusServiceRequest object is not initialized.
@retval !NULL: pointer to the table name to be operated.
*/
const char* GetTableName(OUT size_t* table_name_size = NULL) const;
/**
@brief: get the game zone ID of the request operation
@retval: operate the game zone ID
*/
int GetZoneId() const;
/**
@brief: set the user buffer, which is carried back by the response
@param [IN] user_buffer: user buffer pointer
@param [IN] buffer_data_size: user buffer length, and the maximum supported length is 1024
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code.
*/
int SetUserBuff(IN const char* user_buffer, IN const size_t buffer_data_size);
/**
@brief: get the user buffer information in the request
@param [OUT] buffer_data_size: If the buffer_data_size is not NULL, write the table name length to its specified position.
@retval NULL: return NULL when the TcaplusServiceRequest object is not initialized.
@retval !NULL: first pointer to the user buffer.
*/
const char* GetUserBuff(OUT size_t* buffer_data_size = NULL) const;
/**
@brief: set the asynchronous transaction ID corresponding to the request.
@param [IN] async_id: asynchronous transaction ID corresponding to the request. Tcaplus will bring its value back through the response message corresponding to the request unchanged
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code.
*/
int SetAsyncID(IN uint64_t async_id);
/**
@brief: get the asynchronous transaction ID corresponding to the request
@retval: asynchronous transaction ID
*/
uint64_t GetAsynID() const;
/**
@brief: set the request serial number
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
*/
int SetSequence(IN int32_t seq);
/**
@brief: get the request serial number
@retval: request serial number
*/
int32_t GetSequence() const;
/**
@brief: get the general flag bit of the request
@return: return the general flag bit of the request
@note: for a list of valid flag bits and a detailed explanation, please refer to SetFlags()
*/
int32_t GetFlags() const;
/**
@brief: add a record to the request.
@param [IN] index: used for List operations, and it is usually >=0, indicating the Index(not subscript) of the Record in the List.
It is used for TCAPLUS_API_LIST_ADDAFTER_REQ and TCAPLUS_API_LIST_ADDAFTER_BATCH_REQ in the List table. The index can take the command number of TCAPLUS_API_LIST_PRE_FIRST_INDEX or TCAPLUS_API_LIST_LAST_INDEX.
Index is the secondary key, and tcaplus automatically maintains its uniqueness. For the newly inserted record, the index will increase.
When cmd is TCAPLUS_API_LIST_ADDAFTER_REQ, it means that the record is inserted after the record containing the index (implicit constraint: the record containing the index must already exist);
The index also supports the following special values:
TCAPLUS_API_LIST_PRE_FIRST_INDEX: it means that the new element is inserted before the first element
TCAPLUS_API_LIST_LAST_INDEX: it means that the new element is inserted after the last element
For Generic operations, the index is meaningless and will be ignored.
@retval \link TcaplusRecord \endlink: return the record pointer
@retval NULL: failed to add a record
*/
TcaplusServiceRecord* AddRecord(IN int32_t index = -1);
/**
@brief: output request visualization
@param [INOUT] buffer: buffer pointer
@param [IN] buffer: buffer size
@retval: buffer pointer for the package, and the content ends with ' \0'
*/
const char* Print(INOUT char* buffer, IN size_t buffer_size);
/**
@brief: get the last recorded error message. Only when the logger initialization parameter is NULL will request automatically generate the buffer; Otherwise, the log will be automatically written, and this function returns NULL.
@retval: the last error message buffer.
*/
const char* GetLastError();
/**
@brief: set the name list of the Value fields for querying or updating, that is, querying and updating partial Value fields.
It can be used for get, batchget, partkeyget, listget, listgetall, listreplace, replace, update, tabletraverse operations.
@param [IN] field_name: list of field names that need to be queried or updated. The maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_count: number of field names
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
@note: When using the SetData() function to set data in update operations (replace, batchReplace, update, batchUpdate, listreplace operation),
if only partial fields need to be updated,
you can use this function to set the fields that need to be updated.
Note that when updating partial fields, it is important to call the SetData() function first, and then call the SetFieldNames() function
to achieve the function of updating partial fields.
@note: when using this function to set a field name, the field name can only contain the value field name, not the key field name
*/
int32_t SetFieldNames(IN const char* field_name[], IN const unsigned field_count);
/**
@brief: set the name list of the Value fields for querying, that is, querying partial Value fields.
It can be used for get, batchget, partkeyget, listget, listgetall operations.
@param [IN] field_name: field name to be queried. The maximum length of each field name is 32 bytes, and the name ends with '\0'
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t AddFieldName(IN const char* field_name);
/**
@brief: set the general flag bit of the request. Multiple values can be set at the same time through the "bit or" operation
@param [IN] flag: value of the request flag bit
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
@note: valid flag bits include:
* TCAPLUS_FLAG_FETCH_ONLY_IF_MODIFIED:
* "Fetch only if modified" flag bit: Before starting a read operation, the user code carries the version number of the locally buffered data through TcaplusServiceRecord::SetVersion()
* and sets this flag. When the storage end detects that the current data is consistent with the API buffered data version,
* it indicates that the record has not been modified and that the API buffered data is the latest. As a result, it will not return the actual data,
* but only the error code of TcapErrCode::COMMON_INFO_DATA_NOT_MODIFIED
*
* After this flag bit is set in the request, the response should first be received through TcaplusServiceResponse::GetFlags() to find out
* whether the TCAPLUS_FLAG_FETCH_ONLY_IF_MODIFIED flag was set when sending the request.
*
* Only the following requests support setting this flag:
* TCAPLUS_API_GET_REQ,
* TCAPLUS_API_LIST_GET_REQ,
* TCAPLUS_API_LIST_GETALL_REQ
*
* TCAPLUS_FLAG_FETCH_ONLY_IF_EXPIRED:
* "Fetch only if expired" flag bit: Before starting a read operation, the user code sets the data expiration time through SetExpireTime(),
* and set this flag. When the storage end detects that the record has been updated within the specified time, it will return the data.
* Otherwise, it will not return the actual data, but only the error code of TcapErrCode::COMMON_INFO_DATA_NOT_MODIFIED.
*
* After this flag bit is set in the request, the response should first be received through TcaplusServiceResponse::GetFlags() to find out
* whether the TCAPLUS_FLAG_FETCH_ONLY_IF_EXPIRED flag was set when sending the request.
*
* Only the following requests support setting this flag:
* TCAPLUS_API_BATCH_GET_REQ
*
* TCAPLUS_FLAG_ONLY_READ_FROM_SLAVE
* After setting this flag, the read request will be directly sent to the Tcapsvr Slave node.
* Tcapsvr Slave is usually relatively idle. Setting this flag helps to fully utilize Tcapsvr Slave resources.
*
* Applicable scenarios:
* read requests that do not require high data timeliness,
* including all read requests for the generic table and list table, as well as batch get and traversal requests
*
* TCAPLUS_FLAG_LIST_RESERVE_INDEX_HAVING_NO_ELEMENTS
* After setting this flag, the index and version need to be retained when deleting the last element in the List table.
* The ListDelete, ListDeleteBatch and ListDeleteAll operations set this flag when deleting the last element of the list table.
* When writing a new List record, the version number will increase and not be reset to 1.
*
* Applicable scenarios:
* app that needs to determine whether a table needs to retain index and version when deleting the last element.
* Mainly involves the use experience of the List table
*
*/
int SetFlags(int32_t flag);
/**
@brief: clear the general flag bit of the request. Multiple values can be set at the same time through the "bit or" operation
@param [IN] flag: value of the request flag bit
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
@note: for a list of valid flag bits and a detailed explanation, please refer to SetFlags()
*/
int ClearFlags(int32_t flag);
/**
@brief: set the result flag. It is mainly used for inserting, increasing, replacing, updating, deleting Generic tables, and deleting and replacing list tables.
@param [IN] result_flag request flag:
0 means: return whether the operation was successfully executed
1 means: return the data same with the request
2 means: return the latest data for all fields in the modified record
3 means: return the old data for all fields in the modified record
For batch_get requests, when this field is set to greater than 0, the corresponding key will be returned when a key query record does not exist or there are other errors generated by the svr side,
so as to know which key corresponding record failed
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
@Note: if using this interface, part request flags are actually not supported. It is strongly recommended to use the SetResultFlagForSuccess interface and the SetResultFlagForFail interface
*/
int SetResultFlag(IN char result_flag);
/**
@brief: set the result flag. It mainly refers to the data returned to the front-end after the successful execution of this request
The value range of result_flag is as follows:
TCaplusValueFlag_NOVALUE = 0, // Do not return any return value
TCaplusValueFlag_SAMEWITHREQUEST = 1, // Return the value consistent with the request
TCaplusValueFlag_ALLVALUE = 2, // Return the value of all fields after the tcapsvr operation
TCaplusValueFlag_ALLOLDVALUE = 3, // Return the value of all fields before the tcapsvr operation
The following are the details of the data returned to the API side after successful execution of each supported command word with different results set:
1. TCAPLUS_API_INSERT_REQ TCAPLUS_API_BATCH_INSERT_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return the data after this insert operation after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return null data after successful operation
2. TCAPLUS_API_REPLACE_REQ TCAPLUS_API_BATCH_REPLACE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return the data after this replace operation after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. If there is no data on tcapsvr, return null data
3. TCAPLUS_API_UPDATE_REQ TCAPLUS_API_BATCH_UPDATE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return the data after this update operation after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation
4. TCAPLUS_API_INCREASE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return the data after this increase operation after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. If there is no data on tcapsvr, return null data
5. TCAPLUS_API_DELETE_REQ TCAPLUS_API_BATCH_DELETE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return null data after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation
6. TCAPLUS_API_LIST_DELETE_BATCH_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, return no data after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. All data corresponding to the index successfully deleted this time will be returned
7. TCAPLUS_API_LIST_ADDAFTER_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, return the records inserted this time and the records expired this time after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return no value after successful operation
8. TCAPLUS_API_LIST_DELETE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, return null data after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listdelete operation on tcapsvr after successful operation
9. TCAPLUS_API_LIST_REPLACE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, return the data after the listreplace operation on tcapsvr after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listreplace operation on tcapsvr after successful operation
10. TCAPLUS_API_LIST_REPLACE_BATCH_REQ
If TCaplusValueFlag_NOVALUE is set, return the data same with the request after successful operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
If TCaplusValueFlag_ALLVALUE is set, return the data after the listreplace operation on tcapsvr after successful operation
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listreplace operation on tcapsvr after successful operation
@param [IN] result_flag request flag:
0 means: return whether the operation was successfully executed
1 means: return the data same with the request
2 means: return the latest data for all fields in the modified record
3 means: return the old data for all fields in the modified record
For batch_get requests, when this field is set to greater than 0, the corresponding key will be returned when a key query record does not exist or there are other errors generated by the svr side,
so as to know which key corresponding record failed
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
*/
int SetResultFlagForSuccess (char result_flag);
/**
@brief: set the result flag. It mainly refers to the data returned to the front-end after the failed execution of this request
The value range of result_flag is as follows:
TCaplusValueFlag_NOVALUE = 0, // Do not return any return value
TCaplusValueFlag_SAMEWITHREQUEST = 1, // Return the value consistent with the request
TCaplusValueFlag_ALLVALUE = 2, // Return the value of all fields after the tcapsvr operation
TCaplusValueFlag_ALLOLDVALUE = 3, // Return the value of all fields before the tcapsvr operation
The following are the details of the data returned to the API side after the failed execution of each supported command word with different results set:
1. TCAPLUS_API_INSERT_REQ TCAPLUS_API_BATCH_INSERT_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
2. TCAPLUS_API_REPLACE_REQ TCAPLUS_API_BATCH_REPLACE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
3. TCAPLUS_API_UPDATE_REQ TCAPLUS_API_BATCH_UPDATE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
4. TCAPLUS_API_INCREASE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
5. TCAPLUS_API_DELETE_REQ TCAPLUS_API_BATCH_DELETE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
6. TCAPLUS_API_LIST_DELETE_BATCH_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. All data corresponding to the index successfully deleted this time will be returned
7. TCAPLUS_API_LIST_ADDAFTER_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return no value
8. TCAPLUS_API_LIST_DELETE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
9. TCAPLUS_API_LIST_REPLACE_REQ
If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side
@param [IN] result_flag request flag:
0 means: return whether the operation was successfully executed
1 means: return the data same with the request
2 means: return the latest data for all fields in the modified record
3 means: return the old data for all fields in the modified record
For batch_get requests, when this field is set to greater than 0, the corresponding key will be returned when a key query record does not exist or there are other errors generated by the svr side,
so as to know which key corresponding record failed
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
*/
int SetResultFlagForFail (char result_flag);
/**
@brief: get the result flag
@return: return the result flag
*/
char GetResultFlag() const;
/**
@brief: get the result flag, mainly using the value set by SetResultFlagForSuccess
@return: return the result flag
*/
char GetResultFlagForSuccess () const;
/**
@brief: get the result flag, mainly using the value set by SetResultFlagForFail
@return: return the result flag
*/
char GetResultFlagForFail () const;
/**
@Brief: set the mode of deleting old elements at the time of inserting elements when LIST is full
@param [in] chListShiftFlag TCAPLUS_LIST_SHIFT_NONE: It is not allowed to delete elements. If LIST is full, the insertion fails; TCAPLUS_ LIST_ SHIFT_ HEAD: Remove the first element; TCAPLUS_ LIST_ SHIFT_ TAIL: Remove the last element
If the table is a sort List, the user will fail to call the interface in the case that expiration must be done, and the expiration rules are automatically determined based on the sorting order of the fields
@Retval 0: setting successful
@Retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t SetListShiftFlag(IN const char chListShiftFlag = TCAPLUS_API_LIST_SHIFT_HEAD);
/**
@brief: get the list shift flag
@return: return the list shift flag
*/
char GetListShiftFlag() const;
6. Method Description in Response Object
Note: Other methods of response object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.
/**
@brief: get the table name of the request operation
@param [OUT] table_name_size: if the table_name_size is not NULL, write the table name length to its specified position,
and the length includes the ending '\0'.
@retval NULL: return NULL when the TcaplusServiceResponse object is not initialized.
@retval !NULL: pointer to the table name to be operated.
*/
const char* GetTableName(OUT size_t* table_name_size = NULL) const;
/** \brief: get the operation result
* \retval 0: operation successful
* \retval >0: operation result warning. For example, if getting or deleting a nonexistent data record, the retval returns TcapErrCode::SVR_ERR_FAIL_RECORD_EXIST. For error details, see \link ErrorCode \endlink
* \retval< 0: operation result error. For example, if writing data fails, the retval returns TcapErrCode::SVR_ERR_FAIL_WRITE_RECORD. For error details, see \link ErrorCode \endlink
*/
int32_t GetResult() const;
/**
@brief: get the APPID
@retval non-0: return the app_id in the response package
@retval 0: return 0 by default if the object has not been initialized or the response package has not been parsed
*/
int64_t GetAppId() const;
/**
@brief: get the ZoneId
@retval non-0 Return the zone_id in the response package
@retval 0: return 0 by default if the object has not been initialized or the response package has not been parsed
*/
int GetZoneId() const;
/**
@brief: get the result operation type
@retval \link TCaplusApiCmds \endlink
*/
TCaplusApiCmds GetCmd() const;
/**
@brief: get the request sub-operation type, which is meaningful for document operations
@retval \link TCaplusApiCmds \endlink
*/
uint32_t GetSubCmd() const;
/**
@brief: get the asynchronous transaction ID corresponding to the result
@retval: asynchronous transaction ID
*/
uint64_t GetAsynID() const;
/**
@brief: get the result serial number
@retval: result serial number
*/
int32_t GetSequence() const;
/**
@brief: get the general flag bit of the response
@return: return the general flag bit of the response
@note: for a list of valid flag bits and a detailed explanation, please refer to TcaplusServiceRequest::SetFlags(int)
*/
int32_t GetFlags() const;
/**
@brief: get the user buffer information in the response
@param [out] buffer_data_size: user buffer data size. If the buffer_data_size is not NULL, write the table name length to its specified position.
@retval NULL: return NULL when the TcaplusServiceResponse object is not initialized.
@retval !NULL: first pointer to the user buffer.
*/
const char* GetUserBuff(OUT size_t* buffer_data_size = NULL) const;
/**
@brief: get the number of result records in this response
@brief: the number of result records in this response
*/
int32_t GetRecordCount() const;
/**
@brief: get a record from the result
@param [OUT]: pointer to the returned record
@retval 0: record getting successful
@retval 0: record getting failed
@note: after getting the TcaplusServiceRecord object for this operation through this function, the TcaplusServiceRecord object got from the previous operation will be overwritten
*/
int32_t FetchRecord(OUT const TcaplusServiceRecord*& record);
/**
@brief: output visualization
@param [INOUT] buffer: buffer pointer
@param [IN] buffer: buffer size
@retval: buffer pointer for the package, and the content ends with ' \0'
*/
const char* Print(INOUT char* buffer, IN size_t buffer_size);
7. Method Description in Record Object
Note: Other methods of response object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.
- Common method of record:
/**
@brief: set the version number of the record
@param [IN] iVersion: version number of the record <=0: it means that the version number is not important. The specific meaning is as follows.
When the value of the parameter type passed into the int SetCheckDataVersionPolicy(enum tagCHECKDATAVERSIONTYPE type) function of class TcaplusServiceRequest is CHECKDATAVERSION_AUTOINCREASE: it means that the record version number is to be checked. If the value of the parameter iVersion passed into the void SetVersion (IN int32_t iVersion) function of class TcaplusServiceRecord is <= 0, it still means that the version number is not important; if the value of the parameter iVersion passed into the void SetVersion (IN int32_t iVersion) function of class TcaplusServiceRecord is > 0, the Replace, Update, Increase, ListAddAfter, ListDelete, ListReplace, and ListDeleteBatch operations will succeed only if the version number is the same as the server side version number. And the version number will increase by 1 on the server side.
When the value of the parameter type passed into the int SetCheckDataVersionPolicy(enum tagCHECKDATAVERSIONTYPE type) function of the class TcaplusServiceRequest is NOCHECKDATAVERSION_OVERWRITE: it means that the record version number is not checked. If the value of the parameter iVersion passed into the void SetVersion (IN int32_t iVersion) function of class TcaplusServiceRecord is <= 0, the version number 1 will be written to the record version number on the server side (the record version number successfully written on the server side is at least 1); if the value of the parameter iVersion passed into the void SetVersion (IN int32_t iVersion) function of class TcaplusServiceRecord is > 0, the version number will be written to the record version number on the server side.
When the value of the parameter type passed into the int SetCheckDataVersionPolicy(enum tagCHECKDATAVERSIONTYPE type) function of class TcaplusServiceRequest is NOCHECKDATAVERSION_AUTOINCREASE: It means that the record version number is not checked, and the version number on the server side will increase by 1. If the server side newly writes a data record, the newly written data record version number is 1.
@retval void
*/
//Attention: For the Generic operation, it means setting the version of the Record, whereas for the List operation, it means setting the version of the List unit in which the Record is located.
void SetVersion(IN int32_t iVersion);
/**
@brief: get the record version number
@retval: record version number
@note: For the Generic operation, it means getting the version of the Record; whereas for the List operation, it means getting the version of the List in which the Record is located.
*/
int32_t GetVersion() const;
/**
@brief: set the filter conditions for the record based on the TDR description
@param [IN] condition: condition state
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t SetCondition(const std::string &condition);
/**
@brief: set the operation state of the array in the record based on the TDR description
@param [IN] operation: operation state, including PUSH/POP/SET/GET
@param [IN] operateOption: operation option, useful only for GET. See enum RecordOperationOption
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t SetOperation(const std::string &operation, int operateOption = 0);
/**
@brief: get the record subscript or index
@retval: for Generic type operations, return the record subscript in the record array; for a List type operation, return the record index in the List. When the index value is - 1, it means an invalid record subscript or index. In particular, for the addafter operation in the List table, this method can get the index of the newly added list element.
*/
int32_t GetIndex() const;
- Record can be set and extracted based on TDR structure
/**
@brief: set the record data based on the TDR description
@param [IN] data_buffer: data buffer
@param [IN] data_size: data buffer size
@param [IN] data_version: data version number, see the SetVersion function. The default value of -1 means that version number is not verified during write operations and the version number is not important. The value of data_version <= 0 means that the version number is not verified during write operations, and the version number is not important.
@param [IN] data_meta: meta description of the data in the data buffer; when it is NULL, automatically use the default meta information set by request. See the SetTable function.
@param [IN] partkey_index_name: index name of the part key.
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t SetData(IN const void* data_buffer, IN size_t data_size,
IN int32_t data_version = -1, IN LPTDRMETA data_meta = NULL,
IN const char* partkey_index_name = NULL);
/**
@brief: get the record data based on the TDR description
@param [OUT] data_buffer: data buffer; first initialize it through memset or tdr_init
@param [IN] data_size: data buffer size
@param [OUT] data_version: data version number, see the GetVersion function.
@param [IN] data_meta: meta description of the data to be fetched; when it is NULL, automatically use the default meta information set by response. See the SetTable function.
@retval 0: setting successful
@retval <0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetData(OUT void* data_buffer, IN size_t data_buffer_size,
OUT int32_t* data_version = NULL, IN LPTDRMETA data_meta = NULL) const;
- Record also supports the SetKey and SetValue interfaces for setting record fields and the GetKey and GetValue interfaces for fetching record fields. However, SetKey, SetValue, GetKey, and GetValue cannot be used with the SetData and GetData interfaces
- The data set by the SetKey SetValue interface can only be read through the GetKey and GetValue interfaces,When using the batch command for the SetKey SetValue interface, you should pay attention to that after the record setting is completed, you can call Pack () to package the records; SetData is one-time, and function calls will be automatically packaged. SetKey SetValue is not sure when the user has set the last field, so the user needs to call Pack () to package the records after setting kv
- The data set by the SetData interface can only be read through GetData
/**
@brief: general key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 1024 bytes
@param [IN] value_size: field value size
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKey(IN const char* field_name, IN const void * field_value, IN const size_t value_size);
/**
@brief: int8_t type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyInt8(IN const char* field_name, IN const int8_t field_value);
/**
@brief: int16_t type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyInt16(IN const char* field_name, IN const int16_t field_value);
/**
@brief: int32_t type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyInt32(IN const char* field_name, IN const int32_t field_value);
/**
@brief: int64_t type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyInt64(IN const char* field_name, IN const int64_t field_value);
/**
@brief: float type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyFloat(IN const char* field_name, IN const float field_value);
/**
@brief: double type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyDouble(IN const char* field_name, IN const double field_value);
/**
@brief: string type key field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 1024 bytes, ending with '\0'
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyStr(IN const char* field_name, IN const char* field_value);
/**
@brief: blob type key field value settings
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 1024 bytes
@param [IN] value_size: field value size
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetKeyBlob(IN const char* field_name, IN const char* field_value, IN const size_t value_size);
/**
@brief: general value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB)
@param [IN] value_size: field value size
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValue(IN const char* field_name, IN const void * field_value, IN const size_t value_size);
/**
@brief: int8_t type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueInt8(IN const char* field_name, IN const int8_t field_value);
/**
@brief: int16_t type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueInt16(IN const char* field_name, IN const int16_t field_value);
/**
@brief: int32_t type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueInt32(IN const char* field_name, IN const int32_t field_value);
/**
@brief: int64_t type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueInt64(IN const char* field_name, IN const int64_t field_value);
/**
@brief: float type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueFloat(IN const char* field_name, IN const float field_value);
/**
@brief: double type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueDouble(IN const char* field_name, IN const double field_value);
/**
@brief: string type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB), ending with '\0'
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueStr(IN const char* field_name, IN const char* field_value);
/**
@brief: blob type value field value setting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [IN] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB)
Note: For the Blob type, the system will reserve 2 B for version number construction, so do not write more than (maximum length - 2 B).
@param [IN] value_size: field value size
@retval 0: setting successful
@retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
*/
int SetValueBlob(IN const char* field_name, IN const char* field_value, IN const size_t value_size);
/**
@brief: general key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 1024 bytes
@param [OUT] value_size: field value size
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKey(IN const char* field_name, OUT void *& field_value, OUT size_t & value_size) const;
/**
@brief: int8_t type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyInt8(IN const char* field_name, OUT int8_t & field_value) const;
/**
@brief: int16_t type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyInt16(IN const char* field_name, OUT int16_t & field_value) const;
/**
@brief: int32_t type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyInt32(IN const char* field_name, OUT int32_t & field_value) const;
/**
@brief: int64_t type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyInt64(IN const char* field_name, OUT int64_t & field_value) const;
/**
@brief: float type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyFloat(IN const char* field_name, OUT float & field_value) const;
/**
@brief: double type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyDouble(IN const char* field_name, OUT double & field_value) const;
/**
@brief: string type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 1024 bytes, ending with '\0'
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyStr(IN const char* field_name, OUT const char*& field_value) const;
/**
@brief: blob type key field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 1024 bytes
@param [OUT] value_size: field value size
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKeyBlob(IN const char* field_name, OUT const char*& field_value, OUT size_t & value_size) const;
/**
@brief: number of key fields getting
@retval 0: number of key fields
*/
uint32_t GetKeyCount() const;
/**
@brief: key field value getting
@param [IN] fieldIndex: field index, and its valid value must be greater than or equal to 0 and less than GetKeyNum()
@param [OUT] field_value: field name, and the type is string
@param [OUT] field_value: field value, and the maximum length is 1024 bytes
@param [OUT] value_size: field value size
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetKey(IN uint32_t fieldIndex, OUT const char*& field_name, OUT const void *& field_value, OUT size_t& fieldValueLen) const;
/**
@brief: general value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 128 KB
@param [OUT] value_size: field value size
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValue(IN const char* field_name, OUT void *& field_value, OUT size_t & value_size) const;
/**
@brief: int8_t type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueInt8(IN const char* field_name, OUT int8_t & field_value) const;
/**
@brief: int16_t type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueInt16(IN const char* field_name, OUT int16_t & field_value) const;
/**
@brief: int32_t type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueInt32(IN const char* field_name, OUT int32_t & field_value) const;
/**
@brief: int64_t type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueInt64(IN const char* field_name, OUT int64_t & field_value) const;
/**
@brief: float type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueFloat(IN const char* field_name, OUT float & field_value) const;
/**
@brief: double type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueDouble(IN const char* field_name, OUT double & field_value) const;
/**
@brief: string type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB), ending with '\0'
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueStr(IN const char* field_name, OUT const char*& field_value) const;
/**
@brief: blob type value field value getting
@param [IN] field_name: field name, the maximum length of each field name is 32 bytes, and the name ends with '\0'
@param [OUT] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB)
@param [OUT] value_size: field value size
@retval 0: getting successful
@retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValueBlob(IN const char* field_name, OUT const char*& field_value, OUT size_t & value_size) const;
/**
@brief: number of Value fields getting
* \retval 0: number of Value fields
*/
uint32_t GetValueCount() const;
/**
@brief: Value field value getting
* \param [IN] fieldIndex: field index, and its valid value must be greater than or equal to 0 and less than GetValueNum()
* \param [OUT] field_name: field name, and the type is string
* \param [OUT] field_value: field value, and the maximum length is 128 KB (When Tcapsvr >= 3.24.0, the maximum length is 256 KB)
* \param [OUT] value_size: field value size
* \retval 0: getting successful
* \retval non-0: getting failed. For specific errors, see \link ErrorCode \endlink
*/
int32_t GetValue(IN int fieldIndex, OUT const char*& field_name, OUT const void *& field_value, OUT size_t& fieldValueLen) const;
8. FAQ
For details, see Meaning and Handling of Error Codes.
8. Other Reference Documents
[TDR List Table] [Java SDK] Interface Description for Getting All Elements from a List
[TDR List Table] [Go SDK] Interface Description for Getting All Elements from a List