Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by mathieu93 · Aug 17, 2016 at 09:00 AM · buttondatabasedatabase handling

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mathieu93 · Aug 24, 2016 at 03:10 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges