DatabaseUtilsCompat.java revision 1935ed3af7c6545bc38adfdc6026d87a3249222f
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.database;
18
19import android.text.TextUtils;
20
21/**
22 * Helper for accessing newer features in DatabaseUtils.
23 */
24public class DatabaseUtilsCompat {
25
26    private DatabaseUtilsCompat() {
27        /* Hide constructor */
28    }
29
30    /**
31     * Concatenates two SQL WHERE clauses, handling empty or null values.
32     */
33    public static String concatenateWhere(String a, String b) {
34        if (TextUtils.isEmpty(a)) {
35            return b;
36        }
37        if (TextUtils.isEmpty(b)) {
38            return a;
39        }
40
41        return "(" + a + ") AND (" + b + ")";
42    }
43
44    /**
45     * Appends one set of selection args to another. This is useful when adding a selection
46     * argument to a user provided set.
47     */
48    public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
49        if (originalValues == null || originalValues.length == 0) {
50            return newValues;
51        }
52        String[] result = new String[originalValues.length + newValues.length ];
53        System.arraycopy(originalValues, 0, result, 0, originalValues.length);
54        System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
55        return result;
56    }
57}
58