- Home /
Question by
aureegpn · Aug 23, 2020 at 04:59 PM ·
androidunityeditordatabasesqlite
Unity sqlite to android: no such table
i am trying to use a database on a unity game for android it works on unity but it does not find tables on android device,i dont know what cant it be i have tried so many things ( i am following this tutorial https://github.com/robertohuertasm/SQLite4Unity3d ) i have alredy tried this https://answers.unity.com/questions/513862/sqlite-no-such-table.html and this https://stackoverflow.com/questions/8482419/c-sharp-and-sqlite-no-such-table-error-when-using-relative-path but still have same error
This is the error i am getting on Android device Monitor:
this is the database : and this is the code:
using SQLite4Unity3d;
using UnityEngine;
#if !UNITY_EDITOR
using System.Collections;
using System.IO;
#endif
using System.Collections.Generic;
public class DataService {
private SQLiteConnection _connection;
string DatabaseName="BaseDeDatos.db";
public DataService(){
#if UNITY_EDITOR
var dbPath = string.Format(@"Assets/StreamingAssets/{0}", DatabaseName);
#else
// check if file exists in Application.persistentDataPath
var filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);
if (!File.Exists(filepath))
{
Debug.Log("Database not in Persistent path");
// if it doesn't ->
// open StreamingAssets directory and load the db ->
#if UNITY_ANDROID
var loadDb = new WWW("jar:file://" + Application.dataPath + "!/assets/" + DatabaseName); // this is the path to your StreamingAssets in android
while (!loadDb.isDone) {
Debug.Log("aaaaaaaaaaaaa");
} // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
// then save to Application.persistentDataPath
File.WriteAllBytes(filepath, loadDb.bytes);
#endif
Debug.Log("Database written");
}
var dbPath = filepath;
#endif
_connection = new SQLiteConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
Debug.Log("Final PATH: " + dbPath);
}
public int GetPlayerDBCheckPoints(){
Debug.Log("me quiero morir");
return _connection.Table<playerDB>().Where(x => x.Id == 1).FirstOrDefault().checkpoints;
}
}
capturadb.png
(10.1 kB)
capturaerror.png
(47.3 kB)
Comment