[PB] BatchInsertRecords
Supported version: 3.50.0
Brief Introduction
The insertion method can add data in batches in the PB table. The batch insert interface is not an atomic interface. It allows for partial success and partial failure. The user needs to judge the number of successful or failed records according to the return value.
POST http://{Tcaplus_REST_URL}
Request Syntax
Http Request
#Tencent Cloud Console RESTful Endpoint, ip: 80, port: 80 by default
http://172.17.0.22
#TcaplusDB Local docker RESTful Endpoint, ip: 31001, port: 31001 by default
http://9.135.8.93:31001
Http Head
x-tcaplus-target:Tcaplus.BatchInsertRecords
x-tcaplus-app-id:{string}
x-tcaplus-zone-id:{string}
x-tcaplus-protocol-version:{string}
x-tcaplus-table-name:{string}
x-tcaplus-pwd-md5:{string}
x-tcaplus-result-flag:result_flag
x-tcaplus-version:{string}
x-tcaplus-data-version-check:{string}
x-tcaplus-idl-type:protobuf
Parameter description:
| Name | Required or not | Limitations | Description |
|---|---|---|---|
| x-tcaplus-target | Yes | None | Tcaplus.BatchInsertRecords |
| x-tcaplus-version | Yes | None | Tcaplus3.50.0 |
| x-tcaplus-app-id | Yes | None | Correspond to the app id number(aka, cluster access id) |
| x-tcaplus-zone-id | Yes | None | Correspond to the zone number (aka, table group id) |
| x-tcaplus-protocol-version | Yes | None | Correspond to the protocol version number, default 2.0 |
| x-tcaplus-table-name | Yes | None | Correspond to the table name |
| x-tcaplus-pwd-md5 | Yes | None | App password (aka, cluster access password), that is, the md5 value after the calculation |
| x-tcaplus-idl-type | Yes | None | protobuf |
| x-tcaplus-result-flag | No | None | 0: No data will be returned after successful operation; 1: After the operation is successful, the data that is consistent with the request will be returned; 2: After the operation is successful, the data after this update operation will be returned; 3: After the operation is successful, the data before the tcapsvr operation will be returned |
| x-tcaplus-data-version-check | No | 1: Detect the record version number. Only when the version number is the same as the server version number, the version number will automatically increase; 2: Do not detect the record version number, but force the client record version number to be written to the server; 3: Do not detect the record version number, and automatically increase the server version number | |
| x-tcaplus-data-version | No | Version number |
Example:
x-tcaplus-target:Tcaplus.BatchInsertRecords
x-tcaplus-app-id:3
x-tcaplus-zone-id:1
x-tcaplus-protocol-version:2.0
x-tcaplus-table-name:game_players
x-tcaplus-pwd-md5:4e81984efccfb4982333aeb1ff7968d5
x-tcaplus-result-flag:2
x-tcaplus-version:Tcaplus3.50.0
x-tcaplus-data-version-check: 3
x-tcaplus-idl-type:protobuf
Data
Use json format to represent the record related information. Parameter description:
- MultiRecords: Record set
- Record: Required, sub-record data
{
"MultiRecords": [{
"Record": {
"player_id": 5,
"player_name": "5",
"player_email": "5",
"game_server_id": 5,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 5,
"amount": 5,
"method": 5
}
}
}, {
"Record": {
"player_id": 5,
"player_name": "5",
"player_email": "55",
"game_server_id": 55,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 55,
"amount": 55,
"method": 55
}
}
}, {
"Record": {
"player_id": 6,
"player_name": "6",
"player_email": "6",
"game_server_id": 6,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 6,
"amount": 6,
"method": 6
}
}
}]
}
Complete Request Example
curl -i -XPOST -H 'x-tcaplus-target: Tcaplus.BatchInsertRecords' -H 'x-tcaplus-app-id: 70' -H 'x-tcaplus-zone-id: 1' -H 'x-tcaplus-protocol-version: 2.0' -H 'x-tcaplus-table-name: game_players' -H 'x-tcaplus-pwd-md5: 0972ad76decf4d11a69e2e0d9af335da' -H 'x-tcaplus-result-flag: 2' -H 'x-tcaplus-version: Tcaplus3.50.0' -H 'x-tcaplus-data-version-check: 3' -H 'x-tcaplus-idl-type: protobuf' http://172.17.32.17 -d '{
"MultiRecords": [{
"Record": {
"player_id":5,
"player_name":"5",
"player_email":"5",
"game_server_id":5,
"login_timestamp":[],
"logout_timestamp":[],
"is_online":false,
"pay": {
"pay_id": 5,
"amount": 5,
"method": 5
}
}
}, {
"Record": {
"player_id":5,
"player_name":"5",
"player_email":"55",
"game_server_id":55,
"login_timestamp":[],
"logout_timestamp":[],
"is_online":false,
"pay": {
"pay_id": 55,
"amount": 55,
"method": 55
}
}
},{
"Record": {
"player_id":6,
"player_name":"6",
"player_email":"6",
"game_server_id":6,
"login_timestamp":[],
"logout_timestamp":[],
"is_online":false,
"pay": {
"pay_id": 6,
"amount": 6,
"method": 6
}
}
}]
}'
Return Syntax
Return Parameter Description
| Parameter name | Description |
|---|---|
| ErrorCode | Return code |
| ErrorMsg | Return message |
| ReturnValues | The reserved data set by the user arrives at tcaplus with the request and is returned in the original form by the response |
| SucceedRecords | Data returned of successful records in json format. For details, refer to Data section |
| SucceedNum | Number of successful records |
| FailedRecords | Data returned of failed records in json format. For details, refer to Data section |
| FailedNum | Number of failed records |
Return Example
Successful Return Example
{
"ErrorCode": 0,
"ErrorMsg": "Succeed",
"SucceedRecords": [{
"RecordVersion": 1,
"Record": {
"player_id": 5,
"player_name": "5",
"player_email": "5",
"game_server_id": 5,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 5,
"amount": 5,
"method": 5
}
}
}, {
"RecordVersion": 1,
"Record": {
"player_id": 5,
"player_name": "5",
"player_email": "55",
"game_server_id": 55,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 55,
"amount": 55,
"method": 55
}
}
}, {
"RecordVersion": 1,
"Record": {
"player_id": 6,
"player_name": "6",
"player_email": "6",
"game_server_id": 6,
"login_timestamp": [],
"logout_timestamp": [],
"is_online": false,
"pay": {
"pay_id": 6,
"amount": 6,
"method": 6
}
}
}],
"SucceedNum": 3
}
Failed Return Example
{
"ErrorCode": -1293,
"ErrorMsg": "tcapsvr_fail_record_exist",
"SucceedRecords": [],
"SucceedNum": 0,
"FailedRecords": [{
"Record": {
"player_email": "5",
"player_id": 5,
"player_name": "5"
}
}, {
"Record": {
"player_email": "55",
"player_id": 5,
"player_name": "5"
}
}, {
"Record": {
"player_email": "6",
"player_id": 6,
"player_name": "6"
}
}],
"FailedNum": 3
}
Error code
Refer to Common Error Codes
Other Reference Documents
[PB Generic Table][C++ SDK] Interface Description for Batch-Inserting Multiple Records
[[PB Generic Table] [Go SDK] Interface Description for Batch-Inserting Records(../../02Go_SDK/02Interface_Documents/12[Generic_Table]Batch_Insert_Multiple_Records.md