【发布时间】:2018-01-29 15:21:46
【问题描述】:
您好,我在访问我的移动 Android 设备上的数据库时遇到问题。似乎它没有读取我的数据库,或者我不知道我的数据库在构建时不包含在内。但这里有一个问题,我的数据库在统一编辑器中运行良好。我似乎无法在我的移动设备上找到问题,因为我无法访问它的控制台。顺便说一句,这是我的代码:
读取数据库:
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 Database Browser 2.0 b1 创建了我的数据库 -- 数据库位于资产文件夹中我的数据库文件夹中 -- 我的插件文件夹中有 Mono.Data、Mono.Data.Sqlite、sqlite3.dll、sqlite3.def、System.Data.dll
【问题讨论】: