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

The following are Jave code examples for showing how to use executeUpdateDelete() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: DbManagerImpl.java   Source Code and License Vote up 6 votes
@Override
public int executeUpdateDelete(SqlInfo sqlInfo) throws DbException {
    SQLiteStatement statement = null;
    try {
        statement = sqlInfo.buildStatement(database);
        return statement.executeUpdateDelete();
    } catch (Throwable e) {
        throw new DbException(e);
    } finally {
        if (statement != null) {
            try {
                statement.releaseReference();
            } catch (Throwable ex) {
                LogUtil.e(ex.getMessage(), ex);
            }
        }
    }
}
 
Example 2
Project: GitHub   File: DbManagerImpl.java   Source Code and License Vote up 6 votes
@Override
public int executeUpdateDelete(String sql) throws DbException {
    SQLiteStatement statement = null;
    try {
        statement = database.compileStatement(sql);
        return statement.executeUpdateDelete();
    } catch (Throwable e) {
        throw new DbException(e);
    } finally {
        if (statement != null) {
            try {
                statement.releaseReference();
            } catch (Throwable ex) {
                LogUtil.e(ex.getMessage(), ex);
            }
        }
    }
}
 
Example 3
Project: OftenPorter   File: SqliteHandle.java   Source Code and License Vote up 6 votes
@Override
public int del(Condition query) throws DBException
{
    SQLiteStatement statement = null;
    try
    {
        SqlUtil.WhereSQL whereSQL = SqlUtil.toDelete(tableName, checkCondition(query), true);

        statement = db.compileStatement(whereSQL.sql);
        Object[] args = whereSQL.args;
        for (int i = 0; i < args.length; i++)
        {
            bind(i + 1, args[i], statement);
        }

        return statement.executeUpdateDelete();
    } catch (Exception e)
    {
        throw new DBException(e);
    } finally
    {
        close(statement);
    }

}
 
Example 4
Project: healthvault-java-sdk   File: ViewProvider.java   Source Code and License Vote up 6 votes
public int update(Uri uri, ContentValues values, String selection,
		String[] selectionArgs) {
	int updateCount = 0;

	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

	List<String> segments = uri.getPathSegments();
	String recordId = segments.get(1);
	String name = segments.get(3);

	String updateView = "update views set query = ?, date_synced = ? where record_id = ? and name = ?";
       SQLiteStatement updateViewStmt = sqlDb.compileStatement(updateView);

	updateViewStmt.bindString(1, values.getAsString("query"));
	updateViewStmt.bindString(2, values.getAsString("date_synced"));
	updateViewStmt.bindString(3, recordId);
	updateViewStmt.bindString(4, name);
	
	updateCount = updateViewStmt.executeUpdateDelete();

	if (updateCount > 0) { 
	      getContext().getContentResolver().notifyChange(uri, null); 
	} 

	return updateCount; 
}
 
Example 5
Project: LaunchEnr   File: LauncherProvider.java   Source Code and License Vote up 5 votes
/**
 * 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 6
Project: OftenPorter   File: SqliteHandle.java   Source Code and License Vote up 5 votes
@Override
public int update(Condition query, NameValues nameValues) throws DBException
{
    if (nameValues == null || nameValues.size() == 0)
    {
        return 0;
    }
    int n = 0;
    SQLiteStatement statement = null;
    try
    {
        SqlUtil.WhereSQL whereSql = SqlUtil
                .toSetValues(tableName, nameValues.names(), checkCondition(query), false);
        statement = db.compileStatement(whereSql.sql);
        for (int i = 0; i < nameValues.size(); i++)
        {
            bind(i + 1, nameValues.value(i), statement);
        }
        Object[] args = whereSql.args;
        for (int i = 0, k = nameValues.size() + 1; i < args.length; i++, k++)
        {
            bind(k, args[i], statement);
        }
        n = statement.executeUpdateDelete();

    } catch (Exception e)
    {
        throw new DBException(e);
    } finally
    {
        close(statement);
    }

    return n;
}
 
Example 7
Project: editor-sql   File: SQLHelper.java   Source Code and License Vote up 5 votes
public int execSQLStr(String sqlStr) {
    if (!isDBOk()) {
        return Constant.FAIL;
    }

    SQLiteStatement statement = _db.compileStatement(sqlStr);

    try {
        return statement.executeUpdateDelete();
    } finally {
        statement.close();
    }
}
 
Example 8
Project: nifi-android-s2s   File: SQLiteDataPacketQueue.java   Source Code and License Vote up 5 votes
private static int executeDeleteQuery(SQLiteStatement sqLiteStatement, long[] ids, int numIds) {
    sqLiteStatement.clearBindings();
    for (int i = 0; i < numIds; i++) {
        sqLiteStatement.bindLong(i + 1, ids[i]);
    }
    return sqLiteStatement.executeUpdateDelete();
}
 
Example 9
Project: sealtalk-android-master   File: RongDatabaseDriver.java   Source Code and License Vote up 5 votes
@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 10
Project: Cash   File: tblCompras.java   Source Code and License Vote up 5 votes
public int update() {

        try {
            SQLiteStatement sStatement = Funcoes.mDataBase.compileStatement("UPDATE compra_itens SET" +
                    " dt_compra = " + String.valueOf(getDtCompra()) +
                    ", dt_compra_inv = " + String.valueOf(getDtCompraInv()) +
                    " WHERE id_compra = " + String.valueOf(getIdCompra()));

            sStatement.executeUpdateDelete();

            return Funcoes.mDataBase.update(mTable, getValues(), "id_compra = ?", new String[]{String.valueOf(getIdCompra())});
        } catch (Exception e) {
            return -1;
        }
    }
 
Example 11
Project: Cash   File: tblVendas.java   Source Code and License Vote up 5 votes
public int update() {

        try {
            SQLiteStatement sStatement = Funcoes.mDataBase.compileStatement("UPDATE venda_itens SET" +
                    " dt_venda = " + String.valueOf(getDtVenda()) +
                    ", dt_venda_inv = " + String.valueOf(getDtVendaInv()) +
                    " WHERE id_venda = " + String.valueOf(getIdVenda()));

            sStatement.executeUpdateDelete();

            return Funcoes.mDataBase.update(mTable, getValues(), "id_venda = ?", new String[]{String.valueOf(getIdVenda())});
        } catch (Exception e) {
            return -1;
        }
    }
 
Example 12
Project: FlickLauncher   File: LauncherProvider.java   Source Code and License Vote up 4 votes
/**
 * 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) {
                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 13
Project: SimpleUILauncher   File: LauncherProvider.java   Source Code and License Vote up 4 votes
/**
 * 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) {
                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 14
Project: healthvault-java-sdk   File: ViewThingsProvider.java   Source Code and License Vote up 4 votes
public int delete(Uri uri, String selection, String[] selectionArgs) {
	// TODO: Delete things not shared with other views
	
	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

	List<String> segments = uri.getPathSegments();

	String recordId = segments.get(1);
	String name = segments.get(3);

	String deleteView = "delete from view_things where record_id = ? and view_name = ?";
       SQLiteStatement deleteViewStmt = sqlDb.compileStatement(deleteView);

	deleteViewStmt.bindString(1, recordId);
	deleteViewStmt.bindString(2, name);
	
	int rc = deleteViewStmt.executeUpdateDelete();
	
	getContext()
               .getContentResolver()
               .notifyChange(uri, null);

	return rc;
}
 
Example 15
Project: healthvault-java-sdk   File: ThingProvider.java   Source Code and License Vote up 4 votes
public int delete(Uri uri, String selection, String[] selectionArgs) {
	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

	List<String> segments = uri.getPathSegments();
	String thingId = segments.get(1);

	String deleteThing = "delete from things where thing_id = ?";
       SQLiteStatement deleteThingStmt = sqlDb.compileStatement(deleteThing);

	deleteThingStmt.bindString(1, thingId);
	
	int rc = deleteThingStmt.executeUpdateDelete();
	
	getContext()
               .getContentResolver()
               .notifyChange(uri, null);
    
	return rc;
}
 
Example 16
Project: healthvault-java-sdk   File: ViewProvider.java   Source Code and License Vote up 4 votes
public int delete(Uri uri, String selection, String[] selectionArgs) {
	// TODO: Delete things not shared with other views
	
	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

	List<String> segments = uri.getPathSegments();

	String recordId = segments.get(1);
	String name = segments.get(3);

	String deleteView = "delete from views where record_id = ? and name = ?";
       SQLiteStatement deleteViewStmt = sqlDb.compileStatement(deleteView);

	deleteViewStmt.bindString(1, recordId);
	deleteViewStmt.bindString(2, name);
	
	int rc = deleteViewStmt.executeUpdateDelete();
	
	getContext()
               .getContentResolver()
               .notifyChange(uri, null);

	return rc;
}