using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite;
using System.Data;
using System;
using System.IO;
using UnityEngine.UI;
public class DBAccess : MonoBehaviour {
public void OpenDB()
{
#if UNITY_EDITOR
connectionString = “URI=file:” + Application.dataPath + “/StreamingAssets/” + “catgiri.db”; //Path to database.
#elif UNITY_ANDROID
// check if file exists in Application.persistentDataPath
string filepath = Application.persistentDataPath + “/” + “catgiri.db”;
test.GetComponent().text = filepath;
if (!File.Exists(filepath))
{
Debug.LogWarning(“File "” + filepath + “" does not exist. Attempting to create from "” +
Application.dataPath + “!/assets/” + “catgiri.db”);
test.GetComponent().text = “1”;
// if it doesn’t →
// open StreamingAssets directory and load the db →
WWW loadDB = new WWW(“jar:file://” + Application.dataPath + “!/assets/” + “catgiri.db”);
while (!loadDB.isDone) { }
// then save to Application.persistentDataPath
File.WriteAllBytes(filepath, loadDB.bytes);
}
//open db connection
connectionString = “URI=file:” + filepath;
#endif
Debug.Log("Stablishing connection to: " + connectionString);
dbcon = (IDbConnection)new SqliteConnection(connectionString);
dbcon.Open();
}
Hello i have create a demo of game with sqlite database in Unity 4.6 , it s working fine with unity editor but not in android emulator or device, first time UI Text say 1 , then if i relaunch the db is created , i check it in folder and second launch say filepath correct
Storage/sdcard0/android/data/com.u.t/files/catgiri.db , the database is here
But In game nothing works like if connection doesn t do.
Can you help me plz ?
Thanks you for help