当前位置: 首页>>代码示例>>C#>>正文


C# QueryFilter.ToSQL方法代码示例

本文整理汇总了C#中QueryFilter.ToSQL方法的典型用法代码示例。如果您正苦于以下问题:C# QueryFilter.ToSQL方法的具体用法?C# QueryFilter.ToSQL怎么用?C# QueryFilter.ToSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QueryFilter的用法示例。


在下文中一共展示了QueryFilter.ToSQL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        public override bool Update(string table, Dictionary<string, object> values,
            Dictionary<string, int> incrementValues, QueryFilter queryFilter, uint? start,
            uint? count)
        {
            if ((values == null || values.Count < 1) && (incrementValues == null || incrementValues.Count < 1))
            {
                MainConsole.Instance.Warn("Update attempted with no values");
                return false;
            }

            string query = string.Format("UPDATE {0}", table);
            Dictionary<string, object> ps = new Dictionary<string, object>();

            string filter = "";
            if (queryFilter != null && queryFilter.Count > 0)
            {
                filter = " WHERE " + queryFilter.ToSQL('?', out ps);
            }

            List<string> parts = new List<string>();
            if (values != null)
            {
                foreach (KeyValuePair<string, object> value in values)
                {
                    string key = "?updateSet_" + value.Key.Replace("`", "");
                    ps[key] = value.Value;
                    parts.Add(string.Format("{0} = {1}", value.Key, key));
                }
            }
            if (incrementValues != null)
            {
                foreach (KeyValuePair<string, int> value in incrementValues)
                {
                    string key = "?updateSet_increment_" + value.Key.Replace("`", "");
                    ps[key] = value.Value;
                    parts.Add(string.Format("{0} = {0} + {1}", value.Key, key));
                }
            }

            query += " SET " + string.Join(", ", parts.ToArray()) + filter;

            if (start.HasValue)
            {
                query += " LIMIT " + start.Value.ToString();
                if (count.HasValue)
                {
                    query += ", " + count.Value.ToString();
                }
            }

            try
            {
                ExecuteNonQuery(query, ps);
            }
            catch (MySqlException e)
            {
                MainConsole.Instance.Error("[MySQLDataLoader] Update(" + query + "), " + e);
            }
            return true;
        }
开发者ID:BillBarnhill,项目名称:WhiteCore-Dev,代码行数:60,代码来源:MySQLDataManager.cs

示例2: Delete

        public override bool Delete(string table, QueryFilter queryFilter)
        {
            Dictionary<string, object> ps = new Dictionary<string, object>();
            string query = "DELETE FROM " + table +
                           (queryFilter != null ? (" WHERE " + queryFilter.ToSQL('?', out ps)) : "");

            try
            {
                ExecuteNonQuery(query, ps);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[MySQLDataLoader] Delete(" + query + "), " + e);
                return false;
            }
            return true;
        }
开发者ID:BillBarnhill,项目名称:WhiteCore-Dev,代码行数:17,代码来源:MySQLDataManager.cs

示例3: Query2

        private List<string> Query2(string sqll, QueryFilter queryFilter, Dictionary<string, bool> sort, uint? start,
            uint? count)
        {
            string query = sqll;
            Dictionary<string, object> ps = new Dictionary<string, object>();
            List<string> retVal = new List<string>();
            List<string> parts = new List<string>();

            if (queryFilter != null && queryFilter.Count > 0)
            {
                query += " WHERE " + queryFilter.ToSQL('?', out ps);
            }

            if (sort != null && sort.Count > 0)
            {
                parts = new List<string>();
                foreach (KeyValuePair<string, bool> sortOrder in sort)
                {
                    parts.Add(string.Format("`{0}` {1}", sortOrder.Key, sortOrder.Value ? "ASC" : "DESC"));
                }
                query += " ORDER BY " + string.Join(", ", parts.ToArray());
            }

            if (start.HasValue)
            {
                query += " LIMIT " + start.Value.ToString();
                if (count.HasValue)
                {
                    query += ", " + count.Value.ToString();
                }
            }

            IDataReader reader = null;
            int i = 0;
            try
            {
                using (reader = Query(query, ps))
                {
                    while (reader.Read())
                    {
                        for (i = 0; i < reader.FieldCount; i++)
                        {
                            Type r = reader[i].GetType();
                            retVal.Add(r == typeof (DBNull) ? null : reader.GetString(i));
                        }
                    }
                    return retVal;
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[MySQLDataLoader] Query(" + query + "), " + e);
                return null;
            }
        }
开发者ID:BillBarnhill,项目名称:WhiteCore-Dev,代码行数:55,代码来源:MySQLDataManager.cs

示例4: Delete

        public override bool Delete(string table, QueryFilter queryFilter)
        {
            Dictionary<string, object> ps = new Dictionary<string, object>();
            string query = "DELETE FROM " + table +
                           (queryFilter != null ? (" WHERE " + queryFilter.ToSQL(':', out ps)) : "");

            SqliteCommand cmd = new SqliteCommand(query);
            AddParams(ref cmd, ps);
            try
            {
                ExecuteNonQuery(cmd);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[Sqlite]: Delete(" + query + "), " + e);
                return false;
            }
            CloseReaderCommand(cmd);
            return true;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:20,代码来源:SQLiteDataManager.cs

示例5: Query2

        List<string> Query2(string query, QueryFilter queryFilter, Dictionary<string, bool> sort, 
                            uint? start, uint? count)
        {
            Dictionary<string, object> ps = new Dictionary<string, object>();
            List<string> parts;

            if (queryFilter != null && queryFilter.Count > 0)
            {
                query += " WHERE " + queryFilter.ToSQL(':', out ps);
            }

            if (sort != null && sort.Count > 0)
            {
                parts = new List<string>();
                foreach (KeyValuePair<string, bool> sortOrder in sort)
                {
                    parts.Add(string.Format("`{0}` {1}", sortOrder.Key, sortOrder.Value ? "ASC" : "DESC"));
                }
                query += " ORDER BY " + string.Join(", ", parts.ToArray());
            }

            if (start.HasValue)
            {
                query += " LIMIT " + start.Value;
                if (count.HasValue)
                {
                    query += ", " + count.Value;
                }
            }

            int i;
            var cmd = PrepReader(query);
            AddParams(ref cmd, ps);
            lock (GetLock())
            {
                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    var RetVal = new List<string>();
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            for (i = 0; i < reader.FieldCount; i++)
                                RetVal.Add(reader[i] == null ? null : reader[i].ToString());
                        }
                    }
                    //reader.Close();
                    CloseReaderCommand(cmd);

                    return RetVal;
                }
            }
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:53,代码来源:SQLiteDataManager.cs

示例6: Query2

        List<string> Query2(string query, QueryFilter queryFilter, Dictionary<string, bool> sort, 
                            uint? start, uint? count)
        {
            Dictionary<string, object> ps = new Dictionary<string, object>();
            List<string> parts;

            if (queryFilter != null && queryFilter.Count > 0)
            {
                query += " WHERE " + queryFilter.ToSQL (':', out ps);

                // 20161014 -greythane- 
                // temporary fix for events until the datetime field can be modified to something that SQLite can handle
                if (query.Contains ("UNIX_TIMESTAMP")) {
                    // reset to the 'datetime()' function
                    query = query.Replace ("UNIX_TIMESTAMP(", "datetime(");

                    // convert unix times to utc seconds
                    var newps = new Dictionary<string, object> ();
                    foreach (var qval in ps) {
                        if (qval.Key.Contains ("UNIX_TIMESTAMP")) {
                            var unixTs = (float)qval.Value;
                            var unixDateTime = Util.ToDateTime ((ulong)unixTs);
                            var newVal = unixDateTime.ToLocalTime().ToString ("yyyy-MM-dd HH:mm");
                            newps.Add (qval.Key, newVal);
                        } else
                            newps.Add (qval.Key, qval.Value);
                    }
                    ps = newps;
                }
            }

            if (sort != null && sort.Count > 0)
            {
                parts = new List<string>();
                foreach (KeyValuePair<string, bool> sortOrder in sort)
                {
                    parts.Add(string.Format("`{0}` {1}", sortOrder.Key, sortOrder.Value ? "ASC" : "DESC"));
                }
                query += " ORDER BY " + string.Join(", ", parts.ToArray());
            }

            if (start.HasValue)
            {
                query += " LIMIT " + start.Value;
                if (count.HasValue)
                {
                    query += ", " + count.Value;
                }
            }

            int i;
            var cmd = PrepReader(query);
            AddParams(ref cmd, ps);
            lock (GetLock())
            {
                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    var RetVal = new List<string>();
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            for (i = 0; i < reader.FieldCount; i++)
                                RetVal.Add(reader[i] == null ? null : reader[i].ToString());
                        }
                    }
                    //reader.Close();
                    CloseReaderCommand(cmd);

                    return RetVal;
                }
            }
        }
开发者ID:WhiteCoreSim,项目名称:WhiteCore-Dev,代码行数:73,代码来源:SQLiteDataManager.cs


注:本文中的QueryFilter.ToSQL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。