// Use this for initialization void Start() { #if UNITY_ANDROID MyLibs.InitializeSQLCipher(); #endif if (dataObjects.Length < 1) { Write("No data to write database!"); return; } ORMSQLiteInit.InitSqlite(dbFile, dbDirectory, password); Write("Open Database at " + ORMSQLiteInit.pathDB); FieldLister lister = new FieldLister(); Write(dataObjects[0].ToString()); var info = lister.ListUp <UserData>(); Write(info.ToString()); string insert = SQLMaker.GenerateInsertSQL(info, dataObjects[0]); string update = SQLMaker.GenerateUpdateSQL(info, dataObjects[0]); Write("Insert = {0}", insert); Write("Update = {0}", update); DBMapper mapper = new DBMapper(ORMSQLiteInit.Evolution.Database); mapper.UpdateOrInsertAll(dataObjects); UserData[] fromDb = mapper.Read <UserData>("SELECT * FROM UserData;"); Write(fromDb[0].ToString()); Write(fromDb[1].ToString()); JSONMapper jsonMapper = new JSONMapper(); string json = jsonMapper.Write <UserData>(fromDb); UserData[] fromJson = jsonMapper.Read <UserData>(json); Write("Json = {0}", json); Write(fromJson[0].ToString()); Write(fromJson[1].ToString()); #if UNITY_ANDROID MyLibs.ToastMessage("SQLCipher Done"); #endif }
// Use this for initialization void Start() { #if UNITY_ANDROID MyLibs.InitializeSQLCipher(); #endif database = new SqliteDatabase(dbFilePath, dbDirectoryPath); database.Open(); if (!string.IsNullOrEmpty(dbPassword)) { database.Key(dbPassword); } Write("Open Database at " + database.pathDB); database.ExecuteNonQuery("delete from UserData;"); Write("Clear Table UserData"); object[] paramVal = new object[] { 1, "Joko", "Jakarta", 28 }; string query = "insert into UserData values ({0}, {1}, {2}, {3});"; Write("Execute: " + query, paramVal); database.ExecuteNonQuery(query, paramVal); QueryTable(1); paramVal = new object[] { "Joko Update", 1 }; query = "update UserData set name = {0} where Id = {1}"; Write("Execute: " + query, paramVal); database.ExecuteNonQuery(query, paramVal); QueryTable(1); database.Close(); #if UNITY_ANDROID MyLibs.ToastMessage("SQLCipher Done"); #endif }