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, string tableName) { string q = "PRAGMA foreign_keys\n"; q += "PRAGMA foreign_keys = \"0\";"; q = "DROP TABLE " + "`" + tableName + "`"; 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); 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, string originName, string toCopyTable) { HashSet <string> SameDataType = new HashSet <string>(); Dictionary <string, ColumnInfo> copyColumns = dbManager.GetDBTableColumnsInfo(toCopyTable); Dictionary <string, ColumnInfo> selectColumns = dbManager.GetDBTableColumnsInfo(originName); foreach (KeyValuePair <string, ColumnInfo> c in copyColumns) { if (selectColumns.ContainsKey(c.Key)) { if (selectColumns [c.Key]._dataType == c.Value._dataType) { SameDataType.Add(c.Key); } } /* * if(c.Value._attribute.IndexOf(AUTOINCREMENT.Key) > 0 || * c.Value._attribute.IndexOf(PRIMARY_KEY.Key) > 0) * notSameDataType.Add(c.Key); * */ } string insertQ = "INSERT INTO " + toCopyTable + " "; string selectQ = " SELECT "; string selectColumnsQ = ""; string insertColumnsQ = "("; foreach (KeyValuePair <string, ColumnInfo> column in copyColumns) { if (SameDataType.Contains(column.Key)) { if (selectColumnsQ.Length > 0) { selectColumnsQ += ","; insertColumnsQ += ","; } selectColumnsQ += "`"; selectColumnsQ += column.Key; selectColumnsQ += "`"; insertColumnsQ += column.Key; } } insertColumnsQ += ") "; insertQ += insertColumnsQ; selectQ += selectColumnsQ; selectQ += " FROM " + "`" + originName + "`"; return(insertQ + selectQ); }
static public string GetQuery(MonoSQLiteManager dbManager, System.Type table) { Dictionary <string, ColumnInfo> columns = new Dictionary <string, ColumnInfo>(); FieldInfo[] fields = table.GetFields(); for (int i = 0; i < fields.Length; ++i) { string attributes = DBFieldAttribute.GetDBAttributes(fields[i]); ColumnInfo c = new ColumnInfo(fields[i].Name, dbManager.GetCTypeToSqlType(fields[i].FieldType), attributes); columns.Add(c._name, c); } return(GetQuery(dbManager, table.Name, columns)); }
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); }
static public string GetQuery(MonoSQLiteManager dbManager, string tableName, Dictionary <string, ColumnInfo> columns) { string q = "CREATE TABLE " + tableName + " ("; string q_fields = ""; foreach (KeyValuePair <string, ColumnInfo> c in columns) { if (q_fields.Length > 0) { q_fields += ","; } q_fields += "`"; q_fields += c.Key; q_fields += "`"; q_fields += " "; q_fields += c.Value._dataType; q_fields += " "; q_fields += c.Value._attribute; } q += q_fields; q += " )"; return(q); }
internal CreateTable(MonoSQLiteManager dbManager, string tableName, Dictionary <string, ColumnInfo> columns, bool isBackup = true) : base(dbManager) { _tableName = tableName; _columns = columns; _isBackup = isBackup; }
internal CloneTable(MonoSQLiteManager dbManager, string originName, string cloneName) : base(dbManager) { _originName = originName; _cloneName = cloneName; }
internal UpdateTable(MonoSQLiteManager dbManager, ref T table) : base(dbManager) { _table = table; }
internal CreateTable(MonoSQLiteManager dbManager, System.Type table, bool isBackup = true) : base(dbManager) { _table = table; _tableName = table.Name; _isBackup = isBackup; }
internal DropTable(MonoSQLiteManager dbManager, string tableName) : base(dbManager) { _tableName = tableName; }
internal InsertTable(MonoSQLiteManager dbManager, ref T table) : base(dbManager) { _table = table; }
internal CopyTable(MonoSQLiteManager dbManager, string originName, string toCopyTable) : base(dbManager) { _originName = originName; _toCopyTable = toCopyTable; }
protected QueryContainer(MonoSQLiteManager dbManager) { _dbManager = dbManager; }
static public string GetQuery(MonoSQLiteManager dbManager, string tableName, string columnName, System.Type type) { string fieldType = dbManager.GetCTypeToSqlType(type); return("ALTER TABLE " + tableName + " ADD COLUMN " + columnName + " " + fieldType); }
internal AddColumn(MonoSQLiteManager dbManager, string tableName, string columnName, System.Type type) : base(dbManager) { _tableName = tableName; _type = type; _columnName = columnName; }
static public string GetQuery(MonoSQLiteManager dbManager, string originName, string cloneName) { return("CREATE TABLE " + cloneName + " AS SELECT * FROM " + originName); }