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 /
avatar image
1
Question by vonnbla123 · Aug 28, 2015 at 12:06 PM · databasesqlite

Database not loaded on Device, but works on Unity Game Scene

Good day I am having a problem accessing my database on my mobile android device. It seems that it doesn't read my database or I don't know my database is not included upon build. But here is the catch, my database works fine in unity editor. I can't seem to find the problem on my mobile device because I don't have access on it's console. BTW here is my code:

Reading database:

 void readDatabase(){
 
      string conn = "URI=file:" + Application.dataPath + "/Database/AtlasDB.sqlite";
 
     string sqlQuery = "SELECT * FROM UserScore";
 
     using (SqliteConnection c = new SqliteConnection(conn))
         {
             c.Open();
             using (SqliteCommand cmd = new SqliteCommand(sqlQuery, c))
             {
                 using (SqliteDataReader rdr = cmd.ExecuteReader())
                 {
                     while (rdr.Read())
                         {
                         currHighScore = rdr.GetInt32(0);
                             //            string name = reader.GetString(1);
                         currHighDist = rdr.GetInt32(1);
                                     
                             Debug.Log( "High Score : " + currHighScore + ", High Distance: " + currHighDist);
                         }
                 }
             }
         }
 
 }


Updating database:

 void highscoreChecker(){
 
 string conn2 = "URI=file:" + Application.dataPath + "/Database/AtlasDB";
         string  sqlQuery2 = "UPDATE UserScore SET Highscore = '" + MoveSanji.scoreAccumulate + "'";
 
 using (SqliteConnection c = new SqliteConnection(conn2))
         {
             c.Open();
             using (SqliteCommand cmd = new SqliteCommand(sqlQuery2, c))
             {
                 if (MoveSanji.scoreAccumulate > currHighScore) {
 
                     cmd.ExecuteReader();
                 }
             }
         }
 
 string  sqlQuery3 = "UPDATE UserScore SET HighDistance = '" + Mathf.RoundToInt( MoveSanji.distanceRun )+ "'";
 
         using (SqliteConnection c = new SqliteConnection(conn2))
         {
             c.Open();
             using (SqliteCommand cmd = new SqliteCommand(sqlQuery3, c))
             {
                 if (Mathf.RoundToInt( MoveSanji.distanceRun) > currHighDist) {
                     
                     cmd.ExecuteReader();
                 }
             }
         }
 
     }


Im using sqlite

Note: I made my database using SQLite Database Browser 2.0 b1 -- Database is located on my Database Folder in Assets Folder -- I have Mono.Data, Mono.Data.Sqlite, sqlite3.dll, sqlite3.def, System.Data.dll on my plugins folder

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hameed-ullah-jan · Jan 29, 2018 at 07:23 AM

Hi, Problem solved, please download this plugin: https://github.com/codecoding/SQLite4Unity3d

Comment
Add comment · Show 2 · 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 palalopea · Jan 31, 2018 at 08:55 PM 0
Share

how about if u build in standalone/pc? is it works?

avatar image hameed-ullah-jan palalopea · Jul 04, 2018 at 07:29 AM 0
Share

I didn't check it on the standalone build, but works fine in the editor, ios device, Android device

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

SQLite Except: The database file is locked 1 Answer

Database (SQLite) Setup for Unity 0 Answers

SQLite Transaction Update Problem on Android 0 Answers

SQLite: updating integer with the value 1 to integer = integer + 1 results in 3 instead of 2 1 Answer

Sq lite Date base in unity 3d? 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