// Use this for initialization void Start() { SqliteInit.InitSqlite(); FieldLister lister = new FieldLister(); UserData[] data = new UserData[2]; data[0] = new UserData(); data[0].ID = 1; data[0].Name = "Tarou"; data[0].Hoge = "fuga"; data[0].Age = 32; data[0].LastUpdated = new DateTime(2013, 4, 1); data[0].NestedClass.Fuga = "bbbb"; data[0].NestedClass.Hoge = 23; data[1] = new UserData(); data[1].ID = 2; data[1].Name = "Jirou"; data[1].Hoge = "wahoo"; data[1].Age = 11; data[1].AddressData = "aaaaa"; data[1].LastUpdated = new DateTime(2013, 5, 1); Write(data[0].ToString()); var info = lister.ListUp <UserData>(); Write(info.ToString()); var sqlMaker = new SQLMaker(); string insert = sqlMaker.GenerateInsertSQL(info, data[0]); string update = sqlMaker.GenerateUpdateSQL(info, data[0]); Write("Insert = {0}", insert); Write("Update = {0}", update); DBMapper mapper = new DBMapper(SqliteInit.Evolution.Database); mapper.UpdateOrInsertAll(data); 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()); }
// Use this for initialization void Start() { SqliteInit.InitSqlite(); FieldLister lister = new FieldLister(); UserData[] data = new UserData[2]; data[0] = new UserData(); data[0].ID = 1; data[0].Name = "Tarou"; data[0].Hoge = "fuga"; data[0].Age = 32; data[0].LastUpdated = new DateTime(2013,4,1); data[0].NestedClass.Fuga = "bbbb"; data[0].NestedClass.Hoge = 23; data[1] = new UserData(); data[1].ID = 2; data[1].Name = "Jirou"; data[1].Hoge = "wahoo"; data[1].Age = 11; data[1].AddressData = "aaaaa"; data[1].LastUpdated = new DateTime(2013,5,1); Debug.Log(data[0]); var info = lister.ListUp<UserData>(); Debug.Log(info); var sqlMaker = new SQLMaker(); string insert = sqlMaker.GenerateInsertSQL(info,data[0]); string update = sqlMaker.GenerateUpdateSQL(info,data[0]); Debug.Log("Insert = " + insert); Debug.Log("Update = " + update); DBMapper mapper = new DBMapper(SqliteInit.Evolution.Database); mapper.UpdateOrInsertAll(data); UserData[] fromDb = mapper.Read<UserData>("SELECT * FROM UserData;"); Debug.Log(fromDb[0]); Debug.Log(fromDb[1]); JSONMapper jsonMapper = new JSONMapper(); string json = jsonMapper.Write<UserData>(fromDb); UserData[] fromJson = jsonMapper.Read<UserData>(json); Debug.Log("Json = " + json); Debug.Log(fromJson[0]); Debug.Log(fromJson[1]); }
// 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 }
public static void InitSqlite(string file, string directory, string password) { if (alreadyInited) { return; } alreadyInited = true; pathDB = Path.Combine(Application.persistentDataPath, directory); pathDB = Path.Combine(pathDB, file); Evolution = new DBEvolution(file, directory, password); Evolution.RecreateTableIfHashDiffers = true; // You shoud set false when you release application to avoid suddon drop table. // Init table Evolution.Evolute("SampleTable", // Traget table new List <string>() // These sql is executed at once. { @"CREATE TABLE SampleTable(id INTEGER,nickname TEXT,lastLogin INTEGER, score FLOAT);", @"ALTER TABLE SampleTable ADD COLUMN age INTEGER;" }); Evolution.Evolute("OtherTable", new List <string>() { @"CREATE TABLE OtherTable(key TEXT,val TEXT);", @"INSERT INTO OtherTable VALUES ('a','b')" }); Evolution.Evolute("UserData", new List <string>() { //@"CREATE TABLE UserData(id INTEGER PRIMARY_KEY,name TEXT,hoge TEXT); " SQLMaker.GenerateCreateTableSQL <UserData>(ClassDescRepository.Instance.GetClassDesc <UserData>()) + " " }); }