Hi,
my Unity project for Android and iOS uses a SQLite DB; on Android all is ok but on iOS I've a read-only exception when I run the app via Xcode:
Mono.Data.Sqlite.SqliteException: Attempt to write a read-only database
I use this code to write in the DB:
public static bool InsertInto(string tableName, String Column, String Value) {
string query = "INSERT INTO " + tableName + " (" + Column +") VALUES (" + Value + ")";
try {
dbcmd = dbcon.CreateCommand();
dbcmd.Prepare();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader();
}
catch (Exception exception) {
Debug.LogError (exception);
return false;
}
return true;
}
To open the DB:
public static void OpenDB(string p) {
string filepath = "";
#if UNITY_EDITOR
filepath = string.Format(@"Assets/StreamingAssets/{0}", p);
#elif UNITY_ANDROID
filepath = Application.persistentDataPath + "/" + p;
if(!File.Exists(filepath)) {
Debug.LogWarning("File \"" + filepath + "\" does not exist. Attempting to create from \"" + Application.dataPath + "!/assets/" + p);
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + p);
while(!loadDB.isDone) {}
File.WriteAllBytes(filepath, loadDB.bytes);
}
#elif UNITY_IOS
filepath = Path.Combine(UnityEngine.Application.streamingAssetsPath, p);
#endif
connection = "URI=file:" + filepath;
try {
dbcon = new SqliteConnection(connection);
dbcon.Open();
} catch (Exception exception) {
GUITxt = exception.Message + "\n" + exception.StackTrace;
Debug.LogError(exception.Message + "\n" + exception.StackTrace);
}
}
Some idea?
Thank you!
↧