Menu

A problem in IBoxDB

Vladislav
2015-07-13
2019-11-06
  • Vladislav

    Vladislav - 2015-07-13

    Hello everyone, i'm new to Unity as well as to IBoxDB, i would like to know why am i getting an error when i try to create a table in the IBoxDB.

    This is the code i; trying to use:

    using UnityEngine;
    using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.UI;

    // [iBoxDB.net2.dll]
    using iBoxDB.LocalServer;

    public class IBoxTest : MonoBehaviour
    {

    public DB server = null;
    public DB.AutoBox db = null;
    
    public class Player
    {
        public string playerName;
        public long playerExp;
        public List<String> playerCards;
    }
    
    public class Cart
    {
        public string cardName;
    
        public string cardDescription;
    
        public Image cardFace;
    }
    
    // Use this for initialization
    void Start ()
    {
        if(db == null)
        {
            DB.Root(Application.persistentDataPath);
    
            server = new DB();
    
            server.GetConfig().EnsureTable<Player>("Players","Name","Experience","CardZ");
    
            db = server.Open();
        }
    
        for (int i = 0; i < 5 ;i++)
        {
            var pl= new Player{
                playerName ="Vlad_"+i,
                playerExp = i,
                playerCards = new List<string>()
            };
    
            db.Insert ("Players",pl);
        }
    
    }//Start Ends
    private string _context;
    
    void DrawToString ()
    {
        _context = "";
        //SQL-like Query
        _context += "Players \r\n";
        foreach (Player player in db.Select<Player>("from Players", 0)) {
            _context += player.playerName + " Experience:" + player.playerExp + "\r\n";
        }
    }
    

    }

    The Error i'm getting is:

    ArgumentNullException: Argument cannot be null.
    Parameter name: key
    System.Collections.Generic.Dictionary`2[System.Type,iBoxDB.ByteCodes.Class193].TryGetValue (System.Type key, iBoxDB.ByteCodes.Class193& value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588)
    iBoxDB.ByteCodes.Class188.smethod_12 (System.Type type_0)
    iBoxDB.ByteCodes.Class148.smethod_2[Player] (System.String[] string_3)
    iBoxDB.ByteCodes.Class148.smethod_0[Player] (System.String string_3, System.String[] string_4)
    iBoxDB.LocalServer.DatabaseConfig.EnsureTable[Player] (System.String tableName, System.String[] names)
    iBoxDB.LocalServer.DatabaseConfig+Config.EnsureTable[Player] (System.String tableName, System.String[] names)
    IBoxTest.Start () (at Assets/Scripts/IBoxTest.cs:46)

    any help would be appreciated.

     
  • iBoxDB

    iBoxDB - 2019-11-06
    public class Player
    {
        public string playerName;
        public long playerExp;
    }
     GetConfig().EnsureTable<Player>("Players","Name","Experience","CardZ");
    

    "Name", "Experience", "CardZ" are not the Fields of Class Player.
    Use Field-Name or Property-Name as Key

    .EnsureTable<Player>("Player", "playerName");
    
     

    Last edit: iBoxDB 2019-11-06

Log in to post a comment.