예제 #1
0
파일: SetClause.cs 프로젝트: pigeon79/GCore
        public string ToSqlText(DataParameterCollection dpc, DbDialect dd, List <string> queryRequiredFields)
        {
            var sb = new StringBuilder("SET ");

            foreach (var kv in this)
            {
                if (queryRequiredFields != null)
                {
                    if (queryRequiredFields.Contains(kv.Key))
                    {
                        continue;
                    }
                }
                string dpStr;
                switch (kv.Operation)
                {
                case KvOpertation.None:
                    if (DataSettings.UsingParameter)
                    {
                        dpStr = dd.QuoteParameter(string.Format("{0}_{1}", DataParameter.LegalKey(kv.Key), dpc.Count));
                        var dp = new DataParameter(dpStr, kv.Value, kv.ValueType);
                        dpc.Add(dp);
                    }
                    else
                    {
                        dpStr = DataTypeParser.ParseToString(kv.Value, dd);
                    }
                    break;

                case KvOpertation.Now:
                    dpStr = dd.DbNowString;
                    break;

                case KvOpertation.Add:
                    dpStr = dd.QuoteForColumnName(kv.Key) + "+(" + kv.Value + ")";
                    break;

                case KvOpertation.Sub:
                    dpStr = dd.QuoteForColumnName(kv.Key) + "-(" + kv.Value + ")";
                    break;

                default:
                    throw new ApplicationException("Application Error");
                }

                sb.Append(dd.QuoteForColumnName(kv.Key));
                sb.Append("=");
                sb.Append(dpStr);
                sb.Append(",");
            }
            try
            {
                return(StringHelper.GetStringLeft(sb.ToString()));
            }
            catch (ArgumentOutOfRangeException)
            {
                return("");
            }
        }
예제 #2
0
        public string ToSqlText(DataParameterCollection dpc, DbDialect dd, List <string> queryRequiredFields)
        {
            var sb1 = new StringBuilder();
            var sb2 = new StringBuilder();

            foreach (var kv in this)
            {
                if (queryRequiredFields != null)
                {
                    if (queryRequiredFields.Contains(kv.Key))
                    {
                        continue;
                    }
                }
                string dpStr;
                switch (kv.Operation)
                {
                case KvOpertation.None:
                    if (DataSettings.UsingParameter)
                    {
                        dpStr = dd.QuoteParameter(string.Format("{0}_{1}", DataParameter.LegalKey(kv.Key), dpc.Count));
                        var dp = new DataParameter(dpStr, kv.NullableValue, kv.ValueType);
                        dpc.Add(dp);
                    }
                    else
                    {
                        dpStr = DataTypeParser.ParseToString(kv.Value, dd);
                    }
                    break;

                case KvOpertation.Now:
                    dpStr = dd.DbNowString;
                    break;

                case KvOpertation.Add:
                case KvOpertation.Sub:
                    dpStr = "0";
                    break;

                default:
                    throw new ApplicationException();
                }

                sb1.Append(dd.QuoteForColumnName(kv.Key));
                sb1.Append(",");

                sb2.Append(dpStr);
                sb2.Append(",");
            }
            return(string.Format(StatementTemplate, StringHelper.GetStringLeft(sb1.ToString()), StringHelper.GetStringLeft(sb2.ToString())));
        }
예제 #3
0
파일: Condition.cs 프로젝트: sfltd/DbEntry
        protected virtual string GetValueString(DataParameterCollection dpc, DbDialect dd, KeyValue kv)
        {
            if (kv.Value == null)
            {
                return("NULL");
            }
            string dpStr;

            if (ConfigReader.Config.Database.UseParameter)
            {
                dpStr = dd.QuoteParameter(string.Format("{0}_{1}", DataParameter.LegalKey(kv.Key), dpc.Count));
                var dp = new DataParameter(dpStr, kv.NullableValue, kv.ValueType);
                dpc.Add(dp);
            }
            else
            {
                dpStr = DataTypeParser.ParseToString(kv.Value, dd);
            }
            return(dpStr);
        }