我在Unity3D遊戲中創建數據庫連接,並將其部署到iOS設備上。數據庫連接工作正常,但我的數據庫是空的,雖然我已經預先填充它發射之前。在iOS設備中啓動應用程序時Unity3d iPhone SQLite數據庫爲空設備
我使用的是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
請幫幫我。
您是否在該數據庫中創建了任何表格? –
@NicolasDai是的,我在數據庫中有crested table。 – Yashesh
@NicolasDai我發現了這個問題。我的數據庫存儲在unity3d.app包下,我正在訪問文檔文件夾。現在我怎樣才能訪問unity3d.app/myDatabase.db? – Yashesh