Ejemplo n.º 1
0
 public void SetTokens(QSqlBase s)
 {
     for (int i = 0; i < s.FieldCount; i++)
     {
         SetToken(s.GetColumnName(i), s.GetString(i));
     }
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        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);
                            }
                        }
                    }
                }
            }
        }