我正在 Unity3d 游戏中创建数据库连接,并将其部署在 iOS 设备上。数据库连接工作正常,但我的数据库是空的,尽管我在启动前预先填充了它。
我正在使用 Unity 4.0.1 Pro 和我的 xCode 4.6 以及 C# 语言的代码。
这是我在 C# 中的代码
void Start ()
{
string connectionString;
if (Application.platform == RuntimePlatform.IPhonePlayer) {
connectionString = "URI=file:" + Application.persistentDataPath + "/Database.db";
} else {
connectionString = "URI=file:Database.db";
}
Debug.Log ("Connection String = " + connectionString);
IDbConnection dbcon;
dbcon = (IDbConnection)new SqliteConnection (connectionString);
dbcon.Open ();
Debug.Log ("Start DB");
IDbCommand dbcmd = dbcon.CreateCommand ();
string sql =
"SELECT * from Test ";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader ();
while (reader.Read()) {
Debug.Log ("IN WHILE");
string FirstName = reader.GetString (0);
// Print to Console
Debug.Log (FirstName);
}
// clean up
reader.Close ();
reader = null;
dbcmd.Dispose ();
dbcmd = null;
dbcon.Close ();
dbcon = null;
}
我在控制台中收到以下错误。
SqliteException: SQLite error
no such table: Test
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0
请帮我。