Java Code Examples for android.database.sqlite.SQLiteStatement#executeUpdateDelete()

The following examples show how to use android.database.sqlite.SQLiteStatement#executeUpdateDelete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLiteSchema.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private void removeMutationBatch(String uid, int batchId) {
  SQLiteStatement mutationDeleter =
      db.compileStatement("DELETE FROM mutations WHERE uid = ? AND batch_id = ?");
  mutationDeleter.bindString(1, uid);
  mutationDeleter.bindLong(2, batchId);
  int deleted = mutationDeleter.executeUpdateDelete();
  hardAssert(deleted != 0, "Mutatiohn batch (%s, %d) did not exist", uid, batchId);

  // Delete all index entries for this batch
  db.execSQL(
      "DELETE FROM document_mutations WHERE uid = ? AND batch_id = ?",
      new Object[] {uid, batchId});
}
 
Example 2
Source File: Db.java    From medic-gateway with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("PMD.UnusedPrivateMethod") // it's used - PMD bug?
private static int rawUpdateOrDelete(SQLiteDatabase db, String statement, String[] cols, String... args) {
	statement = String.format(statement, (String[]) cols);
	SQLiteStatement s = db.compileStatement(statement);
	for(int i=args.length; i>0; --i)
		s.bindString(i, args[i-1]);
	return s.executeUpdateDelete();
}
 
Example 3
Source File: SqliteDatabaseDriver.java    From weex with Apache License 2.0 5 votes vote down vote up
@TargetApi(DatabaseConstants.MIN_API_LEVEL)
private <T> T executeUpdateDelete(
    SQLiteDatabase database,
    String query,
    ExecuteResultHandler<T> handler) {
  SQLiteStatement statement = database.compileStatement(query);
  int count = statement.executeUpdateDelete();
  return handler.handleUpdateDelete(count);
}
 
Example 4
Source File: Storage.java    From beacons-android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("ObsoleteSdkInt")
private void executeSafeUpdateOrDelete(SQLiteStatement statement) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        statement.executeUpdateDelete();
    }
    else {
        statement.execute();
    }
}
 
Example 5
Source File: SqliteDatabaseDriver.java    From stetho with MIT License 5 votes vote down vote up
@TargetApi(DatabaseConstants.MIN_API_LEVEL)
private <T> T executeUpdateDelete(
    SQLiteDatabase database,
    String query,
    ExecuteResultHandler<T> handler) {
  SQLiteStatement statement = database.compileStatement(query);
  int count = statement.executeUpdateDelete();
  return handler.handleUpdateDelete(count);
}
 
Example 6
Source File: SQLiteDatabaseAdapter.java    From squidb with Apache License 2.0 5 votes vote down vote up
@Override
public int executeUpdateDelete(String sql, Object[] bindArgs) {
    SQLiteStatement statement = null;
    try {
        statement = db.compileStatement(sql);
        SquidCursorFactory.bindArgumentsToProgram(statement, bindArgs);
        return statement.executeUpdateDelete();
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}
 
Example 7
Source File: DatabaseDriver.java    From pandora with Apache License 2.0 4 votes vote down vote up
private void executeUpdateDelete(SQLiteDatabase database, String query, DatabaseResult result) {
    SQLiteStatement statement = database.compileStatement(query);
    int count = statement.executeUpdateDelete();
    result.transformUpdateDelete(count);
}
 
Example 8
Source File: SQLitePersistence.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the given prepared non-query statement using the supplied bind arguments.
 *
 * @return The number of rows affected.
 */
int execute(SQLiteStatement statement, Object... args) {
  statement.clearBindings();
  bind(statement, args);
  return statement.executeUpdateDelete();
}
 
Example 9
Source File: LauncherProvider.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
 */
@Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
    db.beginTransaction();
    Cursor c = null;
    SQLiteStatement updateStmt = null;

    try {
        // Only consider the primary user as other users can't have a shortcut.
        long userSerial = getDefaultUserSerial();
        c = db.query(Favorites.TABLE_NAME, new String[] {
                Favorites._ID,
                Favorites.INTENT,
            }, "itemType=" + Favorites.ITEM_TYPE_SHORTCUT + " AND profileId=" + userSerial,
            null, null, null, null);

        updateStmt = db.compileStatement("UPDATE favorites SET itemType="
                + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?");

        final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
        final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);

        while (c.moveToNext()) {
            String intentDescription = c.getString(intentIndex);
            Intent intent;
            try {
                intent = Intent.parseUri(intentDescription, 0);
            } catch (URISyntaxException e) {
                e.printStackTrace();
                continue;
            }

            if (!Utilities.isLauncherAppTarget(intent)) {
                continue;
            }

            long id = c.getLong(idIndex);
            updateStmt.bindLong(1, id);
            updateStmt.executeUpdateDelete();
        }
        db.setTransactionSuccessful();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        db.endTransaction();
        if (c != null) {
            c.close();
        }
        if (updateStmt != null) {
            updateStmt.close();
        }
    }
}
 
Example 10
Source File: LauncherProvider.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
 */
@Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
    db.beginTransaction();
    Cursor c = null;
    SQLiteStatement updateStmt = null;

    try {
        // Only consider the primary user as other users can't have a shortcut.
        long userSerial = UserManagerCompat.getInstance(mContext)
                .getSerialNumberForUser(UserHandleCompat.myUserHandle());
        c = db.query(TABLE_FAVORITES, new String[] {
                Favorites._ID,
                Favorites.INTENT,
            }, "itemType=" + Favorites.ITEM_TYPE_SHORTCUT + " AND profileId=" + userSerial,
            null, null, null, null);

        updateStmt = db.compileStatement("UPDATE favorites SET itemType="
                + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?");

        final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
        final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);

        while (c.moveToNext()) {
            String intentDescription = c.getString(intentIndex);
            Intent intent;
            try {
                intent = Intent.parseUri(intentDescription, 0);
            } catch (URISyntaxException e) {
                Log.e(TAG, "Unable to parse intent", e);
                continue;
            }

            if (!Utilities.isLauncherAppTarget(intent)) {
                continue;
            }

            long id = c.getLong(idIndex);
            updateStmt.bindLong(1, id);
            updateStmt.executeUpdateDelete();
        }
        db.setTransactionSuccessful();
    } catch (SQLException ex) {
        Log.w(TAG, "Error deduping shortcuts", ex);
    } finally {
        db.endTransaction();
        if (c != null) {
            c.close();
        }
        if (updateStmt != null) {
            updateStmt.close();
        }
    }
}
 
Example 11
Source File: Index.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public void removeNativeMap(int x, int y, @Nullable ProgressListener progressListener) {
    if (mMaps[x][y] == null)
        return;
    if (mMaps[x][y].created == 0)
        return;

    boolean hillshades = mMaps[x][y].hillshadeVersion != 0L;

    logger.error("Removing map: {} {}", x, y);
    if (progressListener != null)
        progressListener.onProgressStarted(100);
    try {
        // remove tiles
        SQLiteStatement statement = mMapsDatabase.compileStatement(SQL_REMOVE_TILES);
        SQLiteStatement hillshadeStatement = mHillshadeDatabase.compileStatement(SQL_REMOVE_TILES);
        for (int z = 8; z < 15; z++) {
            int s = z - 7;
            int cmin = x << s;
            int cmax = ((x + 1) << s) - 1;
            int rmin = y << s;
            int rmax = ((y + 1) << s) - 1;
            statement.clearBindings();
            statement.bindLong(1, z);
            statement.bindLong(2, cmin);
            statement.bindLong(3, cmax);
            statement.bindLong(4, rmin);
            statement.bindLong(5, rmax);
            statement.executeUpdateDelete();
            if (hillshades && z < 13) {
                hillshadeStatement.clearBindings();
                hillshadeStatement.bindLong(1, z);
                hillshadeStatement.bindLong(2, cmin);
                hillshadeStatement.bindLong(3, cmax);
                hillshadeStatement.bindLong(4, rmin);
                hillshadeStatement.bindLong(5, rmax);
                hillshadeStatement.executeUpdateDelete();
            }
        }
        if (progressListener != null)
            progressListener.onProgressChanged(10);
        logger.error("  removed tiles");
        // remove features
        statement = mMapsDatabase.compileStatement(SQL_REMOVE_FEATURES);
        statement.bindLong(1, x);
        statement.bindLong(2, y);
        statement.executeUpdateDelete();
        if (progressListener != null)
            progressListener.onProgressChanged(20);
        logger.error("  removed features");
        statement = mMapsDatabase.compileStatement(SQL_REMOVE_FEATURE_NAMES);
        statement.executeUpdateDelete();
        if (progressListener != null)
            progressListener.onProgressChanged(40);
        logger.error("  removed feature names");
        // remove names
        if (MapTrekDatabaseHelper.hasFullTextIndex(mMapsDatabase)) {
            ArrayList<Long> ids = new ArrayList<>();
            Cursor cursor = mMapsDatabase.rawQuery(SQL_SELECT_UNUSED_NAMES, null);
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                ids.add(cursor.getLong(0));
                cursor.moveToNext();
            }
            cursor.close();
            if (ids.size() > 0) {
                StringBuilder sql = new StringBuilder();
                sql.append(SQL_REMOVE_NAMES_FTS);
                String sep = "";
                for (Long id : ids) {
                    sql.append(sep);
                    sql.append(id);
                    sep = ",";
                }
                sql.append(")");
                statement = mMapsDatabase.compileStatement(sql.toString());
                statement.executeUpdateDelete();
            }
            if (progressListener != null)
                progressListener.onProgressChanged(60);
            logger.error("  removed names fts");
        }
        statement = mMapsDatabase.compileStatement(SQL_REMOVE_NAMES);
        statement.executeUpdateDelete();
        if (progressListener != null)
            progressListener.onProgressChanged(100);
        logger.error("  removed names");
        setDownloaded(x, y, (short) 0);
        setHillshadeDownloaded(x, y, (byte) 0);
        if (progressListener != null)
            progressListener.onProgressFinished();
    } catch (Exception e) {
        logger.error("Query error", e);
    }
}
 
Example 12
Source File: MeasurementManager.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
public void updateRecordUserInput(int recordId, String description, Short pleasantness,
                                  String[] tags, Uri photo_uri, String noisePartyTag) {

    SQLiteDatabase database = storage.getWritableDatabase();
    try {
        database.beginTransaction();
        SQLiteStatement recordStatement = database.compileStatement(
                "UPDATE " + Storage.Record.TABLE_NAME +
                        " SET "+ Storage.Record.COLUMN_DESCRIPTION + " = ?, " +
                        Storage.Record.COLUMN_PLEASANTNESS + " = ?, " +
                        Storage.Record.COLUMN_PHOTO_URI + " = ?, " +
                        Storage.Record.COLUMN_NOISEPARTY_TAG + " = ?" +
                        " WHERE " + Storage.Record.COLUMN_ID + " = ?");
        recordStatement.clearBindings();
        recordStatement.bindString(1, description);
        if(pleasantness != null) {
            recordStatement.bindLong(2, pleasantness);
        } else {
            recordStatement.bindNull(2);
        }
        recordStatement.bindString(3, photo_uri != null ? photo_uri.toString() : "");
        recordStatement.bindString(4, noisePartyTag);
        recordStatement.bindLong(5, recordId);
        recordStatement.executeUpdateDelete();
        database.delete(Storage.RecordTag.TABLE_NAME,
                Storage.RecordTag.COLUMN_RECORD_ID + " = ?" +
                        "", new String[] {String.valueOf(recordId)});
        SQLiteStatement tagStatement = database.compileStatement(
                "INSERT INTO " + Storage.RecordTag.TABLE_NAME +
                        "(" + Storage.RecordTag.COLUMN_RECORD_ID + ", " +
                        Storage.RecordTag.COLUMN_TAG_SYSTEM_NAME + ") " +
                        " VALUES (?, ?)");
        for(String sysTag : tags) {
            tagStatement.clearBindings();
            tagStatement.bindLong(1, recordId);
            tagStatement.bindString(2, sysTag);
            tagStatement.executeInsert();
        }
        database.setTransactionSuccessful();
        database.endTransaction();
    } finally {
        database.close();
    }
}