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 the 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, and owner_inDate, 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 |
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); // Adds 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtracts 20 from the def of the existing data
updateParam.AddCalculation("exp", GameInfoOperator.division, 2); // Decreases the exp of the existing data by 1/2
updateParam.AddCalculation("money", GameInfoOperator.multiplication, 1.25); // Increases the money of the existing data by 1.25 times
// Looks 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); // Adds 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtracts 20 from the def of the existing data
updateParam.AddCalculation("exp", GameInfoOperator.division, 2); // Decreases the exp of the existing data by 1/2
updateParam.AddCalculation("money", GameInfoOperator.multiplication, 1.25); // Increases the money of the existing data by 1.25 times
// Looks 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); // Adds 10 to atk of the existing data
updateParam.AddCalculation("def", GameInfoOperator.subtraction, 20); // Subtracts 20 from the def of the existing data
updateParam.AddCalculation("exp", GameInfoOperator.division, 2); // Decreases the exp of the existing data by 1/2
updateParam.AddCalculation("money", GameInfoOperator.multiplication, 1.25); // Increases the money of the existing data by 1.25 times
// Looks 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
});
Return cases
Success cases
When the modification is successful
statusCode : 204
Error cases
When the total number of columns to be calculated is over 290
statusCode : 400
errorCode : ValidationException
When the data in Param is not modified as AddCalculation type
statusCode : 400
errorCode : BadParameterException
When there is an attempt to modify data that is not a number type
statusCode : 400
errorCode : ValidationException
When the user tries to modify a non-existent column
statusCode : 400
errorCode : ValidationException
When the tableName does not exist
statusCode : 404
errorCode : NotFoundException
When the user searches the table to be updated with the where condition, but the table does not exist
statusCode : 404
errorCode : NotFoundException
When there is an attempt to search for a column whose schema is not defined with the where condition
statusCode : 404
errorCode : NotFoundException
(Schema) When there is an attempt to modify a null or non-existent column
statusCode : 404
errorCode : NotFoundException
When the eight fields(partition, gamer_id, inDate, updatedAt, sender, receiver, reservationDate, and owner_inDate) are included in param
statusCode : 405
errorCode : MethodNotAllowedParameterException
When an attempt is made to modify an inactive table
statusCode : 412
errorCode : PreconditionFailed
When one row(group of columns) exceeds 400 KB
statusCode : 413
errorCode : ServerErrorException