/// <summary> /// Create this instance. /// </summary> public static void Create() { // save PlayerPrefs.SetString (HELLGATE_DB_PATH, sqlitePath); PlayerPrefs.SetString (HELLGATE_DB_OUTPUT_PATH, outputJsonPath); PlayerPrefs.SetString (HELLGATE_DB_IGNORE_TABLE, ignoreTableName); string[] ignores = ignoreTableName.Split (new string[] { ",", "|" }, System.StringSplitOptions.None); query = new Hellgate.Query (sqlitePath); SqliteMastser[] master = query.SELECT<SqliteMastser> ("type", (object)"table"); if (master == null) { Debug.Log ("There are no tables"); } else { for (int i = 0; i < master.Length; i++) { if (master [i].Name == "sqlite_sequence") { continue; } if (Array.IndexOf (ignores, master [i].Name) >= 0) { continue; } CreateUsalJson (master [i].Name); } } }
/// <summary> /// Create this instance. /// </summary> public static void Create() { // save PlayerPrefs.SetString(HELLGATE_DB_PATH, sqlitePath); PlayerPrefs.SetString(HELLGATE_DB_OUTPUT_PATH, outputJsonPath); PlayerPrefs.SetString(HELLGATE_DB_IGNORE_TABLE, ignoreTableName); string[] ignores = ignoreTableName.Split(new string[] { ",", "|" }, System.StringSplitOptions.None); query = new Hellgate.Query(sqlitePath); SqliteMastser[] master = query.SELECT <SqliteMastser> ("type", (object)"table"); if (master == null) { Debug.Log("There are no tables"); } else { for (int i = 0; i < master.Length; i++) { if (master [i].Name == "sqlite_sequence") { continue; } if (Array.IndexOf(ignores, master [i].Name) >= 0) { continue; } CreateUsalJson(master [i].Name); } } }
/// <summary> /// Creates the usal json. /// </summary> /// <param name="tableName">Table name.</param> public static void CreateUsalJson(string tableName) { Hellgate.DataTable data = query.SELECT(tableName); if (data.Rows.Count <= 0) { return; } string json = JsonUtil.ToJson(data.Rows); EditorUtil.CreateJsonFile(tableName, json, outputJsonPath); }
/// <summary> /// Simples the migration. /// </summary> /// <param name="force">If set to <c>true</c> force.</param> public void SimpleMigration(bool force = true) { // StreamingAssets folder string path = Path.Combine(Application.streamingAssetsPath, Path.GetFileName(pathDB)); if (path.Contains("://")) // android { WWW www = new WWW(path); while (!www.isDone) { ; } if (www.error == null) { path = string.Format("{0}_copy{1}", Path.GetFileNameWithoutExtension(path), Path.GetExtension(path)); path = Path.Combine(Application.persistentDataPath, path); File.WriteAllBytes(path, www.bytes); } else { HDebug.LogWarning(www.error); return; } path = Path.GetFileName(path); } Query query = new Query(path); SqliteMastser[] resources = query.SELECT <SqliteMastser> (); List <SqliteMastser> list = new List <SqliteMastser> (resources); query = new Query(pathDB); SqliteMastser[] masters = query.SELECT <SqliteMastser> (); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < masters.Length; i++) { SqliteMastser master = list.Find(x => x.Name == masters [i].Name); if (master != null) { list.Remove(master); } if (force) { if (master != null) { if (masters [i].Sql != master.Sql) { stringBuilder.Append(query.GenerateDropTableSQL(master.Name)); stringBuilder.AppendLine(); stringBuilder.AppendFormat("{0};", master.Sql); stringBuilder.AppendLine(); } } else { stringBuilder.Append(query.GenerateDeleteSQL(masters [i].Name)); stringBuilder.AppendLine(); } } } if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { stringBuilder.AppendFormat("{0};", list [i].Sql); stringBuilder.AppendLine(); } } if (stringBuilder.ToString() != "") { query.ExecuteNonQuery(stringBuilder.ToString()); } if (path.Contains("://")) // android { File.Delete(path); } }