Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by bluediamondgaming · Apr 27, 2012 at 05:59 PM · c#androidsqlite

Sqlite database and Android

I'm using Unity3D (for the first time) to create an Android app (for the first time) so I don't know much about either lol. I'm programming in C#.

I have a sqlite database which, from my understanding, should work natively on Android. From my research, I need to copy it from a folder in Unity called "Assets/StreamingAssets" over to Application.persistentDataPath on the device.

So this should work:

 WWW loadDB = new WWW ("jar:file://" + Application.dataPath + "!/assets/" + FILE_NAME);
 while (!loadDB.isDone) {} 
 File.WriteAllBytes (Application.persistentDataPath + "/" + FILE_NAME, loadDB.bytes);

And then just open the SQLiteConnection and read the results (which works in Unity on my computer, but does not work on the Android device).

Does anyone have any working code snippets or know why this isn't working for me? Thanks :)

Comment
Add comment · Show 4
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 oktemre · Mar 17, 2016 at 03:11 PM 0
Share

Did you find a solution for this?

avatar image bighoz · Oct 17, 2016 at 09:28 AM 0
Share

$$anonymous$$E TOo.. i have spend a week for this issue.... im tired!!! pls somebody help us....

avatar image Bonfire-Boy · Oct 17, 2016 at 10:56 AM 0
Share

I copy sqlite DBs from strea$$anonymous$$g assets to persistent data using code that looks similar to yours (except I generally do it in a coroutine, using yield return loadDB; ins$$anonymous$$d of your while loop). Unless I'm missing something, your code looks sound enough to me (for Android).

So please provide more information. "It does not work" is rarely helpful!

In particular, does it fail to load the file, or does it load the file but fail to write it? (you could e.g check the value of loadDB.errorand the size of loadDB.bytes before your Write call)

Or... is the problem somewhere else? You've shown us only the code for copying the file. From your vague description of the problem, it could be that the file actually being copied fine and you're doing something wrong when trying to connect to the DB. You can use adb to inspect the filesystem on the android device and copy the DB file back to your computer to check it.

If you find that the file is being copied correctly, I would suggest that you edit your question, adding the code you're using to connect to the DB.

And note that that code is Android-specific. So I don't think you're correct to say that it "works in Unity on my computer".

To simplify coding I generally use this for the strea$$anonymous$$gAssetsPath

 public static string strea$$anonymous$$gAssetsPath
 {
     get
     {
         if (Application.platform == RuntimePlatform.Android)
             return "jar:file://" + Application.dataPath + "!/assets/";
         else
             return "file://" + Application.strea$$anonymous$$gAssetsPath +"/";
     }
 }

With that, I can use this for your first line to make it work for any platform...

 WWW loadDB = new WWW (strea$$anonymous$$gAssetsPath + FILE_NA$$anonymous$$E);

Finally, any errors or warnings in the log on your Android device? (again, you can use adb, to look at the logcat)

avatar image leebrond Bonfire-Boy · May 27, 2017 at 06:40 AM 0
Share

hello @Bonfire-Boy ! Can you describe more about how to use SQLite on Unity and apply it on Android device? Please. Thanks

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Hizak · Feb 02, 2018 at 07:38 PM

i have the same prbloem just right now, everytingh works well on pc but android dont do the querys

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 Bonfire-Boy · Feb 02, 2018 at 08:02 PM 0
Share

When you say it doesn't do the queries, are you saying that it does connect to the database?

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

8 People are following this question.

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

Related Questions

Unity 2019 sqlite3 connection android 0 Answers

Multiple Cars not working 1 Answer

Unity 4 Android Game cannot access SQLite DB (C# Script) 1 Answer

Distribute terrain in zones 3 Answers

Sqlite RANDOM() function not working on Android? 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