Esempio n. 1
0
        public override BaseHelper Get(Dictionary <string, object> wheres, QueryObj query)
        {
            string showCols;

            if (string.IsNullOrEmpty(query.Select) || query.Select == "*")
            {
                showCols = allColumnNames;
            }
            else
            {
                showCols = query.Select;
            }

            string sortOn   = string.IsNullOrEmpty(query.SortOn) ? CurrentTable.PrimaryKey : query.SortOn;
            string sortType = string.Compare(query.SortType, "asc", StringComparison.CurrentCultureIgnoreCase) == 0 ? " ASC" : " DESC";

            int            pz;
            StringBuffer   sql     = "SELECT SQL_CALC_FOUND_ROWS ";
            WhereCondition which   = MakeWhere(wheres);
            string         tbWhere = Schema + CurrentTable.Name + which.WhereSql;

            //paginated data
            if (query.PageSize > 0)
            {
                pz = query.PageSize;

                int offset = pz * query.PageIndex;


                sql.AppendFormat("{0} FROM {1} ORDER BY {2} {3} LIMIT {4},{5};", showCols, tbWhere, sortOn, sortType, offset, pz);

                sql.AppendFormat("SELECT FOUND_ROWS() ;");

                //HttpContext.Current.Response.Write("<hr>" + sql + which.Params.Length + "<hr><hr>");
                //return this;

                DataSet ds = dac.GetDataSet(sql, which.Params);

                int count = ds.Tables[1].Rows[0][0].TryToInt();

                DataPage dp = new DataPage {
                    Table = ds.Tables[0],
                    Page  = MakePageInfo(count, pz, query.PageIndex)
                };

                return(End(dp, sql));
            }
            else
            {
                //sql += DefaultPagesize + " " + showCols + " From " + tbWhere + " Order By " + sortOn + sortType ;
                sql.AppendFormat("{0} FROM {1} ORDER BY {2} {3} LIMIT {4}", showCols, tbWhere, sortOn, sortType, DefaultPagesize);
                //HttpContext.Current.Response.Write("<hr>" + sql + "<hr><hr>");
                //return this;

                DataTable dt = dac.GetTableByReader(sql, which.Params);

                return(End(dt, sql));
            }
        }
        public void ShouldTestDoubles([Values("", "N0", "N2", "P0", "P2", "C0", "C2", "G", "G0", "G2", "E")] string format, [Random(double.MinValue, double.MaxValue, 20)] double floating)
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat($"{{0:{format}}}", floating);
            Check.That(buffer.ToString()).IsEqualTo(floating.ToString(format));
        }
        public void ShouldTestDecimals([Values("", "N0", "N2", "P0", "P2", "C0", "C2", "G", "G0", "G2", "E")] string format, [Random(-79228162514264337593543950335d, 79228162514264337593543950335d, 20)] decimal floating)
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat($"{{0:{format}}}", floating);
            Check.That(buffer.ToString()).IsEqualTo(floating.ToString(format));
        }
        public void ShouldTestShortNegativeHex([Values(-1)] short integer)
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat("{0:X}", integer);
            Check.That(buffer.ToString()).IsEqualTo(integer.ToString("X"));
        }
        public void ShouldTestLongs([Values("", "N0", "N2", "P0", "P2", "C0", "C2", "D", "D0", "D2", "G", "G0", "G2", "X", "E")] string format, [Random(int.MinValue, int.MaxValue, 20)] long integer)
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat($"{{0:{format}}}", integer);
            Check.That(buffer.ToString()).IsEqualTo(integer.ToString(format));
        }
Esempio n. 6
0
        public void should_throw_if_specifier_is_unrecognized()
        {
            var buffer = new StringBuffer(128);

            Check.ThatCode(() => buffer.AppendFormat("{0:q}", Guid.NewGuid()))
            .Throws <FormatException>();
        }
        public void ShouldTestUIntegers([Values("", "N0", "N2", "P0", "P2", "C0", "C2", "D", "D0", "D2", "G", "G0", "G2", "X", "E")] string format, [Random(0, int.MaxValue, 20)] int integer)
        {
            var unsigned = (uint)integer;
            var buffer   = new StringBuffer();

            buffer.AppendFormat($"{{0:{format}}}", unsigned);
            Check.That(buffer.ToString()).IsEqualTo(unsigned.ToString(format));
        }
        public void should_format_with_standard_date_format()
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat("Date {0}", new DateTime(2017, 01, 15, 11, 01, 55, 843));

            Check.That(buffer.ToString()).IsEqualTo("Date 2017-01-15 11:01:55.843");
        }
Esempio n. 9
0
        public void should_format_guid()
        {
            var buffer = new StringBuffer(128);

            buffer.AppendFormat("Guid {0}", Guid.Parse("de7bc307-699f-47a2-a0da-79c504edd68f"));

            Check.That(buffer.ToString()).IsEqualTo("Guid de7bc307-699f-47a2-a0da-79c504edd68f");
        }
        public void should_format_with_standard_timespan_format()
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat("Timespan {0}", new TimeSpan(11, 01, 55));

            Check.That(buffer.ToString()).IsEqualTo("Timespan 11:01:55.000");
        }
Esempio n. 11
0
        public void should_format_with_standard_timespan_format_when_more_than_one_day()
        {
            var buffer = new StringBuffer();

            buffer.AppendFormat("Timespan {0}", new TimeSpan(666, 11, 01, 55, 333));

            Check.That(buffer.ToString()).IsEqualTo("Timespan 666.11:01:55.3330000");
        }
Esempio n. 12
0
        public string StringBuffer()
        {
            _sb2.AppendFormat(formatTest, v1, v2);
            var s = _sb2.ToString();

            _sb2.Clear();
            return(s);
        }
Esempio n. 13
0
        public void should_format_guid_with_specifier(string format)
        {
            var guid   = Guid.Parse("de7bc307-699f-47a2-a0da-79c504edd68f");
            var buffer = new StringBuffer(128);

            buffer.AppendFormat($"{{0:{format}}}", guid);

            Check.That(buffer.ToString()).IsEqualTo(guid.ToString(format));
        }
        public void should_format_multiple_with_short_date_format()
        {
            var buffer   = new StringBuffer();
            var dateTime = _fixture.Create <DateTime>();

            buffer.AppendFormat("Date {0:yyyy-MM-dd}", dateTime);

            Check.That(buffer.ToString()).IsEqualTo($"Date {dateTime:yyyy-MM-dd}");
        }
Esempio n. 15
0
        public void should_format_many_guids()
        {
            var buffer = new StringBuffer();

            var newGuid = Guid.NewGuid();

            buffer.AppendFormat("Guid {0}", newGuid);

            Check.That(buffer.ToString()).IsEqualTo($"Guid {newGuid}");
        }
        public void should_format_many_with_standard_timespan_format()
        {
            var buffer = new StringBuffer();

            var timeSpan = TimeSpan.FromSeconds(_fixture.Create <int>());

            buffer.AppendFormat("Timespan {0}", timeSpan);

            Check.That(buffer.ToString()).IsEqualTo($"Timespan {timeSpan.ToString(@"hh\:mm\:ss\.fff")}");
        }
Esempio n. 17
0
        private WhereCondition MakeWhere(Dictionary <string, object> wheres)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            StringBuffer sb = " Where 1=1 ";


            foreach (KeyValuePair <string, object> kv in wheres)
            {
                string key = kv.Key;
                object val = kv.Value;

                if (hasColumn(key))
                {
                    /*if(val is List<KeyValuePair<string, object>>){
                     *      List<KeyValuePair<string, object>> lv = (List<KeyValuePair<string, object>>) val;
                     *      foreach(KeyValuePair<string, object> bv in lv){
                     *
                     *              SqlParameter param = makeParam(CurrentTable.Columns[key], bv.Value);
                     *
                     *              parameters.Add(param);
                     *              sb.Append(" And (" + key + bv.Key + param.ParameterName + ") ");
                     *      }
                     * }
                     * else{*/
                    string       prc;
                    SqlParameter param;


                    if (val is KeyValuePair <string, object> )
                    {
                        KeyValuePair <string, object> bv = (KeyValuePair <string, object>)val;
                        prc   = bv.Key;
                        param = makeParam(CurrentTable.Columns[key], bv.Value);
                    }
                    else
                    {
                        prc   = "=";
                        param = makeParam(CurrentTable.Columns[key], val);
                    }
                    parameters.Add(param);

                    sb.AppendFormat(" And ({0} {1} {2}) ", key, prc, param.ParameterName);

                    /*}*/
                }
            }

            return(new WhereCondition {
                WhereSql = sb.ToString(),
                Params = parameters.ToArray()
            });
        }
Esempio n. 18
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="updated"></param>
        /// <param name="wheres"></param>
        /// <returns></returns>
        public override BaseHelper Set(Dictionary <string, object> updated, Dictionary <string, object> wheres)
        {
            Dictionary <string, Column> cols = CurrentTable.Columns;

            StringBuffer        _valueNames = string.Empty;
            List <SqlParameter> _parameters = new List <SqlParameter>();

            foreach (KeyValuePair <string, Column> kv in cols)
            {
                string colName = kv.Key;
                Column col     = kv.Value;

                //在传入obj中存在数据
                if (updated.ContainsKey(colName))
                {
                    SqlParameter param = makeParam(col, updated[colName]);
                    _parameters.Add(param);

                    _valueNames += colName + "=" + param.ParameterName + ",";
                }
            }


            WhereCondition whereObj = MakeWhere(wheres);

            //合并2个params
            int n = _parameters.Count;
            int m = whereObj.Params.Length;

            SqlParameter[] paramx = new SqlParameter[n + m];
            _parameters.CopyTo(paramx);
            whereObj.Params.CopyTo(paramx, n);

            StringBuffer sql = new StringBuffer();            //"Update " + Schema + CurrentTable.Name + " Set " + _valueNames.ToString(0, _valueNames.Length - 1) + " " + whereObj.WhereSql + " ; ";

            sql.AppendFormat("UPDATE {0}{1} SET {2} {3} ;", Schema, CurrentTable.Name, _valueNames.ToString(0, _valueNames.Length - 1), whereObj.WhereSql);

//			HttpContext.Current.Response.Write("<hr>"+sql +  "<hr>"+paramx.Length+"<hr>");
//			for (int i = 0; i < paramx.Length ; i++){
//				HttpContext.Current.Response.Write("<hr>"+paramx[i].ParameterName +  "<hr>"+paramx[i].Value+"<hr>");
//			}
//			return this;

            if (inTrans)
            {
                return(SetTrans(sql, paramx));
            }
            else
            {
                int v = dac.ExecuteNonQuery(sql, paramx);
                return(End(v, sql));
            }
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            var f = new StringBuffer();

            f.AppendFormat(formatTest, v1, v2);
            Console.WriteLine(f.ToString());
            Console.WriteLine(formatTest, v1, v2);

            // test custom formatters
            StringBuffer.SetCustomFormatter <Blah>(CustomFormat);
            f.Clear();
            f.AppendFormat("Hello {0:yes}{0:no}", new Blah {
                Thing = 42
            });
            Console.WriteLine(f.ToString());

            // test static convenience method
            Console.WriteLine(StringBuffer.Format(formatTest, v1, v2));

            PerfTest();
#if DEBUG
            Console.ReadLine();
#endif
        }
Esempio n. 20
0
        protected unsafe void WritePrefix(Stream stream, LogEvent logEvent)
        {
            _stringBuffer.Clear();
            _stringBuffer.AppendFormat(_prefixFormat,
                                       logEvent.Timestamp.Date,
                                       logEvent.Timestamp.TimeOfDay,
                                       logEvent.ThreadId,
                                       LevelStringCache.GetLevelString(logEvent.Level),
                                       logEvent.Name);

            int bytesWritten;

            fixed(byte *buf = _tempBytes)
            bytesWritten = _stringBuffer.CopyTo(buf, 0, _stringBuffer.Count, _encoding);

            stream.Write(_tempBytes, 0, bytesWritten);
        }
Esempio n. 21
0
        protected override void OnDraw(double frameMS)
        {
            _sceneManager.CurrentScene.Draw(_sb3D, _sbUI);
            _sbUI.GraphicsDevice.Clear(Color.Transparent);
            _sbUI.Begin();
            _uiManager.Draw(_sbUI);

            _buffer.Clear();

            _buffer.AppendFormat(FORMATTED_STRING, CurrentFPS, _sceneManager.CurrentScene.RenderedObjectsCount, _sb3D.Calls, _sb3D.Merged,
                                 (World.Player == null ? string.Empty : World.Player.Position.ToString()),
                                 (_sceneManager.CurrentScene is GameScene gameScene && gameScene.SelectedObject != null ? gameScene.SelectedObject.ToString() : string.Empty),
                                 string.Empty);

            _infoText.Text = _buffer.ToString();
            _infoText.Draw(_sbUI, new Point(Window.ClientBounds.Width - 150, 20));
            _sbUI.End();
        }
Esempio n. 22
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="wheres"></param>
        /// <returns></returns>
        public override BaseHelper Del(Dictionary <string, object> wheres)
        {
            if (wheres == null)
            {
                throw new InvalidExpressionException("Error: 'WHERE' condition can't be null.");
            }

            WhereCondition whereObj = MakeWhere(wheres);
            var            sql      = new StringBuffer();

            sql.AppendFormat("Delete From {0}{1} {2};", Schema, CurrentTable.Name, whereObj.WhereSql);

            if (inTrans)
            {
                return(SetTrans(sql, whereObj.Params));
            }
            else
            {
                int v = dac.ExecuteNonQuery(sql, whereObj.Params);
                return(End(v, sql));
            }
        }
Esempio n. 23
0
        static void PerfTest()
        {
            var formatter = new StringBuffer();
            var builder   = new StringBuilder();

            GC.Collect(2, GCCollectionMode.Forced, true);
            var gcCount = GC.CollectionCount(0);
            var timer   = Stopwatch.StartNew();

            for (int k = 0; k < mul; k++)
            {
                for (int i = 0; i < count; i++)
                {
                    formatter.AppendFormat(formatTest, v1, v2);
                }
                formatter.Clear();
            }
            timer.Stop();
            Console.WriteLine("Mine : {0} us/format", timer.ElapsedMilliseconds * 1000.0 / (count * mul));
            Console.WriteLine("GCs  : {0}", GC.CollectionCount(0) - gcCount);
            Console.WriteLine();

            GC.Collect(2, GCCollectionMode.Forced, true);
            gcCount = GC.CollectionCount(0);
            timer   = Stopwatch.StartNew();

            for (int k = 0; k < mul; k++)
            {
                for (int i = 0; i < count; i++)
                {
                    builder.AppendFormat(formatTest, v1, v2);
                }
                builder.Clear();
            }
            timer.Stop();
            Console.WriteLine("BCL  : {0} us/format", timer.ElapsedMilliseconds * 1000.0 / (count * mul));
            Console.WriteLine("GCs  : {0}", GC.CollectionCount(0) - gcCount);
        }
Esempio n. 24
0
        public override BaseHelper GetField(Dictionary <string, object> wheres, QueryObj query, string whichColumn = null)
        {
            string showCols = whichColumn ?? CurrentTable.PrimaryKey;

            if (!CurrentTable.Columns.ContainsKey(whichColumn))
            {
                return(End(string.Empty, string.Empty));
            }

            StringBuffer orderBySql = string.IsNullOrEmpty(query.SortOn) ? string.Empty : (" Order By " + query.SortOn);

            WhereCondition which = MakeWhere(wheres);

            var sql = new StringBuffer();            //"Select " + showCols + " FROM " + CurrentTable.Name + which.WhereSql + orderBySql + " ;";

            sql.AppendFormat("SELECT {0} FROM {1} {2} {3};", showCols, CurrentTable.Name, which.WhereSql, orderBySql);
            //HttpContext.Current.Response.Write("<hr>"+sql +  "<hr><hr>");
            //return this;

            object objVal = dac.ExecuteScalar(sql, which.Params);

            return(End(objVal, sql));
        }
Esempio n. 25
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override BaseHelper Add(Dictionary <string, object> obj)
        {
            Dictionary <string, Column> cols = CurrentTable.Columns;

            StringBuilder       _colStrs    = new StringBuilder();
            StringBuilder       _valueNames = new StringBuilder();
            List <SqlParameter> _parameters = new List <SqlParameter>();

            foreach (KeyValuePair <string, Column> kv in cols)
            {
                string fieldName = kv.Key;
                Column col       = kv.Value;

                //在传入obj中存在数据
                if (obj.ContainsKey(fieldName))
                {
                    _colStrs.Append(fieldName + ",");

                    SqlParameter param = makeParam(col, obj[fieldName]);

                    _parameters.Add(param);
                    _valueNames.Append(param.ParameterName + ",");
                }

                //obj中不存在数据,但在映射中存在默认值
                else if (col.Default != null)
                {
                    _colStrs.Append(fieldName + ",");

                    //当 字段默认值为 函数
                    if (col.Default.IndexOf("(", StringComparison.Ordinal) > -1)
                    {
                        _valueNames.Append(col.Default + ",");
                    }
                    else
                    {
                        SqlParameter param = makeParam(col, col.Default);
                        _parameters.Add(param);
                        _valueNames.Append(param.ParameterName + ",");
                    }
                }
                //不存在值,且不允许空,且不会自动生成
                else if (!col.AllowNull && !col.AutoGenerate)
                {
                    throw new Exception("Error: " + CurrentTable.Name + ".[" + fieldName + "] can't be null.");
                }
            }

            _colStrs.Length    = _colStrs.Length - 1;
            _valueNames.Length = _valueNames.Length - 1;

            StringBuffer sql = "Set Nocount On; ";

            sql.AppendFormat("Insert Into {0}{1} ({2}) Values ({3}) ; ", Schema, CurrentTable.Name, _colStrs, _valueNames);
            sql += "SELECT @@IDENTITY ;Set Nocount Off;";


            //HttpContext.Current.Response.Write("<hr>"+sql +  "<hr><hr>");
            //return this;
            if (inTrans)
            {
                return(SetTrans(sql, _parameters.ToArray()));
            }
            else
            {
                object objVal = dac.ExecuteScalar(sql, _parameters.ToArray());
                return(End(objVal, sql));
            }
        }
Esempio n. 26
0
        public override BaseHelper Get(Dictionary <string, object> wheres, QueryObj query)
        {
            string showCols;

            if (string.IsNullOrEmpty(query.Select) || query.Select == "*")
            {
                showCols = allColumnNames;
            }
            else
            {
                showCols = query.Select;
            }

            string sortOn   = string.IsNullOrEmpty(query.SortOn) ? CurrentTable.PrimaryKey : query.SortOn;
            string sortType = string.Compare(query.SortType, "asc", StringComparison.CurrentCultureIgnoreCase) == 0 ? " ASC" : " DESC";

            int            pz;
            StringBuffer   sql     = "SELECT TOP ";
            WhereCondition which   = MakeWhere(wheres);
            string         tbWhere = Schema + CurrentTable.Name + which.WhereSql;

            //paginated data
            if (query.PageSize > 0)
            {
                pz = query.PageSize;

                int offset = pz * query.PageIndex;

                //sql += pz + " * FROM (Select " + showCols + ", ROW_NUMBER() OVER (ORDER BY " + sortOn + sortType + ") AS TabRowNumber FROM " ;
                //sql += tbWhere + ") as TA WHERE TA.TabRowNumber>" + offset + ";" ;

                sql.AppendFormat("{0} * FROM (SELECT {1},ROW_NUMBER() OVER (ORDER BY {2} {3}) AS TabRowNumber FROM {4}) as TA WHERE TA.TabRowNumber>{5};", pz, showCols, sortOn, sortType, tbWhere, offset);


                //sql += "Select @rowCount=Count(" + sortOn + ") FROM " + tbWhere ;
                sql.AppendFormat("SELECT @rowCount=Count({0}) FROM {1};", sortOn, tbWhere);

                SqlParameter rowCount = new SqlParameter("@rowCount", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                };

                SqlParameter[] pms = new SqlParameter[which.Params.Length + 1];
                which.Params.CopyTo(pms, 0);
                pms[which.Params.Length] = rowCount;


                //HttpContext.Current.Response.Write("<hr>" + sql + which.Params.Length + "<hr><hr>");
                //return this;

                DataTable dt = dac.GetTable(sql, pms);

                int count = (int)rowCount.Value;

                DataPage dp = new DataPage {
                    Table = dt,
                    Page  = MakePageInfo(count, pz, query.PageIndex)
                };

                return(End(dp, sql));
            }
            else
            {
                //sql += DefaultPagesize + " " + showCols + " From " + tbWhere + " Order By " + sortOn + sortType ;
                sql.AppendFormat("{0} {1} FROM {2} ORDER BY {3} {4}", DefaultPagesize, showCols, tbWhere, sortOn, sortType);
                //HttpContext.Current.Response.Write("<hr>" + sql + "<hr><hr>");
                //return this;

                DataTable dt = dac.GetTableByReader(sql, which.Params);

                return(End(dt, sql));
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="wheres"></param>
        /// <returns></returns>
        public override BaseHelper Del(Dictionary<string , object> wheres)
        {
            if (wheres == null)
                throw new InvalidExpressionException("Error: 'WHERE' condition can't be null.");

            WhereCondition whereObj = MakeWhere(wheres);
            var sql = new StringBuffer();
            sql.AppendFormat("Delete From {0}{1} {2};", Schema , CurrentTable.Name , whereObj.WhereSql);

            if (inTrans)
                return SetTrans(sql, whereObj.Params);
            else {
                int v = dac.ExecuteNonQuery(sql, whereObj.Params);
                return End(v, sql);
            }
        }
Esempio n. 28
0
        public override BaseHelper GetField(Dictionary<string , object> wheres, QueryObj query, string whichColumn = null)
        {
            string showCols = whichColumn ?? CurrentTable.PrimaryKey;

            if (!CurrentTable.Columns.ContainsKey(whichColumn))
                return End(string.Empty, string.Empty);

            StringBuffer orderBySql = string.IsNullOrEmpty(query.SortOn) ? string.Empty : (" Order By " + query.SortOn);

            WhereCondition which = MakeWhere(wheres);

            var sql = new StringBuffer();//"Select " + showCols + " FROM " + CurrentTable.Name + which.WhereSql + orderBySql + " ;";
            sql.AppendFormat("SELECT {0} FROM {1} {2} {3};" , showCols , CurrentTable.Name, which.WhereSql , orderBySql);
            //HttpContext.Current.Response.Write("<hr>"+sql +  "<hr><hr>");
            //return this;

            object objVal = dac.ExecuteScalar(sql, which.Params);

            return End(objVal, sql);
        }
Esempio n. 29
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="updated"></param>
        /// <param name="wheres"></param>
        /// <returns></returns>
        public override BaseHelper Set(Dictionary<string , object> updated, Dictionary<string , object> wheres)
        {
            Dictionary<string , Column> cols = CurrentTable.Columns;

            StringBuffer _valueNames = string.Empty ;
            List<SqlParameter> _parameters = new List<SqlParameter>();

            foreach (KeyValuePair<string, Column> kv in cols) {
                string colName = kv.Key;
                Column col = kv.Value;

                //在传入obj中存在数据
                if (updated.ContainsKey(colName)) {

                    SqlParameter param = makeParam(col, updated[colName]);
                    _parameters.Add(param);

                    _valueNames += colName + "=" + param.ParameterName + "," ;
                }
            }

            WhereCondition whereObj = MakeWhere(wheres);

            //合并2个params
            int n = _parameters.Count;
            int m = whereObj.Params.Length;
            SqlParameter[] paramx = new SqlParameter[n + m];
            _parameters.CopyTo(paramx);
            whereObj.Params.CopyTo(paramx, n);

            StringBuffer sql = new StringBuffer();//"Update " + Schema + CurrentTable.Name + " Set " + _valueNames.ToString(0, _valueNames.Length - 1) + " " + whereObj.WhereSql + " ; ";
            sql.AppendFormat("UPDATE {0}{1} SET {2} {3} ;" , Schema , CurrentTable.Name , _valueNames.ToString(0, _valueNames.Length - 1) , whereObj.WhereSql);

            //			HttpContext.Current.Response.Write("<hr>"+sql +  "<hr>"+paramx.Length+"<hr>");
            //			for (int i = 0; i < paramx.Length ; i++){
            //				HttpContext.Current.Response.Write("<hr>"+paramx[i].ParameterName +  "<hr>"+paramx[i].Value+"<hr>");
            //			}
            //			return this;

            if (inTrans)
                return SetTrans(sql, paramx);
            else {
                int v = dac.ExecuteNonQuery(sql, paramx);
                return End(v, sql);
            }
        }
Esempio n. 30
0
        private WhereCondition MakeWhere(Dictionary <string, object> wheres)
        {
            List <MySqlParameter> parameters = new List <MySqlParameter>();

            StringBuffer sb = " Where 1=1 ";

            foreach (KeyValuePair <string, object> kv in wheres)
            {
                string key = kv.Key;
                object val = kv.Value;
                if (key.Contains("!"))
                {
                    key = key.Replace("!", string.Empty);
                }

                string         prc;
                MySqlParameter param;

                if (hasColumn(key))
                {
                    if (val is KeyValuePair <string, object> )
                    {
                        KeyValuePair <string, object> bv = (KeyValuePair <string, object>)val;
                        prc   = bv.Key;
                        param = makeParam(CurrentTable.Columns[key], bv.Value);
                    }
                    else
                    {
                        prc   = "=";
                        param = makeParam(CurrentTable.Columns[key], val);
                    }
                    parameters.Add(param);

                    sb.AppendFormat(" And ({0} {1} {2}) ", key, prc, param.ParameterName);
                }
                else if (key.StartsWith("$", StringComparison.InvariantCultureIgnoreCase))
                {
                    //
                    if (key.Equals("$or", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // { "$or" : {"colName" : colValue} }
                        if (val is KeyValuePair <string, object> )
                        {
                            var rv = (KeyValuePair <string, object>)val;
                            param = makeParam(CurrentTable.Columns[rv.Key], rv.Value);

                            parameters.Add(param);
                            sb.AppendFormat(" Or {0}={1} ", rv.Key, param.ParameterName);
                        }
                        // { "$or" : [{"colName1" : colValue1} , {"colName2" : colValue2}] }
                        else if (val is List <KeyValuePair <string, object> > )
                        {
                            var rvs = (List <KeyValuePair <string, object> >)val;
                            if (rvs.Count > 0)
                            {
                                sb += " And ( ";
                                foreach (var rv in rvs)
                                {
                                    param = makeParam(CurrentTable.Columns[rv.Key], rv.Value);
                                    parameters.Add(param);
                                    sb.AppendFormat(" {0}={1} Or ", rv.Key, param.ParameterName);
                                }
                                sb.Length -= 3;
                                sb        += ") ";
                            }
                        }
                        //sb.AppendFormat(" And ({0} Or {1})");
                    }
                    else if (key.Equals("$and", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // { "$and" : {"colName" : colValue} }
                        if (val is KeyValuePair <string, object> )
                        {
                            var rv = (KeyValuePair <string, object>)val;
                            param = makeParam(CurrentTable.Columns[rv.Key], rv.Value);

                            parameters.Add(param);
                            sb.AppendFormat(" And {0}={1} ", rv.Key, param.ParameterName);
                        }
                    }
                }
            }

            return(new WhereCondition {
                WhereSql = sb.ToString(),
                Params = parameters.ToArray()
            });
        }
Esempio n. 31
0
 public void NoAllocation()
 {
     _sb2.AppendFormat(formatTest, v1, v2);
     _sb2.CopyTo(DestNative, 0, _sb2.Count);
     _sb2.Clear();
 }