public void SetTokens(QSqlBase s) { for (int i = 0; i < s.FieldCount; i++) { SetToken(s.GetColumnName(i), s.GetString(i)); } }
public static string GetValueForSql(Type t, object val) { if (t == typeof(string)) { return("'" + (val == null ? "" : QSqlBase.Normalize(val.ToString())) + "'"); } else if (t == typeof(bool)) { return((val != null && Convert.ToBoolean(val)) ? "1" : "0"); } else if (t == typeof(DateTime)) { return((val == null || val.ToString() == "") ? null : Convert.ToDateTime(val).ToString("yyyy-MM-dd HH:mm:ss")); } else if (t.IsNumericType()) { return(val == null ? "null" : val.ToString()); } return(null); }
public static void PopulateFromRow(QSqlBase s, object o, BindingFlags flags = BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance) { bool getFields, getProperties, declaredOnly; GetFlags(ref flags, out getFields, out getProperties, out declaredOnly); if (getProperties) { foreach (var prop in o.GetType().GetProperties(flags)) { bool hasPersistentAttribute = false; if (prop.IsDefined(typeof(PersistentAttribute), true)) { if (!prop.GetCustomAttribute <PersistentAttribute>(true).isPersistent) { continue; } hasPersistentAttribute = true; } if (declaredOnly == false || hasPersistentAttribute) { int i = s.MapColumnNameToIndex(prop.Name); if (i >= 0) { object val = s.GetForType(prop.PropertyType, i); if (val != null) { prop.SetValue(o, val); } } } } } if (getFields) { foreach (var prop in o.GetType().GetFields(flags)) { bool hasPersistentAttribute = false; if (prop.IsDefined(typeof(PersistentAttribute), true)) { if (!prop.GetCustomAttribute <PersistentAttribute>(true).isPersistent) { continue; } hasPersistentAttribute = true; } if (declaredOnly == false || hasPersistentAttribute) { int i = s.MapColumnNameToIndex(prop.Name); if (i >= 0) { object val = s.GetForType(prop.FieldType, i); if (val != null) { prop.SetValue(o, val); } } } } } }