Example usage for android.database.sqlite SQLiteDatabase delete

List of usage examples for android.database.sqlite SQLiteDatabase delete

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase delete.

Prototype

public int delete(String table, String whereClause, String[] whereArgs) 

Source Link

Document

Convenience method for deleting rows in the database.

Usage

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

public void deleteOldTransactions(Account account, long date) {
    SQLiteDatabase db = db();
    long dayEnd = DateUtils.atDayEnd(date);
    db.delete("transactions", "from_account_id=? and datetime<=? and is_template=0",
            new String[] { String.valueOf(account.id), String.valueOf(dayEnd) });
    db.delete("running_balance", "account_id=? and datetime<=?",
            new String[] { String.valueOf(account.id), String.valueOf(dayEnd) });
}

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

private void deleteSplitsForParentTransaction(long parentId) {
    List<Transaction> splits = getSplitsForTransaction(parentId);
    SQLiteDatabase db = db();
    for (Transaction split : splits) {
        if (split.isTransfer()) {
            revertToAccountBalance(split);
        }/*from   www .  jav a  2  s. c om*/
        db.delete(TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.TRANSACTION_ID + "=?",
                new String[] { String.valueOf(split.id) });
        writeDeleteLog(TRANSACTION_TABLE, split.remoteKey);
    }

    db.delete(TRANSACTION_TABLE, TransactionColumns.parent_id + "=?",
            new String[] { String.valueOf(parentId) });

}

From source file:com.odoo.orm.OModel.java

/**
 * Delete.//ww w  .java  2 s .co m
 * 
 * @param where
 *            the where
 * @param whereArgs
 *            the where args
 * @param removeFromLocal
 *            the remove from local
 * @return true, if successful
 */
public boolean delete(String where, Object[] whereArgs, boolean removeFromLocal) {
    Boolean deleted = false;
    if (removeFromLocal) {
        SQLiteDatabase db = getWritableDatabase();
        if (db.delete(getTableName(), getWhereClause(where), getWhereArgs(where, whereArgs)) > 0) {
            deleted = true;
        }
        db.close();
    } else {
        // Setting is_active to false.
        OValues values = new OValues();
        values.put("is_dirty", "true");
        values.put("is_active", "false");
        if (update(values, where, whereArgs) > 0)
            deleted = true;
    }
    return deleted;
}

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

private void breakSplitTransactions(Account account, long date) {
    SQLiteDatabase db = db();
    long dayEnd = DateUtils.atDayEnd(date);
    db.execSQL(BREAK_SPLIT_TRANSACTIONS_1, new Object[] { account.id, dayEnd });
    db.execSQL(BREAK_SPLIT_TRANSACTIONS_2, new Object[] { account.id, dayEnd });
    db.delete(
            TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.TRANSACTION_ID + " in (SELECT _id from "
                    + TRANSACTION_TABLE + " where " + TransactionColumns.datetime + "<=?)",
            new String[] { String.valueOf(dayEnd) });
}

From source file:com.openatk.planting.MainActivity.java

@Override
public void SyncControllerDeleteJob(Integer localId) {
    //Check if job exists, if so redraw status
    Job localJob = this.FindJobById(localId);
    if (localJob != null) {
        SQLiteDatabase database = dbHelper.getWritableDatabase();
        database.delete(TableJobs.TABLE_NAME, TableJobs.COL_ID + " = " + Integer.toString(localId), null);
        dbHelper.close();/*from  ww w .  j  a  v  a 2s  . c om*/

        Field localField = this.FindFieldByName(localJob.getFieldName());
        if (localField != null) {
            MyPolygon polygon = null;
            for (int i = 0; i < FieldsOnMap.size(); i++) {
                if (FieldsOnMap.get(i).getId() == localField.getId()) {
                    polygon = FieldsOnMap.get(i).getPolygon();
                }
            }

            if (polygon != null) {
                //Redraw polygon color
                polygon.setFillColor(Field.FILL_COLOR_NOT_PLANNED);
            }
        }
    }
    if (this.fragmentListView != null)
        this.fragmentListView.getData();
}

From source file:com.openatk.planting.MainActivity.java

@Override
public void SyncControllerDeleteField(Integer localId) {
    //Check if field still exists, if so redraw boundary
    Field localField = this.FindFieldById(localId);
    if (localField != null) {
        SQLiteDatabase database = dbHelper.getWritableDatabase();
        database.delete(TableFields.TABLE_NAME, TableFields.COL_ID + " = " + Integer.toString(localId), null);
        dbHelper.close();/*  w ww  . j ava  2s .c  om*/

        MyPolygon polygon = null;
        for (int i = 0; i < FieldsOnMap.size(); i++) {
            if (FieldsOnMap.get(i).getId() == localField.getId()) {
                polygon = FieldsOnMap.get(i).getPolygon();
                FieldsOnMap.remove(i);
            }
        }
        if (polygon != null) {
            //Remove polygon
            polygon.remove();
        }

        if (this.currentField != null && this.currentField.getId() == localField.getId()) {
            if (editIsShowing == 1)
                hideEdit(true);
            if (addIsShowing == 1)
                hideAdd(true);
            this.currentField = null;
            //Remove polygon
            if (this.currentPolygon != null) {
                this.currentPolygon.delete();
                this.currentPolygon = null;
            }
        }
        if (this.fragmentListView != null)
            this.fragmentListView.getData();
    }
}

From source file:com.odoo.core.orm.OModel.java

public void storeManyToManyRecord(String column_name, int row_id, List<Integer> relationIds, Command command)
        throws InvalidObjectException {
    OColumn column = getColumn(column_name);
    if (column != null) {
        OModel rel_model = createInstance(column.getType());
        String table = getTableName() + "_" + rel_model.getTableName() + "_rel";
        String base_column = getTableName() + "_id";
        String rel_column = rel_model.getTableName() + "_id";

        SQLiteDatabase db = getWritableDatabase();
        try {//from  w w w. j av  a 2  s  . c  om
            switch (command) {
            case Add:
                if (relationIds.size() > 0) {
                    for (int id : relationIds) {
                        ContentValues values = new ContentValues();
                        values.put(base_column, row_id);
                        values.put(rel_column, id);
                        values.put("_write_date", ODateUtils.getDate());
                        db.insert(table, null, values);
                    }
                }
                break;
            case Update:
                break;
            case Delete:
                // Deleting records to relation model
                if (relationIds.size() > 0) {
                    for (int id : relationIds) {
                        db.delete(table, base_column + " = ? AND  " + rel_column + " = ?",
                                new String[] { row_id + "", id + "" });
                    }
                }
                break;
            case Replace:
                // Removing old entries
                db.delete(table, base_column + " = ?", new String[] { row_id + "" });
                // Creating new entries
                storeManyToManyRecord(column_name, row_id, relationIds, Command.Add);
                break;
            }
        } finally {
            db.close();
            rel_model.close();
        }
    } else {
        throw new InvalidObjectException(
                "Column [" + column_name + "] not found in " + getModelName() + " model.");

    }
}

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long l) {

    Log.i("item long click2", "click2");
    ////from   w w  w.  j a  v  a 2 s. c o m
    //        Notification newnote=(Notification)parent.getItemAtPosition(position);
    //        String newstring=newnote.noti;
    //
    //        SQLiteDatabase db=helper.getWritableDatabase();
    //        ContentValues cv = new ContentValues();
    //        cv.put(NotificationSquliteOpenHelper.NOTIFICATION, newstring);
    //
    //        db.delete(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, NotificationSquliteOpenHelper.NOTIFICATION+"= '"+newstring+"'", null);
    //
    //
    //        data2.remove(position);
    //        adapter2.notifyDataSetChanged();

    // _selectedItem = (String)lv.getItemAtPosition(position);

    Notification newnote = (Notification) parent.getItemAtPosition(position);
    newstring = newnote.noti;

    final SQLiteDatabase db = helper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(NotificationSquliteOpenHelper.NOTIFICATION, newstring);

    // db.delete(NotificationSquliteOpenHelper.NOTIFICATION_TABLE, NotificationSquliteOpenHelper.NOTIFICATION+"= '"+newstring+"'", null);

    //  data2.remove(position);
    //   adapter2.notifyDataSetChanged();

    pos = position;
    //  par=parent;
    getActivity().openContextMenu(lv);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

    //alertDialogBuilder.setView(R.layout.sig_layout);

    alertDialogBuilder.setTitle("Delete this post ?");

    // alertDialogBuilder.setMessage("helwodosfoasdoifasdofudasofudso");

    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                //Yes button clicked
                Log.i("button", "postitive button");

                db.delete(NotificationSquliteOpenHelper.NOTIFICATION_TABLE,
                        NotificationSquliteOpenHelper.NOTIFICATION + "= '" + newstring + "'", null);

                data2.remove(pos);
                adapter2.notifyDataSetChanged();

                reloadfragment();
                reloadfragment();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                //No button clicked
                break;
            }
        }
    };

    //  ImageView iv=null;
    //  iv.setImageResource(R.drawable.example);

    // alertDialogBuilder.setCustomTitle(iv);
    alertDialogBuilder.setNegativeButton("No", dialogClickListener);
    alertDialogBuilder.setPositiveButton("Yes", dialogClickListener);

    // alertDialogBuilder.setPositiveButton("bUtton 1", );

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();

    return true;
}

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

public int deleteAccount(long id) {
    SQLiteDatabase db = db();
    db.beginTransaction();/*  w w w  . j  av a2s .c  o m*/
    try {
        String[] sid = new String[] { String.valueOf(id) };
        Account a = load(Account.class, id);
        writeDeleteLog(TRANSACTION_TABLE, a.remoteKey);
        db.execSQL(UPDATE_ORPHAN_TRANSACTIONS_1, sid);
        db.execSQL(UPDATE_ORPHAN_TRANSACTIONS_2, sid);
        db.delete(TRANSACTION_ATTRIBUTE_TABLE,
                TransactionAttributeColumns.TRANSACTION_ID + " in (SELECT _id from " + TRANSACTION_TABLE
                        + " where " + TransactionColumns.from_account_id + "=?)",
                sid);
        db.delete(TRANSACTION_TABLE, TransactionColumns.from_account_id + "=?", sid);
        int count = db.delete(ACCOUNT_TABLE, "_id=?", sid);
        db.setTransactionSuccessful();
        return count;
    } finally {
        db.endTransaction();
    }

}

From source file:net.smart_json_database.JSONDatabase.java

public int update(JSONEntity entity) {
    int returnValue = -1;
    if (entity.getUid() == -1) {
        return returnValue;
    }//from  w w w .  jav  a  2  s  .  c  om

    SQLiteDatabase db = dbHelper.getWritableDatabase();

    try {
        db.beginTransaction();
        entity.setUpdateDate(new Date());
        ContentValues values = new ContentValues();
        values.put("data", entity.getData().toString());
        values.put("updateDate", Util.DateToString(entity.getUpdateDate()));
        values.put("type", entity.getType());
        String[] params = new String[] { "" + entity.getUid() };
        db.update(TABLE_JSON_DATA, values, "json_uid = ?", params);
        for (String name : entity.getTags().getToAdd()) {
            int tagid = -1;
            if (!tags.containsKey(name)) {
                tagid = insertTag(name, db);
            } else {
                tagid = tags.get(name);
            }
            if (relateTagWithJsonEntity(tagid, entity.getUid(), db) == -1) {
                throw new Exception("could not relate");
            }

        }
        for (String name : entity.getTags().getToRemove()) {
            int tagid = -1;
            if (!tags.containsKey(name)) {
                continue;
            } else {
                tagid = tags.get(name);
            }

            db.delete(TABLE_REL_TAG_JSON_DATA, "to_id = ?", new String[] { "" + tagid });
        }

        for (HasMany hasMany : entity.getHasManyRelations().values()) {
            for (Integer id : hasMany.getToRemove()) {
                deleteRelation(hasMany.getName(), entity.getUid(), id, db);
            }

            for (Integer id : hasMany.getToAdd()) {
                insertRelation(hasMany.getName(), entity.getUid(), id, db);
            }
        }

        for (BelongsTo belongsTo : entity.getBelongsToRelations().values()) {
            for (Integer id : belongsTo.getToRemove()) {
                deleteRelation(belongsTo.getName(), id, entity.getUid(), db);
            }

            for (Integer id : belongsTo.getToAdd()) {
                insertRelation(belongsTo.getName(), id, entity.getUid(), db);
            }
        }

        db.setTransactionSuccessful();
        returnValue = entity.getUid();
        notifyListenersOnEntityChange(returnValue, IDatabaseChangeListener.CHANGETYPE_UPDATE);
    } catch (Exception e) {
        returnValue = -1;
    } finally {
        db.endTransaction();
        db.close();
    }
    return returnValue;

}