diff options
Diffstat (limited to 'core/java/android/database/DatabaseUtils.java')
-rw-r--r-- | core/java/android/database/DatabaseUtils.java | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/core/java/android/database/DatabaseUtils.java b/core/java/android/database/DatabaseUtils.java index 10f3806..4ca6601 100644 --- a/core/java/android/database/DatabaseUtils.java +++ b/core/java/android/database/DatabaseUtils.java @@ -20,6 +20,7 @@ import org.apache.commons.codec.binary.Hex; import android.content.ContentValues; import android.content.Context; +import android.content.OperationApplicationException; import android.database.sqlite.SQLiteAbortException; import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; @@ -82,6 +83,8 @@ public class DatabaseUtils { code = 8; } else if (e instanceof SQLiteException) { code = 9; + } else if (e instanceof OperationApplicationException) { + code = 10; } else { reply.writeException(e); Log.e(TAG, "Writing exception to parcel", e); @@ -123,6 +126,18 @@ public class DatabaseUtils { } } + public static void readExceptionWithOperationApplicationExceptionFromParcel( + Parcel reply) throws OperationApplicationException { + int code = reply.readInt(); + if (code == 0) return; + String msg = reply.readString(); + if (code == 10) { + throw new OperationApplicationException(msg); + } else { + DatabaseUtils.readExceptionFromParcel(reply, msg, code); + } + } + private static final void readExceptionFromParcel(Parcel reply, String msg, int code) { switch (code) { case 2: @@ -211,7 +226,7 @@ public class DatabaseUtils { sb.append(sqlString); sb.append('\''); } - + /** * SQL-escape a string. */ @@ -240,7 +255,7 @@ public class DatabaseUtils { appendEscapedSQLString(sql, value.toString()); } } - + /** * Concatenates two SQL WHERE clauses, handling empty or null values. * @hide @@ -252,12 +267,12 @@ public class DatabaseUtils { if (TextUtils.isEmpty(b)) { return a; } - + return "(" + a + ") AND (" + b + ")"; } - + /** - * return the collation key + * return the collation key * @param name * @return the collation key */ @@ -269,7 +284,7 @@ public class DatabaseUtils { return ""; } } - + /** * return the collation key in hex format * @param name @@ -280,7 +295,7 @@ public class DatabaseUtils { char[] keys = Hex.encodeHex(arr); return new String(keys, 0, getKeyLen(arr) * 2); } - + private static int getKeyLen(byte[] arr) { if (arr[arr.length - 1] != 0) { return arr.length; @@ -289,16 +304,16 @@ public class DatabaseUtils { return arr.length-1; } } - + private static byte[] getCollationKeyInBytes(String name) { if (mColl == null) { mColl = Collator.getInstance(); mColl.setStrength(Collator.PRIMARY); } - return mColl.getCollationKey(name).toByteArray(); + return mColl.getCollationKey(name).toByteArray(); } - - private static Collator mColl = null; + + private static Collator mColl = null; /** * Prints the contents of a Cursor to System.out. The position is restored * after printing. @@ -591,10 +606,12 @@ public class DatabaseUtils { public static long queryNumEntries(SQLiteDatabase db, String table) { Cursor cursor = db.query(table, countProjection, null, null, null, null, null); - cursor.moveToFirst(); - long count = cursor.getLong(0); - cursor.deactivate(); - return count; + try { + cursor.moveToFirst(); + return cursor.getLong(0); + } finally { + cursor.close(); + } } /** |