• 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 /
avatar image
0
Question by EvelynSays · 3 days ago · unity 2dsqlite

How do I get SQLite databases working in my build when they already work in my project?

Today I was supposed to begin testing my build, but I've found that I've done something wrong with SQLite integration and I'm not sure what that is.

Everything works in the unity editor, but I think I've missed a step to allow the databases to be created properly in the build folder. The core game systems rely on the databases working correctly, and they are not.


There is a lot of code in my project, so I'm not sure what to share, so here is my Database Manager script, and a screenshot of my project setup.


I think there is something wrong with the location of the databases or how they are being handled in the build, but I have no idea how to fix this type of issue.


Thanks in advance for any help. I am happy to provide any additional information you may need.

alt text

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Mono.Data.Sqlite;
 using System;
 using System.Data;
 
 public class DBManager : MonoBehaviour
 {
     
     private string quotesDB = "URI=file:Quotes.db";
     private string musicDB = "URI=file:Music.db";
 
     public List<Quote> level1Quotes = new();
     public List<Quote> level2Quotes = new();
     public List<Quote> level3Quotes = new();
     public List<Quote> level4Quotes = new();
     public List<Quote> pythonQuotes = new();
     public List<Quote> playQuotes = new();
 
     public List<Track> trackList = new();
     //public List<Track> lofiTracks = new();
     //public List<Track> jazzTracks = new();
     //public List<Track> classicalTracks = new();
 
     PlayerInfo playerInfo;
     public int quoteCount;
 
     void Awake()
     {
         playerInfo = GameObject.Find("PlayerInfo").GetComponent<PlayerInfo>();
     }
 
     private void Start()
     {
         MakeTrackList();
         MakeQuoteList();
         MakePlayQuotes();
     }
 
     public void MakePlayQuotes()
     {
         playQuotes.Clear();
         if (playerInfo.difficultyList[0])
         {
             //Debug.Log("Level 1 Enabled");
             foreach (Quote quote in level1Quotes)
             {
                 playQuotes.Add(quote);
             }
         }
         if (playerInfo.difficultyList[1])
         {
             //Debug.Log("Level 2 Enabled");
             foreach (Quote quote in level2Quotes)
             {
                 playQuotes.Add(quote);
             }
         }
         if (playerInfo.difficultyList[2])
         {
             //Debug.Log("Level 3 Enabled");
             foreach (Quote quote in level3Quotes)
             {
                 playQuotes.Add(quote);
             }
         }
         if (playerInfo.difficultyList[3])
         {
             //Debug.Log("Level 4 Enabled");
             foreach (Quote quote in level4Quotes)
             {
                 playQuotes.Add(quote);
             }
         }
         if (playerInfo.python)
         {
             //Debug.Log("Level 4 Enabled");
             foreach (Quote quote in pythonQuotes)
             {
                 playQuotes.Add(quote);
             }
         }
 
         // shuffle
         for (int i = 0; i < playQuotes.Count; i++)
         {
             Quote tempQuote = playQuotes[i];
             int randomIndex = UnityEngine.Random.Range(i, playQuotes.Count);
             playQuotes[i] = playQuotes[randomIndex];
             playQuotes[randomIndex] = tempQuote;
         }
     }
 
     private void MakeQuoteList()
     {
         using (var connection = new SqliteConnection(quotesDB))
         {
             connection.Open();
 
             // set up an object called command for db control
             using (var command = connection.CreateCommand())
             {
                 // adding all query responses to this list
                 command.CommandText = "SELECT * FROM quotes;";
                 using (IDataReader reader = command.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         Quote tempQuote = new Quote(Convert.ToString(reader["code"]), Convert.ToString(reader["text"]), Convert.ToString(reader["author"]), Convert.ToString(reader["category"]), Convert.ToInt32(reader["length"]), Convert.ToDouble(reader["difficulty"]));
 
                         //Debug.Log("Adding quote " + tempQuote.code + ", by " + tempQuote.author + ". Difficulty: " + tempQuote.difficulty);
                         if (tempQuote.difficulty < 2)
                         {
                             level1Quotes.Add(tempQuote);
                             //Debug.Log("Adding " + tempQuote.code + " to Level 1");
                         }
                         else if (tempQuote.difficulty < 3)
                         {
                             level2Quotes.Add(tempQuote);
                             //Debug.Log("Adding " + tempQuote.code + " to Level 2");
                         }
                         else if (tempQuote.difficulty < 4)
                         {
                             level3Quotes.Add(tempQuote);
                             //Debug.Log("Adding " + tempQuote.code + " to Level 3");
                         }
                         else if (tempQuote.difficulty >= 4 && tempQuote.difficulty < 10)
                         {
                             level4Quotes.Add(tempQuote);
                             //Debug.Log("Adding " + tempQuote.code + " to Level 4");
                         }
                         else if (tempQuote.difficulty == 10.0)
                         {
                             pythonQuotes.Add(tempQuote);
                             //Debug.Log("Adding " + tempQuote.code + " to python");
                         }
 
                     }
                     reader.Close();
                 }
 
             }
             connection.Close();
         }
 
     }
 
     private void MakeTrackList()
     {
         
         using (var connection = new SqliteConnection(musicDB))
         {
             connection.Open();
 
             // set up an object called command for db control
             using (var command = connection.CreateCommand())
             {
                 // adding all query responses to this list
                 command.CommandText = "SELECT * FROM music;";
                 using (IDataReader reader = command.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         Track tempTrack = new Track(Convert.ToString(reader["code"]), Convert.ToString(reader["title"]), Convert.ToString(reader["artist"]), Convert.ToString(reader["playlist"]));
 
                         //Debug.Log("Adding track " + tempTrack.title + ", by " + tempTrack.artist);
                         if (tempTrack.playlist == "lofi")
                         {
                             trackList.Add(tempTrack);
                             //Debug.Log("Adding " + tempTrack.code + " to lofi");
                         }
                         else if (tempTrack.playlist == "jazz")
                         {
                             trackList.Add(tempTrack);
                             //Debug.Log("Adding " + tempTrack.code + " to jazz");
                         }
                         else if (tempTrack.playlist == "classical")
                         {
                             trackList.Add(tempTrack);
                             //Debug.Log("Adding " + tempTrack.code + " to classical");
                         }
 
                     }
                     reader.Close();
                 }
 
             }
             connection.Close();
         }
 
     }
 
     private void ReadNumOfQuotes()
     {
         string stmt = "SELECT COUNT(*) FROM quotes;";
         int count = 0;
         
         // Create the connection
         using (var connection = new SqliteConnection(quotesDB))
         {
             
             using(SqliteCommand quoteCount = new SqliteCommand(stmt, connection))
             {
                 connection.Open();
                 count = Convert.ToInt32(quoteCount.ExecuteScalar());
             }
         }
         quoteCount = count;
     }
 }
 


screenshot-2022-06-03-201118.png (36.8 kB)
screenshot-2022-06-03-201355.png (37.7 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

151 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

smooth rotation 0 Answers

How to get Buildbox Set Up in Unity 2D 0 Answers

Unity2d Walking off platform throws off gravity 0 Answers

I want to learn C-Sharp programming language and I want to learn how to use the Unite game engine 1 Answer

Parent/Child rotation not working 1 Answer


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