robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d
MIT License
1.28k stars 265 forks source link

[Android] How to update new sqlite in StreamingAssets folder ? #37

Open ttpro1995 opened 8 years ago

ttpro1995 commented 8 years ago

I going to ship my product with pre-defined database in Assets/StreamingAssets. However, when I update application with new database (install the update from App store, but not delete and reinstall), the pre-defined sqlite is not update. (it still use old database). How can I get my data updated? (without delete and reinstall app on phone)

Thank you

sandolkakos commented 8 years ago

I think you can keep your sqlite db in the Resources folder and when you open the App for the first time, you will copy it to Application.persistentDataPath.

Something like that:

TextAsset sqdbTextAsset = Resources.Load("sqlite_folder_name/your_database.sqdb") as TextAsset; File.WriteAllBytes(Application.persistentDataPath + "/your_database.sqdb", sqdbTextAsset.bytes);

PS.: the file need to be named with .txt extension, in order to be loaded as TextAsset: your_database.sqdb.txt