Exemplo n.º 1
0
        // Update the query, which updates the icon_view
        public void UpdateQuery()
        {
            if (preventUpdate)
            {
                return;
            }

            if (sepBox != null)
            {
                sepBox.Hide();
            }

            if (rootTerm.Count == 0)
            {
                help.Show();
                query.TagTerm = null;
            }
            else
            {
                help.Hide();
                query.TagTerm = new ConditionWrapper(rootTerm.SqlCondition());
            }

            EventHandler handler = Changed;

            if (handler != null)
            {
                handler(this, new EventArgs());
            }
        }
Exemplo n.º 2
0
        // Update the query, which updates the icon_view
        public void UpdateQuery()
        {
            if (preventUpdate)
            {
                return;
            }

            if (sepBox != null)
            {
                sepBox.Hide();
            }

            if (rootTerm.Count == 0)
            {
                help.Show();
                query.ExtraCondition = null;
            }
            else
            {
                help.Hide();
                query.ExtraCondition = rootTerm.SqlCondition();
                //Console.WriteLine ("extra_condition = {0}", query.ExtraCondition);
            }

            EventHandler handler = Changed;

            if (handler != null)
            {
                handler(this, new EventArgs());
            }
        }
Exemplo n.º 3
0
        // Recursively generate the SQL condition clause that this
        // term represents.
        public virtual string SqlCondition()
        {
            StringBuilder condition = new StringBuilder("(");

            for (int i = 0; i < SubTerms.Count; i++)
            {
                Term term = SubTerms[i] as Term;
                condition.Append(term.SqlCondition());

                if (i != SubTerms.Count - 1)
                {
                    condition.Append(SQLOperator());
                }
            }

            condition.Append(")");

            return(condition.ToString());
        }
Exemplo n.º 4
0
        public void RequestReload()
        {
            uint timer = Log.DebugTimerStart();

            IQueryCondition[] condition_array;

            int i = 0;

            if (untagged)
            {
                condition_array    = new IQueryCondition[conditions.Count + 1];
                condition_array[0] = new UntaggedCondition();
                i = 1;
            }
            else
            {
                condition_array = new IQueryCondition[conditions.Count + 2];
                //		condition_array[0] = new ConditionWrapper (extra_condition);
                condition_array[1] = new ConditionWrapper(terms != null ? terms.SqlCondition() : null);
                i = 2;
            }

            foreach (IQueryCondition condition in Conditions.Values)
            {
                condition_array[i] = condition;
                i++;
            }

            store.QueryToTemp(temp_table, condition_array);

            count          = -1;
            cache          = new PhotoCache(store, temp_table);
            reverse_lookup = new Dictionary <uint, int> ();

            if (Changed != null)
            {
                Changed(this);
            }

            Log.DebugTimerPrint(timer, "Reloading the query took {0}");
        }
Exemplo n.º 5
0
        public Photo [] Query(Term searchexpression, string extraCondition, DateRange range, RollSet importidrange, RatingRange ratingrange)
        {
            bool hide = (extraCondition == null);

            // The SQL query that we want to construct is:
            //
            // SELECT photos.id
            //        photos.time
            //        photos.uri,
            //        photos.description,
            //        photos.roll_id,
            //        photos.default_version_id
            //        photos.rating
            //                  FROM photos, photo_tags
            //                  WHERE photos.time >= time1 AND photos.time <= time2
            //                              AND photos.rating >= rat1 AND photos.rating <= rat2
            //                              AND photos.id NOT IN (select photo_id FROM photo_tags WHERE tag_id = HIDDEN)
            //                              AND photos.id IN (select photo_id FROM photo_tags where tag_id IN (tag1, tag2..)
            //                              AND extra_condition_string
            //                  GROUP BY photos.id

            var query_builder = new StringBuilder();
            var where_clauses = new List <string> ();

            query_builder.Append("SELECT id, " +
                                 "time, " +
                                 "base_uri, " +
                                 "filename, " +
                                 "description, " +
                                 "roll_id, " +
                                 "default_version_id, " +
                                 "rating " +
                                 "FROM photos ");

            if (range != null)
            {
                where_clauses.Add(String.Format("time >= {0} AND time <= {1}",
                                                DateTimeUtil.FromDateTime(range.Start),
                                                DateTimeUtil.FromDateTime(range.End)));
            }

            if (ratingrange != null)
            {
                where_clauses.Add(ratingrange.SqlClause());
            }

            if (importidrange != null)
            {
                where_clauses.Add(importidrange.SqlClause());
            }

            if (hide && App.Instance.Database.Tags.Hidden != null)
            {
                where_clauses.Add(String.Format("id NOT IN (SELECT photo_id FROM photo_tags WHERE tag_id = {0})",
                                                App.Instance.Database.Tags.Hidden.Id));
            }

            if (searchexpression != null)
            {
                where_clauses.Add(searchexpression.SqlCondition());
            }

            if (extraCondition != null && extraCondition.Trim() != String.Empty)
            {
                where_clauses.Add(extraCondition);
            }

            if (where_clauses.Count > 0)
            {
                query_builder.Append(" WHERE ");
                query_builder.Append(String.Join(" AND ", where_clauses.ToArray()));
            }

            query_builder.Append(" ORDER BY time");
            return(Query(query_builder.ToString()));
        }