3
I’m using the Sqlite as a game database made in Unity that works perfectly on Unity Editor, but when I build for Android the game simply does not access the bank (nothing is informed or released).
What I can do to make the sqlite database accessible through Android as well as Unity Editor?
Programs/Versions used:
- Unity 5.3.1f1
-Sqlite Precompiled Binaries for Windows 64 (sqlite-dll-Win64-x64-3100200.zip (688.01 Kib))
Folder Structure:
-- Assets/Database/MyDataBase.db
-- Assets/Scripts/PerguntaScript.cs
-- Assets/Plugins/Mono.Data.Sqlite.dll
-- Assets/Plugins/sqlite3.def
-- Assets/Plugins/sqlite3.dll
-- Assets/Plugins/System.Data.dll
Questionascript.Cs (Script accessing Sqlite database)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Data;
using Mono.Data.Sqlite;
public class PerguntaScript : MonoBehaviour {
private string connectionString;
void Start () {
connectionString = "URI=file:" + Application.dataPath + "/Database/DoencasDB.db";
}
private void GetPergunta(){
using(IDbConnection dbConnection = new SqliteConnection(connectionString)){
dbConnection.Open();
using(IDbCommand dbCommand = dbConnection.CreateCommand()){
string sqlQuery = "SELECT * FROM " + sqliteTabelasPerguntas[sqliteIndexTabelaPergunta] + " WHERE doenca_id=@id LIMIT 1";
dbCommand.Parameters.Add(new SqliteParameter("@id", doencaId));
dbCommand.CommandText = sqlQuery;
using(IDataReader reader = dbCommand.ExecuteReader()){
while(reader.Read()){
pergunta = reader.GetString(1);
alternativasId[0] = reader.GetInt32(3);
alternativasId[1] = reader.GetInt32(4);
alternativasId[2] = reader.GetInt32(5);
alternativasId[3] = reader.GetInt32(6);
alternativaCorretaId = reader.GetInt32(7);
}
dbConnection.Close();
reader.Close();
}
}
}
}
OBS: Tested on Android: 4.4 and 5.0
Even added this file
.so
didn’t work.– Ricardo