Example #1
0
        /// <summary>
        /// Creates the command to get the number of rows in the given section.
        /// </summary>
        /// <returns>
        /// The command to get the number of rows in the given section.
        /// </returns>
        /// <param name='section'>
        /// The section to get the number of rows for.
        /// </param>
        protected virtual SQLiteCommand CreateRowCountCommand(int section)
        {
            string query = "select count (*) from \"" + TableName + "\"";

            object[] args;

            if (SectionExpression != null)
            {
                SQLiteWhereExpression where = new SQLiteWhereExpression();
                SQLiteAndExpression and = new SQLiteAndExpression();

                and.Add(new SQLiteEqualToExpression(SectionExpression, SectionTitles[section]));
                if (SearchExpression != null && SearchExpression.Expression != null)
                {
                    and.AddRange(SearchExpression.Expression);
                }

                where.Expression = and;

                query += " " + where.ToString(out args);
            }
            else if (SearchExpression != null)
            {
                query += " " + SearchExpression.ToString(out args);
            }
            else
            {
                args = new object [0];
            }

            return(Connection.CreateCommand(query, args));
        }
Example #2
0
        SQLiteWhereExpression ParseSearchExpression(string text)
        {
            SQLiteWhereExpression where = new SQLiteWhereExpression();
            SQLiteAndExpression and = new SQLiteAndExpression();
            List <string>       fields;
            bool quoted;

            for (int i = 0; i < text.Length; i++)
            {
                string token = GetNextToken(text, ref i, true, out quoted);

                if (i < text.Length && text[i] == ':')
                {
                    // The user may have requested for a particular field be matched...
                    i++;

                    if (string.IsNullOrEmpty(token))
                    {
                        // lone ':', just ignore...
                        continue;
                    }

                    string match = GetNextToken(text, ref i, false, out quoted);

                    if (match != null)
                    {
                        if (aliases.TryGetValue(token, out fields))
                        {
                            SQLiteOrExpression or = new SQLiteOrExpression();

                            // Search only the aliased fields for the string token...
                            foreach (var field in fields)
                            {
                                or.Add(new SQLiteLikeExpression(field, match));
                            }

                            and.Add(or);
                        }
                    }
                    else
                    {
                        SQLiteOrExpression or = new SQLiteOrExpression();

                        foreach (var col in types)
                        {
                            if (col.Value == typeof(string))
                            {
                                or.Add(new SQLiteLikeExpression(col.Key, token));
                            }
                        }

                        and.Add(or);
                    }
                }
                else if (token != null)
                {
                    // Search all fields for this string token...
                    SQLiteOrExpression or = new SQLiteOrExpression();

                    if (!quoted && aliases.TryGetValue(token, out fields))
                    {
                        foreach (var field in fields)
                        {
                            if (types[field] == typeof(bool))
                            {
                                or.Add(new SQLiteIsExpression(field, true));
                            }
                        }
                    }

                    foreach (var col in types)
                    {
                        if (col.Value == typeof(string))
                        {
                            or.Add(new SQLiteLikeExpression(col.Key, token));
                        }
                    }

                    and.Add(or);
                }
            }

            if (and.Count == 0)
            {
                return(null);
            }

            where.Expression = and;

            return(where);
        }