コード例 #1
0
ファイル: QueryValueEntry.cs プロジェクト: Yetangitu/f-spot
        public static QueryValueEntry Create (QueryValue qv)
        {
            Type qv_type = qv.GetType ();
            Type entry_type = null;

            foreach (KeyValuePair<Type, Type> pair in types) {
                if (pair.Value == qv_type) {
                    entry_type = pair.Key;
                    break;
                }
            }

            // If we don't have an entry type that's exactly for our type, take a more generic one
            if (entry_type == null) {
                foreach (KeyValuePair<Type, Type> pair in types) {
                    if (qv_type.IsSubclassOf (pair.Value)) {
                        entry_type = pair.Key;
                        break;
                    }
                }
            }

            if (entry_type != null) {
                QueryValueEntry entry = Activator.CreateInstance (entry_type) as QueryValueEntry;
                entry.QueryValue = qv;
                return entry;
            }

            return null;
        }
コード例 #2
0
ファイル: QueryField.cs プロジェクト: Yetangitu/f-spot
        public string ToSql (Operator op, QueryValue qv)
        {
            string value = qv.ToSql (op) ?? String.Empty;

            if (op == null) op = qv.OperatorSet.First;

            StringBuilder sb = new StringBuilder ();

            if (no_custom_format) {
                string column_with_key = Column;
                if (qv is StringQueryValue && !(column_lowered || qv is ExactStringQueryValue)) {
                    column_with_key = String.Format ("HYENA_SEARCH_KEY({0})", Column);
                }
                sb.AppendFormat ("{0} {1}", column_with_key, String.Format (op.SqlFormat, value));

                if (op.IsNot) {
                    return String.Format ("({0} IS NULL OR {1})", Column, sb.ToString ());
                } else {
                    return String.Format ("({0} IS NOT NULL AND {1})", Column, sb.ToString ());
                }
            } else {
                sb.AppendFormat (
                    Column, String.Format (op.SqlFormat, value),
                    value, op.IsNot ? "NOT" : null
                );
            }

            return sb.ToString ();
        }
コード例 #3
0
ファイル: QueryValue.cs プロジェクト: codebutler/meshwork
 private static bool CreateFromXml(QueryValue val, XmlElement parent)
 {
     XmlElement val_node = parent[val.XmlElementName];
     if (val_node != null) {
         val.ParseXml (val_node);
         return !val.IsEmpty;
     }
     return false;
 }
コード例 #4
0
        QueryNode Parse(XmlElement node, QueryListNode parent)
        {
            if (node == null)
            {
                return(null);
            }

            QueryListNode list;

            //Console.WriteLine ("Parsing node: {0}", node.Name);
            switch (node.Name.ToLower())
            {
            case "and":
                list = new QueryListNode(Keyword.And);
                break;

            case "or":
                list = new QueryListNode(Keyword.Or);
                break;

            case "not":
                list = new QueryListNode(Keyword.Not);
                break;

            default:
                var term = new QueryTermNode();

                // Get the field (if any) that this term applies to
                if (node["field"] != null)
                {
                    term.Field = field_set [node["field"].GetAttribute("name")];
                }

                // Get the value
                term.Value = QueryValue.CreateFromXml(node, term.Field);

                // Get the operator from the term's name
                term.Operator = term.Value.OperatorSet [node.Name];


                if (parent != null)
                {
                    parent.AddChild(term);
                }

                return(term);
            }

            if (list != null)
            {
                if (parent != null)
                {
                    parent.AddChild(list);
                }

                // Recursively parse the children of a QueryListNode
                foreach (XmlNode child in node.ChildNodes)
                {
                    Parse(child as XmlElement, list);
                }
            }

            return(list);
        }