Ejemplo n.º 1
0
        // Convert an object into an SQL query value:
        public virtual string Stringify()
        {
            // Format the value appropraitely.
            if (Value is DateTime)
            {
                DateTime actualValue = ( DateTime )(Value);
                return(String.Format("'{0}'", actualValue.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            else if (Value is QueryElement)
            {
                QueryElement actualValue = ( QueryElement )(Value);
                return(actualValue.Column);
            }
            else if (Value is DatabaseObject)
            {
                DatabaseObject actualValue = ( DatabaseObject )(Value);
                actualValue.Validate();

                return(String.Format("'{0}'", actualValue.Id));
            }
            else if (Value is DatabaseQuery)
            {
                DatabaseQuery actualValue = ( DatabaseQuery )(Value);
                return(String.Format("({0})", actualValue.Select));
            }
            else
            {
                return(String.Format("'{0}'", Value));
            }
        }
Ejemplo n.º 2
0
        // Add a database column as a query element.
        public void Add(string columnName)
        {
            QueryElement element = new QueryElement(columnName);

            columns      = null;
            values       = null;
            columnValues = null;
            elements.Add(element);
        }
Ejemplo n.º 3
0
        // Function to apply brackets to an inner comparator if it has a dfferent sign than the current comparator.
        public string Bracketify(QueryElement element)
        {
            if (element is QueryComparator)
            {
                QueryComparator comparator           = element as QueryComparator;
                bool            incompatibleOperator = comparator.And && this.Or || comparator.Or && this.And;
                if (!comparator.Not && incompatibleOperator)
                {
                    return(String.Format("({0})", element.Stringify()));
                }
            }

            return(element.Stringify());
        }