具有多个选择参数的android sqlite查询代码

时间:2017-07-21 12:22:36

标签: android mysql sqlite datepicker

我正在构建具有大约20种可能条件的sqlite查询参数。 我想在这里实现的是,当只设置20个条件中的几个时,我如何动态调整并从查询中删除未使用的条件。

String selection = ProjectEntry.COLUMN_CR_NUMBER + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PHASE + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CATEGORY + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PRIORITY + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PERCENT_COMPLETION  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_REGION  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_BU  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PROJECT_NAME  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_RAG  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PO_DATE  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CUSTOMER_DUE_DATE  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CURRENT_BASELINE_DUE_DATE  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_FORECASTED_DUE_DATE  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_ACTUAL_COMPLETE_DATE  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_STATUS  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CUSTOMER_REF  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CUSTOMER_COST_CENTER  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_COUNTRY  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_CUSTOMER_PM  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_PM  + " LIKE?" + " AND "
                + ProjectEntry.COLUMN_ENGINEER + " LIKE?"
                ;

        String[] selectionArg = {
                "%" + queryCrNumber + "%",
                "%" + queryPhase + "%",
                "%" + queryCategory + "%",
                "%" + queryPriority + "%",
                "%" + queryPercentCompletion + "%",
                "%" + queryRegion + "%",
                "%" + queryBu + "%",
                "%" + queryProjectName + "%",
                "%" + queryRag + "%",
                "%" + queryPoDate + "%",
                "%" + queryCustomerDueDate + "%",
                "%" + queryCurrentBaselineDueDate + "%",
                "%" + queryForecastedDueDate + "%",
                "%" + queryActualCompletionDate + "%",
                "%" + queryStatus + "%",
                "%" + queryCustomerRef + "%",
                "%" + queryCustomerCostCenter + "%",
                "%" + queryCountry + "%",
                "%" + queryCustomerPM + "%",
                "%" + queryPM+ "%",
                "%" + queryEngineer + "%"
        };

0 个答案:

没有答案