美好的一天我在我的移動安卓設備上訪問我的數據庫時遇到問題。它似乎沒有讀取我的數據庫,或者我不知道我的數據庫不包含在構建中。但是這裏有個問題,我的數據庫在統一編輯器中工作正常。我似乎無法在我的移動設備上找到問題,因爲我無法訪問它的控制檯。順便說一句,這裏是我的代碼:數據庫未加載在設備上,但在Unity編輯器上工作
閱讀數據庫:
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);
}
}
}
}
}
更新數據庫:使用
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();
}
}
}
}
林sqlite的
注:我使用SQLite數據庫瀏覽器做了我的數據庫2.0 B1 - 數據庫位於我的數據庫文件夾中的資產文件夾 - 我有Mono.Data,Mono.Data.Sqlite,sqlite3.dll,sqlite3.def,Syste m.Data.dll我的插件文件夾
它仍然不爲我工作 我使用這個鏈接作爲參考:http://docs.unity3d.com/Manual/StreamingAssets.html 和改變了我的連接字符串是: 「JAR:文件: //「+ Application.dataPath +」!/assets/AtlasDB.sqlite「; – VonnCC