Esempio n. 1
0
        protected string DeleteQuery(NameValueCollection queryString)
        {
            string result = "DELETE ";

            if (!string.IsNullOrEmpty(CatalogName))
            {
                result += CatalogName + ".";
            }
            result += Name + " WHERE 1=1";

            foreach (string name in queryString)
            {
                if (!FilterableColumns.Any() || FilterableColumns.Contains(name))
                {
                    if (Criteria.TryParse(queryString[name], out Criteria criteria))
                    {
                        result += " AND " + criteria.toSqlWhereClause(name);
                    }
                    else
                    {
                        result += " AND " + name;
                        if (queryString[name].Contains("%"))
                        {
                            result += " LIKE '" + queryString[name] + "'";
                        }
                        else
                        {
                            result += "=" + queryString[name].ToSqlValue();
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        protected string PutQuery(NameValueCollection queryString)
        {
            string result = "UPDATE ";

            if (!string.IsNullOrEmpty(CatalogName))
            {
                result += CatalogName + ".";
            }
            result += Name + " SET";
            string predicat = " WHERE 1=1";

            foreach (string name in queryString)
            {
                if (!FilterableColumns.Any() || FilterableColumns.Contains(name))
                {
                    if (Criteria.TryParse(queryString[name], out Criteria criteria))
                    {
                        predicat += " AND " + criteria.toSqlWhereClause(name);
                    }
                    else
                    {
                        predicat += " AND " + name;
                        if (queryString[name].Contains("%"))
                        {
                            predicat += " LIKE '" + queryString[name] + "'";
                        }
                        else
                        {
                            predicat += "=" + queryString[name].ToSqlValue();
                        }
                    }
                }
                else
                {
                    if (!VisibleColumns.Any() || VisibleColumns.Contains(name))
                    {
                        result += name + "=" + queryString[name].ToSqlValue() + ", ";
                    }
                }
            }

            result += string.Join(", ", DefaultColumns.Select(c => c.Key + "=" + c.Value.ToSqlValue())) + predicat;
            return(result);
        }
Esempio n. 3
0
        protected string GetQuery(NameValueCollection queryString)
        {
            string result = "SELECT " + (VisibleColumns.Any() ? string.Join(", ", VisibleColumns) : "*") + " FROM ";

            if (!string.IsNullOrEmpty(CatalogName))
            {
                result += CatalogName + ".";
            }
            result += Name + " WHERE 1 = 1";
            foreach (string name in queryString)
            {
                if (!FilterableColumns.Any() || FilterableColumns.Contains(name))
                {
                    if (Criteria.TryParse(queryString[name], out Criteria criteria))
                    {
                        result += " AND " + criteria.toSqlWhereClause(name);
                    }
                    else
                    {
                        result += " AND " + name;
                        if (queryString[name].Contains("%"))
                        {
                            result += " LIKE '" + queryString[name] + "'";
                        }
                        else
                        {
                            result += "=" + queryString[name].ToSqlValue();
                        }
                    }
                }
            }
            if (OrderColumns.Any())
            {
                result += " ORDER BY " + string.Join(", ", OrderColumns.Select(c => c.Key + (c.Value == OrderType.Ascending ? " ASC" : " DESC")));
            }

            return(result);
        }