Database for KPI dashboard in Unity
I'm currently working on building 3D KPI dashboards in Unity to work with Microsoft Hololens. However, I can't seem to find any proper docmentation about the best-to-use database type for this application. All database-related questions are about score-keeping. I'm currently thinking about using SQLite, as described here: https://goo.gl/p08WvQ . As I'm not that experienced in databases at the moment, I think using SQLite means that I will first have to convert all database files I import to SQLite format. Is this true?
What type of database would you recommend using for this type of application?
Answer by Kachimareck · Oct 23, 2017 at 08:01 PM
Hello! this code works in android? I am with very difficult to make a database in unity works in mobile devices. Thank you. Please, if you know something this will be a big help.
Answer by mathieu93 · Aug 23, 2016 at 12:32 PM
Update:
I'm currently using a SQLite database, and it works fine while within Unity with the method discribed in the link above. For UWP, iOS and Android however, support for SQLite has to be built in differently. I will update my question if I find out more. Currently, my code for opening and closing the database reader is as follows:
// Initiate database for using
string connectionString = "URI=file:" + Application.dataPath + "/WorldPopulation.db";
IDbConnection dbcon;
dbcon = (IDbConnection)new SqliteConnection(connectionString);
// Open connection to the database
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = "SELECT Region, Value, Unit FROM Population WHERE Year == 2014 ";
// Executing database reader
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
string region = reader.GetString(0);
rawValue = (float)reader.GetInt32(1);
unitValue = (float)reader.GetInt16(2);
for (int i = 0; i < regions.Length; i++)
{
if (regions[i] == region)
{
regionId = i;
}
}
populationVal[regionId] += rawValue * unitValue;
}
for (int i = 0; i < regions.Length; i++)
{
totalPop += populationVal [i];
}
for (int i = 0; i < regions.Length; i++)
{
//Debug.Log (populationVal[i]);
populationPerc[i] = 50 * (populationVal[i] / totalPop);
Debug.Log(populationVal[i] + " " + i);
}
// clean up
reader.Close();
dbcmd.Dispose();
dbcon.Close();
Got everything in working order atm with use of an PCL from Github, which can be found here
Adjusted the code a bit because I won't need to create or edit any tables, only read them. Unfortunately, I haven't found any better way to return all values returned from the SQL query. I currently just put them all in one string in the Person.cs script and then cut them again in the ExistingDBScripts.cs script. $$anonymous$$y code is as follows:
ExistingDBScript.sc
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
public class ExistingDBScript : $$anonymous$$onoBehaviour {
public Text DebugText;
float totalAge;
// Use this for initialization
void Start () {
var ds = new DataService ("existing.db");
var people = ds.GetPersons ();
ToConsole (people);
}
private void ToConsole(IEnumerable<Person> people)
{
foreach (var $$anonymous$$ees in people)
{
string[] split = $$anonymous$$ees.ToString().Split(' ');
totalAge += Convert.ToSingle(split[3]);
ToConsole($$anonymous$$ees.ToString());
}
Debug.Log(totalAge);
}
private void ToConsole(string msg)
{
DebugText.text += System.Environment.NewLine + msg;
Debug.Log (msg);
}
}
DataService.cs (after last #endif statement)
_connection = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
Debug.Log("Final PATH: " + dbPath);
}
public IEnumerable<Person> GetPersons() {
return _connection.Query<Person> ("SELECT * FRO$$anonymous$$ Person WHERE Age < 35");// AND Name == 'John' ");
}
public IEnumerable<Person> GetPersonsNamedRoberto(){
return _connection.Table<Person>().Where(x => x.Name == "*");
}
Person.cs
public class Person {
[Primary$$anonymous$$ey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public int Age { get; set; }
public override string ToString()
{
string strings = (Id + " " + Name + " " + Surname + " " + Age);
return strings;
}
}
Does anyone have any idea on how to handle the return values in a better way? I think this is one of the worst to do it, but it is working fortunately.
Thanks in advance!
Your answer

Follow this Question
Related Questions
Best DataBase for mobile games 2 Answers
Error Inserting Record - SQLite Database 0 Answers
How to return a value from a anonymous function?, 2 Answers
Best BaaS for storing IAP information 0 Answers
Database for 3D KPI dashboards in Unity 0 Answers