Concatenates two SQL WHERE clauses, handling empty or null values. - Android Database

Android examples for Database:SQL Statement

Description

Concatenates two SQL WHERE clauses, handling empty or null values.

Demo Code


//package com.book2s;
import android.text.TextUtils;

public class Main {
    /**/*from w  w w.  ja va  2s  . c o  m*/
     * Concatenates two SQL WHERE clauses, handling empty or null values.
     */
    public static String concatenateWhere(String a, String b) {
        if (TextUtils.isEmpty(a)) {
            return b;
        }
        if (TextUtils.isEmpty(b)) {
            return a;
        }

        return "(" + a + ") AND (" + b + ")";
    }
}

Related Tutorials