Class SQLiteQueryBuilder


  • public class SQLiteQueryBuilder
    extends Object
    Sections taken from android.database.sqlite.SQLiteQueryBuilder in the Android Open Source Project and slightly modified.

    Copyright (C) 2006 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

    • Constructor Detail

      • SQLiteQueryBuilder

        public SQLiteQueryBuilder()
    • Method Detail

      • buildQueryString

        public static String buildQueryString​(boolean distinct,
                                              String table,
                                              String[] columns,
                                              String[] columnsAs,
                                              String where,
                                              String groupBy,
                                              String having,
                                              String orderBy,
                                              String limit)
        Build an SQL query string from the given clauses.
        Parameters:
        distinct - true if you want each row to be unique, false otherwise.
        table - The table name to compile the query against.
        columns - A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
        columnsAs - A list of values to return the corresponding columns as
        where - A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URL.
        groupBy - A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
        having - A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
        orderBy - How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
        limit - Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
        Returns:
        the SQL query string
      • buildQueryString

        public static String buildQueryString​(boolean distinct,
                                              String[] tables,
                                              String[] columns,
                                              String[] columnsAs,
                                              String where,
                                              String groupBy,
                                              String having,
                                              String orderBy,
                                              String limit)
        Build an SQL query string from the given clauses.
        Parameters:
        distinct - true if you want each row to be unique, false otherwise.
        tables - The table names to compile the query against.
        columns - A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
        columnsAs - A list of values to return the corresponding columns as
        where - A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URL.
        groupBy - A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
        having - A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
        orderBy - How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
        limit - Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
        Returns:
        the SQL query string
        Since:
        1.2.1
      • appendColumns

        public static void appendColumns​(StringBuilder s,
                                         String[] columns,
                                         String[] columnsAs)
        Add the names that are non-null in columns to s, separating them with commas.
        Parameters:
        s - string builder
        columns - columns
        columnsAs - columns as