UpdateWithCalculation
public BackendReturnObject UpdateWithCalculation(string tableName, Where where, Param param);
Parameters
Value | Type | Description |
---|---|---|
tableName | string | Name of table to be updated |
where | Where | param used to find rows to be updated |
param | Param | Information to be updated (inserts data using AddCalculation) |
Description
From the values stored in the table, searches and modifies one row that corresponds to the 'where' conditional statement.
- The data can be modified regardless of schema definition status.
- Only one row can be modified.
- If multiple rows are retrieved by the where query, the last inserted row is modified.
- Regardless of the public/private status, you can only modify your own data.
The number type data stored in the table are modified via the four fundamental arithmetic operations.
You can add, subtract, multiply, or divide the base value by the number you enter.
- When using this method, the parameter's param must only use AddCalculation(). (Typing Add() will cause an error.)
- Modification of game information can be performed for only one row.
- When multiple rows are found with the where query, the most recently inserted row will be modified.
- Update() only requires the data to be modified; however, in the case of UpdateWithCalculation(), you may experience a heavier usage of DB compared to Update because the process checks and modifies the numbers of the data.
If calculation is attempted without conditions
When the condition is not specified, such as in the case of new Where(), the modification is proceeded after the calculation for the row most recently added from the rows owned by the user.
Reserved column
When saving, eight fields, including partition, gamer_id, inDate, updatedAt, sender, receiver, reservationDate, owner_inDate, client_date, are used by the server.
When these columns are included in the param, an error occurs.
Value | Description | Whether the value is displayed in BACKND Console |
---|---|---|
partition | Value used by the server to classify a table | X |
gamer_id | Gamer ID of the row owner | O |
inDate | inDate of the row (key value) | O |
updatedAt | Time the table was last modified | O |
sender | Value used internally for BACKND function (e.g., mail) | X |
receiver | Value used internally for BACKND function (e.g., mail) | X |
reservationDate | Value used internally for BACKND function (e.g., mail) | X |
owner_inDate | User inDate of the row owner | O |
client_date | The time when the client first requested data creation | O |
In the case of old version tables' rows without the owner_inDate, an owner_inDate column is added when the rows are updated by using the corresponding method.
Example
Synchronous
Param updateParam = new Param();
updateParam.AddCalculation("atk", GameInfoOperator.addition, 10); // Add 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtract 20 from the def of the existing data
// Look up the most recent data with sword_dragon as itemCode
Where where = new Where();
where.Equal("itemCode", "sword_dragon");
Backend.GameData.UpdateWithCalculation("tableName", where, updateParam);
Asynchronous
Param updateParam = new Param();
updateParam.AddCalculation("atk", GameInfoOperator.addition, 10); // Add 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtract 20 from the def of the existing data
// Look up the most recent data with sword_dragon as itemCode
Where where = new Where();
where.Equal("itemCode", "sword_dragon");
Backend.GameData.UpdateWithCalculation("tableName", where, updateParam, callback =>
{
// Post-process
});
SendQueue
Param updateParam = new Param();
updateParam.AddCalculation("atk", GameInfoOperator.addition, 10); // Add 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtract 20 from the def of the existing data
// Look up the most recent data with sword_dragon as itemCode
Where where = new Where();
where.Equal("itemCode", "sword_dragon");
SendQueue.Enqueue(Backend.GameData.UpdateWithCalculation, "tableName", where, updateParam, callback =>
{
// Post-process
});
ReturnCase
Success cases
When the modification is successful
statusCode : 204
message : Success
Error cases
When the total number of columns to be calculated is over 290
statusCode : 400
errorCode : ValidationException
message : Invalid UpdateExpression: Expression size has exceeded the maximum allowed size;
When the data in Param is not modified as AddCalculation type
statusCode : 400
errorCode : BadParameterException
message : bad operator have to been, Invalid operator
When there is an attempt to modify data that is not a number type
statusCode : 400
errorCode : ValidationException
message : An operand in the update expression has an incorrect data type
When the user tries to modify a non-existent column
statusCode : 400
errorCode : ValidationException
message : An operand in the update expression has an incorrect data type
When the tableName does not exist
statusCode : 404
errorCode : NotFoundException
message : table not found, table cannot be found
When the user searches the table to be updated with the where condition, but the table does not exist
statusCode : 404
errorCode : NotFoundException
message : gameInfo not found, gameInfo cannot be found
When there is an attempt to search for a column whose schema is not defined with the where condition
statusCode : 404
errorCode : NotFoundException
message : column not found, column cannot be found
(Schema) When there is an attempt to modify a null or non-existent column
statusCode : 404
errorCode : NotFoundException
message : column not found, column cannot be found
When the eight fields (partition, gamer_id, inDate, updatedAt, sender, receiver, reservationDate, and owner_inDate) are included in param
statusCode : 405
errorCode : MethodNotAllowedParameterException
message : MethodNotAllowed {param value}, Unavailable {param value}
When an attempt is made to modify an inactive table
statusCode : 412
errorCode : PreconditionFailed
message : inactiveTable prerequisites are not met.
When one row (group of columns) exceeds 400 KB
statusCode : 413
errorCode : ServerErrorException
message : request entity too large