Hello guys, i hope you can help me.
The script finds the database inside android, but i can’t get data from DB.
i get an error like: no such table: ‘tableName’
But when i test it inside unity editor it works…
string p = "dialogue_Test.db";
//string filepath = Application.persistentDataPath + "/" + p;
#if UNITY_EDITOR
var dbPath = string.Format (@"Assets/StreamingAssets/{0}", p);
#else
string filepath=string.Format("{0}/{1}", Application.persistentDataPath, p);
Debug.Log (filepath);
if (!File.Exists (filepath)) {
Debug.Log("Don't exist DB");
Debug.LogWarning ("File \"" + filepath + "\" does not exist. Attempting to create from \"" +
Application.dataPath + "!/assets/" + p);
// if it doesn't ->
// open StreamingAssets directory and load the db ->
#if UNITY_ANDROID
WWW loadDB = new WWW ("jar:file://" + Application.dataPath + "!/assets/StreamingAssets/dialogue_Test.db");
while (!loadDB.isDone) {
}
File.WriteAllBytes (filepath, loadDB.bytes);
#elif UNITY_IOS
var loadDb = Application.dataPath + "/Raw/" + p; // this is the path to your StreamingAssets in iOS
// then save to Application.persistentDataPath
File.Copy(loadDb, filepath);
#elif UNITY_WP8
var loadDb = Application.dataPath + "/StreamingAssets/" + p; // this is the path to your StreamingAssets in iOS
// then save to Application.persistentDataPath
File.Copy(loadDb, filepath);
#elif UNITY_WINRT
var loadDb = Application.dataPath + "/StreamingAssets/" + p; // this is the path to your StreamingAssets in iOS
// then save to Application.persistentDataPath
File.Copy(loadDb, filepath);
#endif
Debug.Log("Database written");
}
var dbPath=filepath;
#endif
string conn = "URI=file:" + dbPath;
Debug.Log (conn);
IDbConnection dbConn;
dbConn = new SqliteConnection (conn);
dbConn.Open ();
string item = "*";
string table = "ptab";
string sqlQuery = "SELECT " + item + " FROM \"" + table + "\"";
IDbCommand command = dbConn.CreateCommand ();
command.CommandText = sqlQuery;
IDataReader reader = command.ExecuteReader ();
while (reader.Read ()) {
print(reader.GetString(0));
options [i, 0] = reader.GetString (0);
options [i, 1] = reader.GetString (1);
options [i, 2] = reader.GetString (2);
options [i, 3] = reader.GetString (3);
i++;
txt.text = "Yes it's ok";
}
reader.Close ();
reader = null;
command.Dispose ();
command = null;