1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.google.android.mms.util; 19 20 import android.compat.annotation.UnsupportedAppUsage; 21 import android.content.ContentResolver; 22 import android.content.ContentValues; 23 import android.content.Context; 24 import android.database.Cursor; 25 import android.database.sqlite.SQLiteException; 26 import android.net.Uri; 27 import android.util.Log; 28 29 public final class SqliteWrapper { 30 private static final String TAG = "SqliteWrapper"; 31 SqliteWrapper()32 private SqliteWrapper() { 33 // Forbidden being instantiated. 34 } 35 36 @UnsupportedAppUsage query(Context context, ContentResolver resolver, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)37 public static Cursor query(Context context, ContentResolver resolver, Uri uri, 38 String[] projection, String selection, String[] selectionArgs, String sortOrder) { 39 try { 40 return resolver.query(uri, projection, selection, selectionArgs, sortOrder); 41 } catch (SQLiteException e) { 42 Log.e(TAG, "Catch a SQLiteException when query: ", e); 43 return null; 44 } 45 } 46 47 @UnsupportedAppUsage update(Context context, ContentResolver resolver, Uri uri, ContentValues values, String where, String[] selectionArgs)48 public static int update(Context context, ContentResolver resolver, Uri uri, 49 ContentValues values, String where, String[] selectionArgs) { 50 try { 51 return resolver.update(uri, values, where, selectionArgs); 52 } catch (SQLiteException e) { 53 Log.e(TAG, "Catch a SQLiteException when update: ", e); 54 return -1; 55 } 56 } 57 58 @UnsupportedAppUsage delete(Context context, ContentResolver resolver, Uri uri, String where, String[] selectionArgs)59 public static int delete(Context context, ContentResolver resolver, Uri uri, 60 String where, String[] selectionArgs) { 61 try { 62 return resolver.delete(uri, where, selectionArgs); 63 } catch (SQLiteException e) { 64 Log.e(TAG, "Catch a SQLiteException when delete: ", e); 65 return -1; 66 } 67 } 68 69 @UnsupportedAppUsage insert(Context context, ContentResolver resolver, Uri uri, ContentValues values)70 public static Uri insert(Context context, ContentResolver resolver, 71 Uri uri, ContentValues values) { 72 try { 73 return resolver.insert(uri, values); 74 } catch (SQLiteException e) { 75 Log.e(TAG, "Catch a SQLiteException when insert: ", e); 76 return null; 77 } 78 } 79 } 80