Skip to main content
Version: 5.15.0

InsertData

public BackendReturnObject InsertData(string tableName);
public BackendReturnObject InsertData(string tableName, Param param);

Parameters

ValueTypeDescription
tableNamestringName of table where the game information will be stored
paramParamContent to be stored in the game information

Description

A row is added to the table.

  • The row is bound to the user who performed InsertData.

  • The data can be registered regardless of the schema definition status.

  • Both public and private data can be registered.

  • When registering schema, null or the default value is entered if the value is empty.

  • For numerical data, you can safely input numbers up to 9,007,199,254,740,991 (approximately 9 quadrillion).
    When your registered data exceeds the limit above, place values in units and tens are rounded down to 0.
    As the number increases and place values expand, small numbers are rounded down, and large numbers are maintained up to 16 - 18 digits, based on the left.

    For 'long', the data is saved as shown below:

    12345678912345678 -> 12345678912345678(within the limit of 9 quadrillion, the input number is maintained) 123456789123456789 -> 123456789123456780(exceeds the limit of 9 quadrillion, the last digit is rounded down) 1234567891234567891 -> 1234567891234568000 9223372036854775807 -> 9223372036854776000(the maximum value for 'long')

    When saving an integer with double to save a larger piece of data, the number is displayed as shown below:

    12345678912345678912 -> 12345678912345678000('double' is larger than the maximum value of 'long') 123456789123456789123.0 -> 123456789123456800000 1234567891234567891234.0 -> 123456789123456800000000 1.23456789123457E+29 -> 123456789123457000000000000000

    In the case of receiving the number from the client (C#), it may be changed to an exponent format.
    12345678912345678000 -> 1.23456789123457E+19

Reserved column

When saving, eight fields, including partition, gamer_id, inDate, updatedAt, sender, receiver, reservationDate, owner_inDate, client_date, are used by the server.
If this column is included in the param, the value in the param is ignored and the value used by the server is stored.

ValueDescriptionWhether the value is displayed in BACKND Console
partitionValue used by the server to classify a tableX
gamer_idGamer ID of the row ownerO
inDateinDate of the row (key value)O
updatedAtTime the table was last modifiedO
senderValue used internally for BACKND function (e.g., mail)X
receiverValue used internally for BACKND function (e.g., mail)X
reservationDateValue used internally for BACKND function (e.g., mail)X
owner_inDateUser inDate of the row ownerO
client_dateThe time when the client first requested data creationO

For schema tables

The following precautions apply when using schema tables:

  • Entering data that does not fit the data type will result in an error.
  • When the data type is set to 'string', '10' cannot be added as data.
  • When the data type is set to 'int', 'float', or 'double', '10' cannot be added as data.
  • When the data type is set to 'int', entering '3.14' as data will convert it to '3'. (Decimal point is discarded.)
  • When the data type is set to 'DateTime', you can only add data that matches that type. (If 'DateTime' is set to HH:mm:ss, the data can only be entered in the format of "15:21:31", and data cannot be added in the format of "2024-01-23T15:21:31.311Z" or "2024-01-23 15:21:31".
  • All data types cannot be registered/modified as null like param.Add("item", null). (The error 'bad {data} dataType, invalid dataType' will occur.)
  • If null is allowed and the data does not exist in the param during data insertion, the data is created without the column.
  • If null is not allowed and the data does not exist in the param, the default value is inserted automatically. However, in case of 'list' or 'map', the data must be included during the data insertion.
  • In the case of 'DateTime', if null is not allowed and the default value is ON, the current time is configured based on UTC. (If the time in Korea is 11:35, the time is set to 02:35.) If the default value is OFF and data is inserted without including the column, an error occurs.

Example

param

Param lunch = new Param();
lunch.Add("how much", 332);
lunch.Add("when", "yesterday");
lunch.Add("what", "eat chocolate");

Dictionary<string, int> dic = new Dictionary<string, int>
{
{ "dic1", 1 },
{ "dic4", 2 },
{ "dic2", 4 }
};

Dictionary<string, string> dic2 = new Dictionary<string, string>
{
{ "mm", "j" },
{ "nn", "n" },
{ "dd", "2" }
};

String[] list = { "a", "b" };
int[] list2 = { 400, 500, 600 };

Param param = new Param();
param.Add("name", "cheolsu");
param.Add("score", 99);
param.Add("lunch", lunch);
param.Add("dic_num", dic);
param.Add("dic_string", dic2);
param.Add("list_string", list);
param.Add("list_num", list2);

Synchronous

Backend.PlayerData.InsertData("tableName", param);

Asynchronous

Backend.PlayerData.InsertData("tableName", param, (callback) => {
// Post-process
});

SendQueue

SendQueue.Enqueue(Backend.PlayerData.InsertData, "tableName", param, (callback) => {
// Post-process
});

ReturnCase

Success cases

When the table registration is successful
statusCode : 200
message : Success
returnValue : {"inDate":"inDate of the registered table"}

e.g.) returnValue : {"ConsumedCapacity":{"Write":{"CapacityUnits":3}},"inDate":"2023-10-28T11:00:38.611Z"}

Error cases

(Schema) When the data type of the column declared upon defining the schema is different from the data type to undergo InsertData
statusCode : 400
errorCode : BadParameterException
message : bad {column name} dataType, Invalid {column name} dataType

(Schema) When InsertData is attempt on a column whose schema is not defined
statusCode : 400
errorCode : BadParameterException
message : bad column does not exist., The invalid column does not exist.

(Schema) When the size of the list set upon declaring the list column in the schema is larger than the size of the list entered in param
statusCode : 400
errorCode : BadParameterException
message : bad list data length, Invalid list data length

(Schema) When the size of the map selected upon declaring the map column in the schema is different from the size of the map entered in param
statusCode : 400
errorCode : BadParameterException
message : bad map data length, Invalid map data length

When the total number of columns to be registered exceeds 290
statusCode : 400
errorCode : ValidationException
message : Invalid UpdateExpression: Expression size has exceeded the maximum allowed size;

When the size of the data being registered exceeds 400 KB
statusCode : 400 errorCode : ValidationException message : Item size has exceeded the maximum allowed size

When the size of the data being registered exceeds 400 KB
statusCode : 400 errorCode : ValidationException message : Item size to update has exceeded the maximum allowed size

When InsertData is attempted on a non-existent table
statusCode : 404
errorCode : NotFoundException
message : {tableName} table not found, {tableName} table cannot be found.

When there is an attempt to register to a deactivated tableName
statusCode : 412
errorCode : PreconditionFailed
message : inactiveTable prerequisites are not met.

When the size of the data being registered exceeds 400 KB
statusCode : 413
errorCode : ServerErrorException
message : request entity too large

Sample Code

public class PlayerDataItem
{
public string nickName = Backend.UserNickName;
public string ownerIndate = Backend.UserInDate;
public string inDate;
public int hp;
public int mp;
public float atk;
public long money;
public Dictionary<string, string> equip = new Dictionary<string, string>();
public List<string> items = new List<string>();
public DateTime lastUpdate;

public PlayerDataItem()
{
}

public PlayerDataItem(LitJson.JsonData json)
{
hp = int.Parse(json["hp"].ToString());
mp = int.Parse(json["mp"].ToString());
atk = float.Parse(json["atk"].ToString());
money = long.Parse(json["money"].ToString());

foreach(var column in json["equip"].Keys)
{
equip.Add(column, json["equip"][column].ToString());
}

for(int i = 0; i < json["items"].Count; i++)
{
items.Add(json["items"][i].ToString());
}
inDate = json["inDate"].ToString();
lastUpdate = DateTime.Parse(json["lastUpdate"].ToString());
}

public Param ToParam()
{
Param param = new Param();

param.Add("nickName", nickName);
param.Add("hp", hp);
param.Add("mp", mp);
param.Add("atk", atk);
param.Add("money", money);
param.Add("equip", equip);
param.Add("items", items);
param.Add("lastUpdate", DateTime.UtcNow);

return param;
}
public override string ToString()
{
string equipString = "equip\n";
foreach(var dic in equip)
{
equipString += $"-{dic.Key} : {dic.Value}\n";
}

string itemString = "items : ";
for(int i = 0; i < items.Count; i++)
{
itemString += $"{items[i]}, ";
}

return $"hp : {hp}\n" +
$"mp : {mp}\n" +
$"atk : {atk}\n" +
$"money : {money}\n" +
$"lastUpdate : {lastUpdate}\n" +
equipString + "\n" + itemString + "\n";
}
}
public void InsertDataTest()
{
PlayerDataItem PlayerData = new PlayerDataItem();

PlayerData.hp = 1000;
PlayerData.mp = 0;
PlayerData.atk = 231.23f;
PlayerData.money = 100000000000;
PlayerData.equip = new Dictionary<string, string>() { { "head", "itemID231" }, { "arms", "itemID192" }, { "legs", "itemID001" }, { "body", "itemID337" } };
PlayerData.items = new List<string>() { "itemID231", "itemID341", "itemID12", "itemID124", "itemID331", "itemID228", "itemID775", "itemID479" };

Param param = PlayerData.ToParam();

var bro = Backend.PlayerData.InsertData("PlayerInfo", param);

if(bro.IsSuccess())
{
string playerInfoIndate = bro.GetInDate();
Debug.Log("My playerInfo indate : " + playerInfoIndate);
}
else
{
Debug.LogError("Game information registration failed : " + bro.ToString());
}
}