diff options
| author | 2017-01-18 18:12:53 +0000 | |
|---|---|---|
| committer | 2017-01-19 16:19:28 +0000 | |
| commit | 794cf190aa38dffdad9e82fc86dbd94940b175b1 (patch) | |
| tree | cb8247ae67ead35b99206e4c16213ad70926f114 | |
| parent | 7a1f1d8a8579278048c044b7aca5d0d58ece57e4 (diff) | |
Also parse "1" as true for ContentValues#getAsBoolean
SQLite's internal representation for booleans is an integer with a value
of 0 or 1, so without this check, boolean values obtained via
DatabaseUtils#cursorRowToContentValues will always return false.
Bug: 34365384
Test: demo app, cts
Change-Id: I6c0829c992252ca5ee16bd5eac48668507fd4089
| -rw-r--r-- | core/java/android/content/ContentValues.java | 6 | ||||
| -rw-r--r-- | core/java/android/database/DatabaseUtils.java | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/core/java/android/content/ContentValues.java b/core/java/android/content/ContentValues.java index 7ed827c00e65..3a87cb3e7a29 100644 --- a/core/java/android/content/ContentValues.java +++ b/core/java/android/content/ContentValues.java @@ -414,7 +414,11 @@ public final class ContentValues implements Parcelable { return (Boolean) value; } catch (ClassCastException e) { if (value instanceof CharSequence) { - return Boolean.valueOf(value.toString()); + // Note that we also check against 1 here because SQLite's internal representation + // for booleans is an integer with a value of 0 or 1. Without this check, boolean + // values obtained via DatabaseUtils#cursorRowToContentValues will always return + // false. + return Boolean.valueOf(value.toString()) || "1".equals(value); } else if (value instanceof Number) { return ((Number) value).intValue() != 0; } else { diff --git a/core/java/android/database/DatabaseUtils.java b/core/java/android/database/DatabaseUtils.java index 227066ddc571..8cd3d7b5bc68 100644 --- a/core/java/android/database/DatabaseUtils.java +++ b/core/java/android/database/DatabaseUtils.java @@ -728,13 +728,10 @@ public class DatabaseUtils { * @param values the {@link ContentValues} to put the row into. */ public static void cursorRowToContentValues(Cursor cursor, ContentValues values) { - AbstractWindowedCursor awc = - (cursor instanceof AbstractWindowedCursor) ? (AbstractWindowedCursor) cursor : null; - String[] columns = cursor.getColumnNames(); int length = columns.length; for (int i = 0; i < length; i++) { - if (awc != null && awc.isBlob(i)) { + if (cursor.getType(i) == Cursor.FIELD_TYPE_BLOB) { values.put(columns[i], cursor.getBlob(i)); } else { values.put(columns[i], cursor.getString(i)); |