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
私を助けてください。