Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3752432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:14:26+00:00 2026-05-19T09:14:26+00:00

I have a MyDBAdapter class, that can do selects, but I also need to

  • 0

I have a MyDBAdapter class, that can do selects, but I also need to do

DELETE FROM user Where email="given value by variable String"

I don’t know how to do deletes on MyDBAdapter with android, I’m very newbie with this, can someone complete my class adding that function to delete users by email please?

This is my class:

public class MyDbAdapter {

    private static final String TAG = "NotesDbAdapter";
    private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;
    private static final String DATABASE_NAME = "gpslocdb";
    private static final String PERMISSION_TABLE_CREATE = "CREATE TABLE permission ( fk_email1 varchar, fk_email2 varchar, validated tinyint, hour1 time default '08:00:00', hour2 time default '20:00:00', date1 date, date2 date, weekend tinyint default '0', fk_type varchar, PRIMARY KEY  (fk_email1,fk_email2))";
    private static final String USER_TABLE_CREATE = "CREATE TABLE user ( email varchar, password varchar, fullName varchar, mobilePhone varchar, mobileOperatingSystem varchar, PRIMARY KEY  (email))";

    private static final int DATABASE_VERSION = 2;

    private final Context mCtx;

    private static class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("DROP TABLE IF EXISTS user");
            db.execSQL("DROP TABLE IF EXISTS permission");
            db.execSQL(PERMISSION_TABLE_CREATE);
            db.execSQL(USER_TABLE_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            //db.execSQL("DROP TABLE IF EXISTS user");
            //db.execSQL("DROP TABLE IF EXISTS permission");
            //onCreate(db);
        }

        @Override
        public void onOpen(SQLiteDatabase db) {
            super.onOpen(db);
            //onCreate(db);
        }

        public void clearDb(SQLiteDatabase db) {
            db.execSQL("DROP TABLE IF EXISTS user");
            db.execSQL("DROP TABLE IF EXISTS permission");
            onCreate(db);
        }

    }

    /**
     * Constructor - takes the context to allow the database to be
     * opened/created
     *
     * @param ctx the Context within which to work
     */
    public MyDbAdapter(Context ctx) {
        this.mCtx = ctx;
    }

    /**
     * Open the database. If it cannot be opened, try to create a new
     * instance of the database. If it cannot be created, throw an exception to
     * signal the failure
     *
     * @return this (self reference, allowing this to be chained in an
     * initialization call)
     * @throws SQLException if the database could be neither opened or created
     */
    public MyDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        //clearDB();
        mDbHelper.close();
    }

    public long createUser(String email, String password, String fullName, String mobilePhone, String mobileOperatingSystem) {
        ContentValues initialValues = new ContentValues();
        initialValues.put("email", email);
        initialValues.put("password", password);
        initialValues.put("fullName", fullName);
        initialValues.put("mobilePhone", mobilePhone);
        initialValues.put("mobileOperatingSystem", mobileOperatingSystem);
        return mDb.insert("user", null, initialValues);
    }

    public long createPermission(String email1, String email2, String validated, String hour1, String hour2,
                                 String date1, String date2, String weekend, String fk_type) {
        ContentValues initialValues = new ContentValues();
        initialValues.put("fk_email1", email1);
        initialValues.put("fk_email2", email2);
        initialValues.put("validated", validated);
        initialValues.put("hour1", hour1);
        initialValues.put("hour2", hour2);
        initialValues.put("date1", date1);
        initialValues.put("date2", date2);
        initialValues.put("weekend", weekend);
        initialValues.put("fk_type", fk_type);
        return mDb.insert("permission", null, initialValues);
    }

    public void clearDB() {
        mDbHelper.clearDb(mDb);
    }

    public Cursor fetchAllUsers() {

        return mDb.query("user", new String[]{"email", "password", "fullName", "mobilePhone", "mobileOperatingSystem"}, null, null, null, null, null);
    }

    public Cursor fetchAllPermissions() {

        return mDb.query("permission", new String[]{"fk_email1", "fk_email2", "validated", "hour1", "hour2", "date1", "date2", "weekend", "fk_type"}, null, null, null, null, null);
    }

    public Cursor fetchUser(String email) throws SQLException {

        Cursor mCursor = mDb.query(true, "user", new String[]{"email", "password", "fullName", "mobilePhone", "mobileOperatingSystem"}
                , "email" + "=" + email, null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    public void deleteUser(String email) throws SQLException {
        Delete From permission Where fk_email1 = 'pablo@upv.es' and fk_email2 = 'fanny@test.es'
    }

    public List<Friend> retrieveAllFriends() {
        List<Friend> friends = new ArrayList<Friend>();
        Cursor result = fetchAllUsers();
        if (result.moveToFirst()) {
            do {
                friends.add(new Friend(result.getString(result.getColumnIndexOrThrow("email")), result.getString(result.getColumnIndexOrThrow("password")), result.getString(result.getColumnIndexOrThrow("fullName")), result.getString(result.getColumnIndexOrThrow("mobilePhone")), result.getString(result.getColumnIndexOrThrow("mobileOperatingSystem"))));
            } while (result.moveToNext());
        }
        return friends;
    }

    public List<Permission> retrieveAllPermissions() {
        List<Permission> permissions = new ArrayList<Permission>();
        Cursor result = fetchAllPermissions();
        if (result.moveToFirst()) {
            do {
                permissions.add(new Permission(result.getString(result.getColumnIndexOrThrow("fk_email1")),
                        result.getString(result.getColumnIndexOrThrow("fk_email2")),
                        Integer.parseInt(result.getString(result.getColumnIndexOrThrow("validated"))),
                        result.getString(result.getColumnIndexOrThrow("hour1")),
                        result.getString(result.getColumnIndexOrThrow("hour2")),
                        result.getString(result.getColumnIndexOrThrow("date1")),
                        result.getString(result.getColumnIndexOrThrow("date2")),
                        Integer.parseInt(result.getString(result.getColumnIndexOrThrow("weekend"))),
                        result.getString(result.getColumnIndexOrThrow("fk_type"))));
            } while (result.moveToNext());
        }
        return permissions;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:14:27+00:00Added an answer on May 19, 2026 at 9:14 am

    mDb.delete(DATABASE_NAME, "email" + "=" + value_to_delete, null);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.