示例#1
0
        public CSQLUpdateBuilder _2_SetColumnObj(object obj, List <string> Cols, bool notUpdateId = true)
        {
            foreach (var col in Cols)
            {
                if (notUpdateId)
                {
                    if (col == "id")
                    {
                        continue;
                    }
                }


                var prop = obj.GetType().GetProperty(col);
                if (prop != null)
                {
                    var objValue = prop.GetValue(obj, null);
                    if (objValue != null)
                    {
                        string val = CMySQLConv.ToMySQLFormat(objValue);
                        _sqlQueryUpdate._2_SetColumns.Add(col, val);
                    }
                }
                else
                {
                    CheckSpecialTimeStamp(col, obj);
                }
            }

            return(this);
        }
        public CSQLInsertBuilder _2_SetColumn(object value)
        {
            string stValue = CMySQLConv.ToMySQLFormat(value);

            string stCol = value.ToString();


            return(this);
        }
        public CSQLInsertBuilder _2_SetColumn(string col, object value)
        {
            string stValue = CMySQLConv.ToMySQLFormat(value);



            _sqlInsertQuery._2_SetColumns.Add(col, stValue);

            return(this);
        }
        public CSQLInsertBuilder _2_SetColumnObj(object obj, List <string> Cols)
        {
            foreach (var col in Cols)
            {
                var prop = obj.GetType().GetProperty(col);
                if (prop != null)
                {
                    string val = CMySQLConv.ToMySQLFormat(prop.GetValue(obj, null));
                    _sqlInsertQuery._2_SetColumns.Add(col, val);
                }
                else
                {
                    CheckSpecialTimeStamp(col, obj);
                }
            }

            return(this);
        }
        private void CheckSpecialTimeStamp(string col, object obj)
        {
            if (!col.Contains("_timestamp_ms"))    //special case for time
            {
                return;
            }

            int num = col.IndexOf("_timestamp_ms");

            if (num > -1)
            {
                string colDt = col.Substring(0, num);
                var    prop  = obj.GetType().GetProperty(colDt);
                if (prop != null)
                {
                    string val = CMySQLConv.ToMySQLFormat(CUtilTime.GetUnixTimestampMillis((DateTime)prop.GetValue(obj, null)));

                    _sqlInsertQuery._2_SetColumns.Add(col, val);
                }
            }
        }
        public CSQLCreateBuilder _2_AddFieldsFromObject(Type t)
        {
            bool needExtraTimeStamp;


            var flds = t.GetProperties();


            foreach (var f in flds)
            {
                _sqlCreateTable._2_Fields.Add
                    (f.Name.ToString() + " " + CMySQLConv.ToMySQLType(f.PropertyType.Name.ToString(), out needExtraTimeStamp));
                if (needExtraTimeStamp)
                {
                    _sqlCreateTable._2_Fields.Add
                        (f.Name.ToString() + "_timestamp_ms BIGINT");
                }
            }


            return(this);
        }
示例#7
0
 public CSQLUpdateBuilder _2_SetColumn(string col, object value)
 {
     _sqlQueryUpdate._2_SetColumns.Add(col, CMySQLConv.ToMySQLFormat(value));
     return(this);
 }