vendredi 28 août 2015

Database not loaded on Device, but works on Unity Editor

Good day I am having a problem accessing my database on my mobile android device. It seems that it doesn't read my database or I don't know my database is not included upon build. But here is the catch, my database works fine in unity editor. I can't seem to find the problem on my mobile device because I don't have access on it's console. BTW here is my code:

Reading database:

void readDatabase(){

     string conn = "URI=file:" + Application.dataPath + "/Database/AtlasDB.sqlite";

    string sqlQuery = "SELECT * FROM UserScore";

    using (SqliteConnection c = new SqliteConnection(conn))
        {
            c.Open();
            using (SqliteCommand cmd = new SqliteCommand(sqlQuery, c))
            {
                using (SqliteDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                        {
                        currHighScore = rdr.GetInt32(0);
                            //          string name = reader.GetString(1);
                        currHighDist = rdr.GetInt32(1);

                            Debug.Log( "High Score : " + currHighScore + ", High Distance: " + currHighDist);
                        }
                }
            }
        }

}

Updating database:

void highscoreChecker(){

string conn2 = "URI=file:" + Application.dataPath + "/Database/AtlasDB";
        string  sqlQuery2 = "UPDATE UserScore SET Highscore = '" + MoveSanji.scoreAccumulate + "'";

using (SqliteConnection c = new SqliteConnection(conn2))
        {
            c.Open();
            using (SqliteCommand cmd = new SqliteCommand(sqlQuery2, c))
            {
                if (MoveSanji.scoreAccumulate > currHighScore) {

                    cmd.ExecuteReader();
                }
            }
        }

string  sqlQuery3 = "UPDATE UserScore SET HighDistance = '" + Mathf.RoundToInt( MoveSanji.distanceRun )+ "'";

        using (SqliteConnection c = new SqliteConnection(conn2))
        {
            c.Open();
            using (SqliteCommand cmd = new SqliteCommand(sqlQuery3, c))
            {
                if (Mathf.RoundToInt( MoveSanji.distanceRun) > currHighDist) {

                    cmd.ExecuteReader();
                }
            }
        }

    }

Im using sqlite

Note: I made my database using SQLite Database Browser 2.0 b1 -- Database is located on my Database Folder in Assets Folder -- I have Mono.Data, Mono.Data.Sqlite, sqlite3.dll, sqlite3.def, System.Data.dll on my plugins folder

Aucun commentaire:

Enregistrer un commentaire