CreateData
public BackndReturnObject CreateData(string tableName);
public BackndReturnObject CreateData(string tableName, Param param);
Parameters
Value | Type | Description |
---|---|---|
tableName | string | Name of table where the game information will be stored |
param | Param | Content to be stored in the game information |
Description
A row is added to the table.
The row is bound to the user who CreateData-ed that row.
The data can be inserted regardless of the schema definition status.
Both public and private data can be inserted.
When inserting 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 input 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(the 'double' larger than the maximum value of 'long')
123456789123456789123.0 -> 123456789123456800000
1234567891234567891234.0 -> 123456789123456800000000
1.23456789123457E+29 -> 123456789123457000000000000000In 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, and owner_inDate, 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.
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 |
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 added/modified as null like param.Add("item", null). (The error 'bad {data} dataType, invalid {data} 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
Backnd.PlayerTable.CreateData("tableName", param);
Asynchronous
Backnd.PlayerTable.CreateData("tableName", param, (callback) =>
{
// Post-process
});
Return cases
Success cases
When the table is inserted successfully
statusCode : 200
returnValue : {"inDate":"inDate of the inserted table"}
e.g.) returnValue : {"inDate":"2020-06-10T09 : 26 : 21.738Z"}
Error cases
(Schema) When the data type of the column declared upon defining the schema is different from that of the column to be CreateData-ed and updated
statusCode : 400
errorCode : BadParameterException
(Schema) When there is an attempt to CreateData a column whose schema is not defined
statusCode : 400
errorCode : BadParameterException
(Schema) When the size of the list selected upon declaring the list column in the schema is different from the size of the list entered in param
statusCode : 400
errorCode : BadParameterException
(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
When the total number of columns to be inserted exceeds 290
statusCode : 400
errorCode : ValidationException
When an attempt is made to insert into a non-existent table
statusCode : 404
errorCode : NotFoundException
When there is an attempt to insert into a deactivated tableName
statusCode : 412
errorCode : PreconditionFailed
When the size of the data to be inserted exceeds 400 KB
statusCode : 413
errorCode : ServerErrorException
Sample code
public class PlayerTableItem
{
public string nickName = Backnd.UserNickName;
public string ownerIndate = Backnd.PlayerInDate;
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 PlayerTableItem()
{
}
public PlayerTableItem(BACKND.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 CreateDataTest()
{
PlayerTableItem PlayerTable = new PlayerTableItem();
PlayerTable.hp = 1000;
PlayerTable.mp = 0;
PlayerTable.atk = 231.23f;
PlayerTable.money = 100000000000;
PlayerTable.equip = new Dictionary<string, string>() { { "head", "itemID231" }, { "arms", "itemID192" }, { "legs", "itemID001" }, { "body", "itemID337" } };
PlayerTable.items = new List<string>() { "itemID231", "itemID341", "itemID12", "itemID124", "itemID331", "itemID228", "itemID775", "itemID479" };
Param param = PlayerTable.ToParam();
var bro = Backnd.PlayerTable.CreateData("PlayerInfo", param);
if(bro.IsSuccess())
{
string playerInfoIndate = bro.GetInDate();
Debug.Log("My playerInfo's indate : " + playerInfoIndate);
}
else
{
Debug.LogError("Failed to CreateData game information : " + bro.ToString());
}
}