@Override protected SQLiteOpenHelper getDatabaseHelper(Context context) { try { return new MigratingSQLiteOpenHelper(context, getCursorFactory()); } catch (IOException e) { Log.Provider.e(e); throw new IllegalStateException(e.getMessage()); } }
/** * Use {@link #tryUpdateWithConstraint(String, Constraint, ContentValues)} */ @Deprecated protected long tryUpdateWithConstrain(String table, String constrain, ContentValues values) { long rowId = -1; int update = dbHelper.getWritableDatabase().update(table, values, constrain + "=?", new String[]{ values.getAsString(constrain) }); if (Log.Provider.verboseLoggingEnabled()) { Log.Provider.v("Constrain " + constrain + " yield " + update); } if (update > 0) { rowId = getRowIdForUpdate(table, new Constraint(Arrays.asList(constrain)), values); } return rowId; }
public long insert(Uri uri, ContentValues values) { ContentValues insertValues = (values != null) ? new ContentValues(values) : new ContentValues(); final String table = UriUtils.getItemDirID(uri); final Constraint constraint = metaInfo.getFirstConstraint(table, insertValues); appendParentReference(uri, insertValues); long rowId = -1; if (constraint != null) { rowId = tryUpdateWithConstraint(table, constraint, insertValues); } else { if (Log.Provider.warningLoggingEnabled()) { Log.Provider.w("No constrain against URI: " + uri); } } if (rowId <= 0) { rowId = dbHelper.getWritableDatabase().insert(table, null, insertValues); } // According to http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert(java.lang.String,%20java.lang.String,%20android.content.ContentValues) // only -1 indicates an error, and returning 0 is valid and has been seen. if (rowId != -1) { return rowId; } throw new SQLException("Failed to insert row into " + uri); }
protected void logEnd(String[] projection, String selection, String[] selectionArgs, String sortOrder, final ExtendedSQLiteQueryBuilder builder, final String groupBy, final String having, final String limit, Map<String, String> autoproj) { if (Provider.verboseLoggingEnabled()) { Provider.v("table: " + builder.getTables()); if (projection != null) { Provider.v("projection:" + Arrays.toString(projection)); } if (selection != null) { Provider.v("selection: " + selection + " with arguments " + Arrays.toString(selectionArgs)); } Provider.v("extra args: " + groupBy + " ,having: " + having + " ,sort order: " + sortOrder + " ,limit: " + limit); if (autoproj != null) { Provider.v("projectionAutomated: " + autoproj); } Provider.v("==================== end of query ======================="); } }
protected long tryUpdateWithConstraint(String table, Constraint constraint, ContentValues values) { long rowId = -1; String whereClause = getWhereClause(constraint); String[] whereArgs = getWhereArguments(constraint, values); int update = dbHelper.getWritableDatabase().update(table, values, whereClause, whereArgs); if (Log.Provider.verboseLoggingEnabled()) { Log.Provider.v("Constrain " + constraint + " yield " + update); } if (update > 0) { rowId = getRowIdForUpdate(table, constraint, values); } return rowId; }
protected void logAppendWhere(String where) { if (Provider.verboseLoggingEnabled()) { Provider.v("Appending to where clause: " + where); } }
protected void logStart(Uri uri) { if (Provider.verboseLoggingEnabled()) { Provider.v("==================== start of query ======================="); Provider.v("Uri: " + uri.toString()); } }