Example usage for android.database.sqlite SQLiteQueryBuilder buildQuery

List of usage examples for android.database.sqlite SQLiteQueryBuilder buildQuery

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteQueryBuilder buildQuery.

Prototype

public String buildQuery(String[] projectionIn, String selection, String groupBy, String having,
        String sortOrder, String limit) 

Source Link

Document

Construct a SELECT statement suitable for use in a group of SELECT statements that will be joined through UNION operators in buildUnionQuery.

Usage

From source file:com.money.manager.ex.reports.PayeeReportFragment.java

@Override
protected String prepareQuery(String whereClause) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());
    //data to compose builder
    String[] projectionIn = new String[] { ViewMobileData.PAYEEID + " AS _id", ViewMobileData.PAYEEID,
            ViewMobileData.PAYEE, "SUM(" + ViewMobileData.AmountBaseConvRate + ") AS TOTAL" };
    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal', 'Deposit')";
    if (!TextUtils.isEmpty(whereClause)) {
        selection += " AND " + whereClause;
    }//from   w  w  w. j  a  va 2 s. com
    String groupBy = ViewMobileData.PAYEEID + ", " + ViewMobileData.PAYEE;
    String having = null;
    String sortOrder = ViewMobileData.PAYEE;
    String limit = null;
    //compose builder
    builder.setTables(mobileData.getSource());
    //return query
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
    } else {
        return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, limit);
    }
}

From source file:com.money.manager.ex.home.DashboardFragment.java

@SuppressWarnings("deprecation")
private String prepareQueryTopPayees() {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());
    // data to compose builder
    String[] projectionIn = new String[] { "ROWID AS _id", ViewMobileData.PAYEEID, ViewMobileData.PAYEE,
            "ABS(SUM(" + ViewMobileData.AmountBaseConvRate + ")) AS TOTAL", "COUNT(*) AS NUM" };

    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal', 'Deposit') AND (julianday(date('now')) - julianday(" + ViewMobileData.Date
            + ") <= 30)";

    String groupBy = ViewMobileData.PAYEEID + ", " + ViewMobileData.PAYEE;
    String having = null;//w  ww  .j a va2 s .c  o  m
    String sortOrder = "ABS(SUM(" + ViewMobileData.AmountBaseConvRate + ")) DESC";
    String limit = "10";
    // compose builder
    builder.setTables(mobileData.getSource());
    // return query
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
    } else {
        return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, limit);
    }
}

From source file:com.money.manager.ex.home.DashboardFragment.java

private String prepareQueryTopWithdrawals() {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());
    // data to compose builder
    String[] projectionIn = new String[] { "ROWID AS _id", ViewMobileData.CATEGID, ViewMobileData.Category,
            ViewMobileData.SubcategID, ViewMobileData.Subcategory,
            "SUM(" + ViewMobileData.AmountBaseConvRate + ") AS TOTAL", "COUNT(*) AS NUM" };

    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal')" + " AND (julianday(date('now')) - julianday(" + ViewMobileData.Date
            + ") <= 30)";

    String groupBy = ViewMobileData.CATEGID + ", " + ViewMobileData.Category + ", " + ViewMobileData.SubcategID
            + ", " + ViewMobileData.Subcategory;
    String having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") < 0";
    String sortOrder = "ABS(SUM(" + ViewMobileData.AmountBaseConvRate + ")) DESC";
    String limit = "10";
    // compose builder
    builder.setTables(mobileData.getSource());
    // return query
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
    } else {//  w w  w . ja v  a  2  s . com
        return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, limit);
    }
}

From source file:com.money.manager.ex.budget.BudgetAdapter.java

private String prepareQuery(String whereClause) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());

    //data to compose builder
    String[] projectionIn = new String[] { "ROWID AS _id", ViewMobileData.CATEGID, ViewMobileData.Category,
            ViewMobileData.SubcategID, ViewMobileData.Subcategory,
            "SUM(" + ViewMobileData.AmountBaseConvRate + ") AS TOTAL" };

    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal', 'Deposit')";
    if (!TextUtils.isEmpty(whereClause)) {
        selection += " AND " + whereClause;
    }//from   ww  w  .  j  ava2 s. c om

    String groupBy = ViewMobileData.CATEGID + ", " + ViewMobileData.Category + ", " + ViewMobileData.SubcategID
            + ", " + ViewMobileData.Subcategory;

    String having = null;
    //        if (!TextUtils.isEmpty(((CategoriesReportActivity) context).mFilter)) {
    //            String filter = ((CategoriesReportActivity) context).mFilter;
    //            if (TransactionTypes.valueOf(filter).equals(TransactionTypes.Withdrawal)) {
    //                having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") < 0";
    //            } else {
    //                having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") > 0";
    //            }
    //        }

    String sortOrder = ViewMobileData.Category + ", " + ViewMobileData.Subcategory;
    String limit = null;

    builder.setTables(mobileData.getSource());

    return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
}

From source file:com.money.manager.ex.reports.CategoriesReportFragment.java

@Override
protected String prepareQuery(String whereClause) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());

    //data to compose builder
    String[] projectionIn = new String[] { "ROWID AS _id", // this does not fetch anything, unfortunately.
            ViewMobileData.CATEGID, ViewMobileData.Category, ViewMobileData.SubcategID,
            ViewMobileData.Subcategory, "SUM(" + ViewMobileData.AmountBaseConvRate + ") AS TOTAL" };

    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal', 'Deposit')";
    if (!TextUtils.isEmpty(whereClause)) {
        selection += " AND " + whereClause;
    }/* ww  w  . j av  a2 s  .  com*/

    String groupBy = ViewMobileData.CATEGID + ", " + ViewMobileData.Category + ", " + ViewMobileData.SubcategID
            + ", " + ViewMobileData.Subcategory;

    String having = null;
    if (!TextUtils.isEmpty(((CategoriesReportActivity) getActivity()).mFilter)) {
        String filter = ((CategoriesReportActivity) getActivity()).mFilter;
        if (TransactionTypes.valueOf(filter).equals(TransactionTypes.Withdrawal)) {
            having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") < 0";
        } else {
            having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") > 0";
        }
    }

    String sortOrder = ViewMobileData.Category + ", " + ViewMobileData.Subcategory;

    //compose builder
    builder.setTables(mobileData.getSource());

    //return query
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, null);
    } else {
        return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, null);
    }
}