static public string GetQuery(MonoSQLiteManager dbManager, ref T table) { Dictionary <string, ColumnInfo> columns = dbManager.GetTableColumnsInfo(table.GetType()); System.Type type = table.GetType(); FieldInfo[] members = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.GetField); FieldInfo key = dbManager.GetPrimaryKey(members); if (key == null) { Debug.Log("not Update None PrimaryKey table. name = " + type.Name); return(null); } int keyindex = 0; for (int i = 0; i < members.Length; ++i) { if (key == members[i]) { keyindex = i; break; } } return("DELETE FROM " + type.Name + " WHERE " + members[keyindex].Name + " = " + members[keyindex].GetValue(table).ToString()); }
static public string GetQuery(MonoSQLiteManager dbManager, ref T table) { Dictionary <string, ColumnInfo> columns = dbManager.GetTableColumnsInfo(table.GetType()); System.Type type = table.GetType(); FieldInfo[] members = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.GetField); FieldInfo key = dbManager.GetPrimaryKey(members); if (key == null) { Debug.Log("not Update None PrimaryKey table. name = " + type.Name); return(null); } int keyindex = 0; for (int i = 0; i < members.Length; ++i) { if (key == members[i]) { keyindex = i; break; } } string q = "UPDATE " + type.Name + " SET "; string columns_q = ""; for (int i = 0; i < members.Length; ++i) { if (keyindex == i) { continue; } if (columns_q.Length > 0) { columns_q += ","; } columns_q += members[i].Name; columns_q += "="; if (members[i].FieldType == typeof(string) || members[i].FieldType == typeof(char)) { columns_q += "\""; } columns_q += members[i].GetValue(table).ToString(); if (members[i].FieldType == typeof(string) || members[i].FieldType == typeof(char)) { columns_q += "\""; } } q += columns_q + " where " + members[keyindex].Name + "= " + members[keyindex].GetValue(table).ToString(); return(q); }
static public string GetQuery(MonoSQLiteManager dbManager, ref T table) { Dictionary <string, ColumnInfo> columns = dbManager.GetTableColumnsInfo(table.GetType()); System.Type type = table.GetType(); FieldInfo[] members = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.GetField); FieldInfo key = dbManager.GetPrimaryKey(members); string q = "INSERT INTO " + table.GetType().Name + " ("; string columns_q = ""; string value_q = " values("; for (int i = 0; i < members.Length; ++i) { if (members[i] == key) { continue; } if (columns_q.Length > 0) { columns_q += ","; value_q += ","; } columns_q += members[i].Name; if (members[i].FieldType == typeof(string) || members[i].FieldType == typeof(char)) { value_q += "'"; value_q += members[i].GetValue(table); value_q += "'"; } else { value_q += members[i].GetValue(table).ToString(); } } q += columns_q + ")"; q += value_q + ")"; return(q); }