iOS can't connect to SQLite DB
Hi everybody. I've a little problem. I have decided to use SQLite to save my application's data. I set up the following code to Write and delete datas by ID. (I don't need to read data, only to write and delete) When I run the application in Unity3D it works. When I build the application on my iPad or on my iPhone it doesn't work. It seeme like if it can't manage to find the database in folders.
PS: I followed this tutorial to write the code and then I modified the connection string in start becouse the tutorial was made for Windows. https://www.youtube.com/watch?v=laspFwXGprg&t=101s
Some Suggestions? Thanks a lot :)
void Start() {
//connectionString = System.IO.Path.Combine (Application.streamingAssetsPath,"MaintenanceDB.sqlite");
connectionString = "URI=file:" + Application.dataPath + "/Raw/MaintenanceDB.sqlite";
}
region SQLite Manager
private string connectionString;
public void Delete(){
DeleteData (GetInstanceID());
}
private void InsertData(int ID, string CurrentDate, string Deadline, int Counter){
using (IDbConnection dbConnection = new SqliteConnection (connectionString)) {
dbConnection.Open ();
using (IDbCommand dbCmd = dbConnection.CreateCommand ()) {
string sqlQuery = String.Format ("INSERT INTO Maintenance (ID,CurrentDate,Deadline,Counter) VALUES(\"{0}\",\"{1}\",\"{2}\",\"{3}\")", ID, CurrentDate, Deadline, Counter);
dbCmd.CommandText = sqlQuery;
dbCmd.ExecuteScalar ();
dbConnection.Close ();
}
}
}
private void DeleteData(int ID){
using (IDbConnection dbConnection = new SqliteConnection (connectionString)) {
dbConnection.Open ();
using (IDbCommand dbCmd = dbConnection.CreateCommand ()) {
string sqlQuery = String.Format ("DELETE FROM Maintenance WHERE ID =\"{0}\"",ID);
dbCmd.CommandText = sqlQuery;
dbCmd.ExecuteScalar ();
dbConnection.Close ();
}
}
}
#endregion
Answer by raffaelebasile · May 27, 2018 at 02:37 PM
I think that the problem could be that "Raw" folder is readable only. Does exist a way to move the DB into a writable folder? If yes,How can I do?
Hello @raffaelebasile .. Did you find a solution to the problem? I am now facing the same problem