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
0
Question by sadowlight123 · Apr 24, 2017 at 02:48 PM · androidplugindatabasesqlite

SqlLite , android and unity

Hello guys I reached a solution after hours and hours of research for getting data from a database to unity .It works really good on windows but not on android (i have a Plugins folder under Assets folder kindly find the attached file to see how the different Plugins were placed into the project ) and then i used the following code to read from database: on windows , it reached step 12 but on android it stops on step 6 so I guess it is going through a infinite while loop but what could cause this? Thanks for the help guys!

public void OpenDBtwo ()

 {

     debuggingthis.text = "step1";
     Debug.Log("Call to open BD: GameDatabase.db"  );
     debuggingthis.text = "step2";
     // check if file exists in Application.DataPath
     string filepath = Application.dataPath + "/StreamingAssets/GameDatabase.db";
     debuggingthis.text = "step3";
     if (!File.Exists(filepath))
     {
         debuggingthis.text = "step14";
         Debug.LogWarning("Arquive \"" + filepath + "\" doenst exist. tring to create from \"" + filepath);
         // if it doesn't ->
         // open StreamingAssets directory and load the db -> 
         debuggingthis.text = "step5";
         WWW loadDB = new WWW("jar:file://" + filepath);
         debuggingthis.text = "step6";
         /*------reached this point on mobile-------*/
         while (!loadDB.isDone) { }
         // then save to Application.persistentDataPath
         File.WriteAllBytes(filepath, loadDB.bytes);
         debuggingthis.text = "step7";
     }

     debuggingthis.text = "step8";
     //open db connection
     connection = "URI=file:" + filepath;
     debuggingthis.text = "step9";
     Debug.Log("Stabilishing connection to: " + connection);
     debuggingthis.text = "step10";
     dbConnection = new SqliteConnection(connection);
     debuggingthis.text = "step11";
     dbConnection.Open();
     debuggingthis.text = "step12";
 }



alt text

alt text

1.png (106.5 kB)
2.png (57.4 kB)
Comment
Add comment · Show 3
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 sadowlight123 · Apr 22, 2017 at 07:33 AM 0
Share

my guess was right ... i just tested it and it is an infinite while loop for I don't know what reason... please can anyone help me fix this and understand whats going on ?

avatar image GilbertoBitt · Apr 24, 2017 at 03:33 PM 0
Share

$$anonymous$$e i made a different approach and work fine on editor, windows and android!

 public DataService(string DatabaseName){
         // check if file exists in Application.persistentDataPath
         var filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);
         if (System.IO.File.Exists(filepath)){        
             _connection = new SQLiteConnection(filepath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
             //Debug.Log("<color=#ffffff>Final PATH:</color> <color=#33bfea>" + filepath + "</color>"); 
         } else {
             #if UNITY_ANDROID 
             var loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName);  // this is the path to your Strea$$anonymous$$gAssets in android
             while (!loadDb.isDone) { }  // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
             // then save to Application.persistentDataPath
             File.WriteAllBytes(filepath, loadDb.bytes);
             #endif
             #if UNITY_EDITOR || UNITY_EDITOR_64 || UNITY_EDITOR_WIN
             var _loaddb = string.Format(@"Assets/Strea$$anonymous$$gAssets/{0}", DatabaseName);
             var filepathTo = string.Format("{0}/{1}", Application.persistentDataPath,DatabaseName);
             File.Copy(_loaddb,filepathTo,true);
             #endif
             _connection = new SQLiteConnection(filepath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
             //Debug.Log("<color=#ffffff>Final PATH:</color> <color=#33bfea>" + filepath + "</color>"); 
         }       
 
     }
avatar image GilbertoBitt · Apr 24, 2017 at 03:34 PM 0
Share

Here it's for android!

 var loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName);  // this is the path to your Strea$$anonymous$$gAssets in android
                 while (!loadDb.isDone) { }  // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
                 // then save to Application.persistentDataPath
                 File.WriteAllBytes(filepath, loadDb.bytes);
     
     _connection = new SQLiteConnection(filepath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GilbertoBitt · Apr 24, 2017 at 03:44 PM

 public DataService(string DatabaseName){
          // check if file exists in Application.persistentDataPath
          var filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);
          if (System.IO.File.Exists(filepath)){        
              _connection = new SQLiteConnection(filepath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
              //Debug.Log("<color=#ffffff>Final PATH:</color> <color=#33bfea>" + filepath + "</color>"); 
          } else {
              #if UNITY_ANDROID 
              var loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName);  // this is the path to your StreamingAssets in android
              while (!loadDb.isDone) { }  // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
              // then save to Application.persistentDataPath
              File.WriteAllBytes(filepath, loadDb.bytes);
              #endif
              #if UNITY_EDITOR || UNITY_EDITOR_64 || UNITY_EDITOR_WIN
              var _loaddb = string.Format(@"Assets/StreamingAssets/{0}", DatabaseName);
              var filepathTo = string.Format("{0}/{1}", Application.persistentDataPath,DatabaseName);
              File.Copy(_loaddb,filepathTo,true);
              #endif
              _connection = new SQLiteConnection(filepath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
              //Debug.Log("<color=#ffffff>Final PATH:</color> <color=#33bfea>" + filepath + "</color>"); 
          }       
  
      }

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 sadowlight123 · Apr 24, 2017 at 08:47 PM 1
Share

thanks really much

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sqlite4Unity3d difficulties 1 Answer

problem retrieving data from SQLite to Android 2 Answers

SQLite Database for Android Unity Error 1 Answer

Storing Constant data in a mobile game 0 Answers

SQLite works fine in Unity Editor but doesn't work in Android device (apk). 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