public void ConfirmButton(Button button) { //send score to DB /* totalScore(); * Debug.Log("Total score is " + total + " and Button is " + button.name); * Debug.Log(button.name + " is pressed."); * Debug.Log("total = " + total); */ addTotalScore(); string sid = PlayerPrefs.GetString("sid", "001"); string totalScore = total.ToString(); SqliteDbHelper db = new SqliteDbHelper("Data Source=./sqlite.db"); if (!db.CheckTable("test0")) { db.CreateTable("test0", new string[] { "recordID", "userId", "totalScore", "date" }, new string[] { "integer primary key autoincrement", "int not null", " text not null", " timestamp default (date('now'))" }); } db.InsertIntoSpecific("test0", new string[] { "userId", "totalScore" }, new string[] { sid, "'" + totalScore + "'" }); db.CloseSqlConnection(); Debug.Log("OK!"); GameObject.Find("Canvas").transform.Find("ResultPanels").transform.Find("Result").gameObject.SetActive(false); //for development's sake, lets user know what the total score is //can be deleted when not needed GameObject.Find("Canvas").transform.Find("ResultPanels").transform.Find("Result2").gameObject.SetActive(true); ResultText2.text = "Your total score is: " + total; }
public void LoadScene(int level) { string sid = PlayerPrefs.GetString("sid", "001"); string score = GameObject.Find("Result/Score").GetComponent <Text>().text; string result = GameObject.Find("Result/Text").GetComponent <Text>().text; SqliteDbHelper db = new SqliteDbHelper("Data Source=./sqlite.db"); if (!db.CheckTable("test" + currentLevel.ToString())) { db.CreateTable("test" + currentLevel.ToString(), new string[] { "recordID", "userId", "score", "result", "date" }, new string[] { "integer primary key autoincrement", "int not null", " text not null", "text not null", " timestamp default (date('now'))" }); } db.InsertIntoSpecific("test" + currentLevel.ToString(), new string[] { "userId", "score", "result" }, new string[] { sid, "'" + score + "'", "'" + result + "'" }); db.CloseSqlConnection(); Debug.Log("OK!"); SceneManager.LoadScene(level); }
static int CreateTable(IntPtr L) { try { ToLua.CheckArgsCount(L, 4); SqliteDbHelper obj = (SqliteDbHelper)ToLua.CheckObject(L, 1, typeof(SqliteDbHelper)); string arg0 = ToLua.CheckString(L, 2); string[] arg1 = ToLua.CheckStringArray(L, 3); string[] arg2 = ToLua.CheckStringArray(L, 4); Mono.Data.Sqlite.SqliteDataReader o = obj.CreateTable(arg0, arg1, arg2); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void register() { string firstname = GameObject.Find("FirstName/InputField/Text").GetComponent <Text>().text; string lastname = GameObject.Find("LastName/InputField/Text").GetComponent <Text>().text; string grade = GameObject.Find("Grade/InputField/Text").GetComponent <Text>().text; string sid = GameObject.Find("SID/InputField/Text").GetComponent <Text>().text; SqliteDbHelper db = new SqliteDbHelper("Data Source=./sqlite.db"); if (!db.CheckTable("user")) { db.CreateTable("user", new string[] { "userid", "firstname", "lastname", "grade" }, new string[] { "integer primary key", "text not null", "text not null", "int not null" }); } db.InsertInto("user", new string[] { sid, "'" + firstname + "'", "'" + lastname + "'", grade }); db.CloseSqlConnection(); Debug.Log("OK!"); PlayerPrefs.SetString("sid", sid); }
void OnGUI() { if (GUILayout.Button("create table")) { db.CreateTable("mytable", new string[] { "id", "name", "email" }, new string[] { "int", "varchar(20)", "varchar(50)" }); Debug.Log("create table ok"); } if (GUILayout.Button("insert data")) { db.InsertInto("mytable", new string[] { "" + (++id), "'随风去旅行" + id + "'", "'zhangj_live" + id + "@163.com'" }); Debug.Log("insert table ok"); } if (GUILayout.Button("insert data specific")) { db.InsertIntoSpecific("mytable", new string[] { "name", "id" }, new string[] { "'随风去旅行6'", "99" }); Debug.Log("insert data specific ok"); } if (GUILayout.Button("Delete data")) { db.Delete("mytable", new string[] { "name" }, new string[] { "'随风去旅行6'" }); Debug.Log("Delete data ok"); } if (GUILayout.Button("Read Full Table")) { IDataReader sqReader = db.ReadFullTable("mytable"); while (sqReader.Read()) { string id = "id=" + sqReader.GetInt32(sqReader.GetOrdinal("id")); name = "name=" + sqReader.GetString(sqReader.GetOrdinal("name")); emls = "email=" + sqReader.GetString(sqReader.GetOrdinal("email")); Debug.LogError(id + "/" + name + "/" + emls); } Debug.Log("Read Full Table ok"); } if (GUILayout.Button("search database")) { IDataReader sqReader = db.SelectWhere("mytable", new string[] { "name", "email" }, new string[] { "id" }, new string[] { "=" }, new string[] { "2" }); while (sqReader.Read()) { name = "name=" + sqReader.GetString(sqReader.GetOrdinal("name")); emls = "email=" + sqReader.GetString(sqReader.GetOrdinal("email")); } } if (GUILayout.Button("Update data")) { db.UpdateInto("mytable", new string[] { "name", "email" }, new string[] { "'吴小雄'", "'吴小雄21a'" }, "id", "5"); Debug.Log("Update data ok"); } if (name != "") { GUI.Label(new Rect(100, 100, 100, 100), name); GUI.Label(new Rect(100, 200, 100, 100), emls); // GUILayout.Label(emls); } if (GUILayout.Button("close database")) { db.CloseSqlConnection(); Debug.Log("close table ok"); } }