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


C# QueryFilter.ToSQL方法代码示例

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


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

示例1: 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("[SQLiteDataManager] Delete(" + query + "), " + e);
                return false;
            }
            CloseReaderCommand(cmd);
            return true;
        }
开发者ID:SignpostMarv,项目名称:Aurora-Sim,代码行数:19,代码来源:SQLiteDataManager.cs

示例2: 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();
                }
            }

            SQLiteCommand cmd = new SQLiteCommand(query);
            AddParams(ref cmd, ps);

            try
            {
                ExecuteNonQuery(cmd);
            }
            catch (SQLiteException e)
            {
                MainConsole.Instance.Error("[SQLiteLoader] Update(" + query + "), " + e);
            }
            CloseReaderCommand(cmd);
            return true;
        }
开发者ID:SignpostMarv,项目名称:Aurora-Sim,代码行数:62,代码来源:SQLiteDataManager.cs

示例3: Query

        public override List<string> Query(string[] wantedValue, string table, QueryFilter queryFilter, Dictionary<string, bool> sort, uint? start, uint? count)
        {
            string query = string.Format("SELECT {0} FROM {1}", string.Join(", ", wantedValue), table); ;
            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();
                }
            }

            int i = 0;

            var cmd = PrepReader(query);
            AddParams(ref cmd, ps);
            using (IDataReader reader = cmd.ExecuteReader())
            {
                var RetVal = new List<string>();
                while (reader.Read())
                {
                    for (i = 0; i < reader.FieldCount; i++)
                    {
                        Type r = reader[i].GetType();
                        RetVal.Add(r == typeof(DBNull) ? null : reader[i].ToString());
                    }
                }
                //reader.Close();
                CloseReaderCommand(cmd);

                return RetVal;
            }
        }
开发者ID:SignpostMarv,项目名称:Aurora-Sim,代码行数:52,代码来源:SQLiteDataManager.cs

示例4: Query2

        private 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> 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();
                }
            }

            int i = 0;

            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:nathanmarck,项目名称:Aurora-Sim,代码行数:54,代码来源:SQLiteDataManager.cs

示例5: Delete

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

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

示例6: Query

        public override List<string> Query(string[] wantedValue, string table, QueryFilter queryFilter, Dictionary<string, bool> sort, uint? start, uint? count)
        {
            string query = string.Format("SELECT {0} FROM {1}", string.Join(", ", wantedValue), table); ;
            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)
            {
                uint j = 0;
                query += " WHERE " + queryFilter.ToSQL('?', out ps, ref j);
            }

            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;
            }
            finally
            {
                try
                {
                    if (reader != null)
                    {
                        reader.Close();
                        //reader.Dispose ();
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error("[MySQLDataLoader] Query(" + query + "), " + e);
                }
            }
        }
开发者ID:Gnu32,项目名称:Silverfin,代码行数:69,代码来源:MySQLDataManager.cs


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