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 7978643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:32:46+00:00 2026-06-04T09:32:46+00:00

I’m pretty sure this is a known issue and there is some info about

  • 0

I’m pretty sure this is a known issue and there is some info about this but I couldn’t find the right answer to it.

Basically, I have an SQLite table that I want the user to be able to remove and insert rows as he sees fit. The user can Insert rows and delete them but the problem is – if the user delete, lets say row 3 (position=2) then after this delete, he wont be able to insert new row there.
I get error 19 – #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */

So, how can i delete a row and then rearrange the rows to be sequential without any gaps? Or otherwise, what is the best way to approach this?

Here is my code:

package android.GUI;

import android.GUI.R.string;

public class DBAdapter {

    public static final String KEY_ROWID = "_id";
    public static final String KEY_DATE = "Date";
    public static final String KEY_DAY = "Day";
    public static final String KEY_HOURS = "Hours";
    public static final String KEY_START = "Start";
    public static final String KEY_END = "End";
    public static final String KEY_TOTAL_HOURS = "TotalH";
    public static final String KEY_TOTAL_MINUTES = "TotalM";

    private static final String TAG = "DBAdapter";
    int dbSumHours;
    int dbSumMinutes;

    private static final String DATABASE_NAME = "shifts6";
    private static final String DATABASE_TABLE = "newtimeDate6";
    private static final int DATABASE_VERSION = 2;

    private static final String DATABASE_CREATE = "create table newtimeDate6 (_id integer primary key autoincrement, "
            + "Date text not null, Hours text not null, TotalH text not null, TotalM text not null, Day text not null, Start text not null, End text not null )";

    private final Context context;

    private static DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx) {

        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    // opens the database
    public DBAdapter open() throws SQLException {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    // closes the database
    public static void close() {
        DBHelper.close();

    }

    // insert a Shift into the database
    public long insertTitle(String Date, String Hour, int TotalH, int TotalM,
            String Day, int ID, String Start, String End) {

        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_DATE, Date);
        initialValues.put(KEY_ROWID, ID);
        initialValues.put(KEY_HOURS, Hour);
        initialValues.put(KEY_TOTAL_HOURS, TotalH);
        initialValues.put(KEY_TOTAL_MINUTES, TotalM);
        initialValues.put(KEY_DAY, Day);
        initialValues.put(KEY_START, Start);
        initialValues.put(KEY_END, End);

        return db.insert(DATABASE_TABLE, null, initialValues);

    }

    public void addToDBTotal(String Date, String Hour, int TotalH, int TotalM,
            String Day, int ID, String Start, String End) {
        dbSumHours = dbSumHours + TotalH;
        dbSumMinutes = dbSumMinutes + TotalM;
        String hour = Hour;
        String date = Date;



        long id = insertTitle(Date, Hour, dbSumHours, dbSumMinutes, Day, ID,
                Start, End);


    }

    // deletes a particular Shifts
    public boolean deleteTitle(long rowId) {
        Boolean deleted = db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;


        return deleted;



    }

    public void deleteAll() {
        this.open();
        this.db.delete(DATABASE_TABLE, null, null);
        Main.C = 1;
    }

    // retrivs all titles
    public Cursor getAllShifts() {

        return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_DATE,
                KEY_HOURS, KEY_DAY, KEY_START, KEY_END }, null, null, null,
                null, null);

    }

    public Cursor getSumHours() {

        return db.query(DATABASE_TABLE, new String[] { KEY_TOTAL_MINUTES, KEY_TOTAL_HOURS },
                null, null, null, null, null);

    }




    public static class DatabaseHelper extends SQLiteOpenHelper {

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

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL(DATABASE_CREATE);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            Log.w(TAG, "Upgrading database from version " + oldVersion + "to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS shifts");
            onCreate(db);

        }
    }

}
  • 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-06-04T09:32:47+00:00Added an answer on June 4, 2026 at 9:32 am

    You have to turn off autoincrement and then manage the rows and row id numbers yourself. After a delete you would have to read out each row after it, delete it and re-insert it in the previous row, repeat until you get to the end.

    Now, why is it so important that there be no gaps?

    And the best way to approach it is to not do it. Its extra cycles (gayety life) that is not gaining you anything.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.