Remove deletion anomaly ?

i am developing an application where i build a database , i build my database with help of tutorial http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/ ,the code is working fine, but the problem is that when i delete an i item from a particular id, it just removes the row and that id oges missing. How can i avoid loss of the that id

the code is given below

private class CustomSQLiteOpenHelper extends SQLiteOpenHelper

{
    public CustomSQLiteOpenHelper(Context context)
    {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        // This string is used to create the database.  It should
        // be changed to suit your needs.
        String newTableQueryString = "create table " +
                                    TABLE_NAME +
                                    " (" +
                                    TABLE_ROW_ID + " integer primary key autoincrement not null," +
                                    TABLE_ROW_ONE + " text," +
                                    TABLE_ROW_TWO + " text" +
                                    ");";
        // execute the query string to the database.
        db.execSQL(newTableQueryString);
    }

and for deletion

public void deleteRow(long rowID)
{
    // ask the database manager to delete the row of given id
    try {db.delete(TABLE_NAME, TABLE_ROW_ID + "=" + rowID, null);}
    catch (Exception e)
    {
        Log.e("DB ERROR", e.toString());
        e.printStackTrace();
    }

Via

  1. Context of an android service problem Here is my DBHelper and DBAdapter Classes: public class DBAdapter { private static final String TAG = "DBAdapter"; private static final String DATABASE_NAME = "geneology"; private static final int DATABASE_VERSION = 1; private final Context context; private DatabaseHelper DBHelper; private SQLiteDatabase db; public DBAdapter(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion...
  2. How to Delete phone number from contact in android? I want to delete (e.g. mobile number) from android database. For that I am passing query as follow public class ContactDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String number = "2222"; Long id = getID(number); int i = getContentResolver().delete(RawContacts.CONTENT_URI, RawContacts._ID+"=?", new String[]{id.toString()}); System.out.println("Deleted"+i); } public Long getID(String number){ Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor c = getContentResolver().query(uri, new String[]{PhoneLookup._ID}, null, null, null); while(c.moveToNext()){ return c.getLong(c.getColumnIndex(PhoneLookup._ID)); } return null; } } but it is deleting entire contact. What should I use to delete only that phone number...
  3. Please Check My Android Calorie Counter Application Hi Friends I developed an application “Calorie Counter”. This is used to count the number of calories in daily taken food. My problem is it works perfectly in the emulator but it doesn’t work in mobile. When i enter new food, it shows zero calories. Please check my database to see if i make any mistakes. Here is my data base code: package com.CalorieCounter; import java.util.ArrayList; import java.util.List; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.util.Log; public class DataBase { public static final String KEY_ROWID = "_id"; public static final String KEY_UNIQUE="uni";...
  4. Android, create and populate SQLite database using InsertHelper and Assets Hi, I am new to Android development and would like to create and pre-populate a SQLite database using csv files from the Assets folder. I am using a database adapter class and in the onCreate method after creating the database I want to read the csv file fromt the assets folder and use it to insert rows using DatabaseUtils.InsertHelper. import android.database.DatabaseUtils.InsertHelper; //... public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // need to read the path csv data here containing columns "_id" and "path" try { InputStream is = getAssets().open("pathcsv"); int size = is.available(); // Read the entire asset into a local...
  5. Cannot create file in Android I try to create a file in android and there is no exception but when i try to open it I get Unable to create external files directory. public static void savePromoItems(ArrayList<PromoItem> promoItems, Context context, String filename) { try { FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE); ObjectOutputStream out = new ObjectOutputStream(fos); for (PromoItem promoItem : promoItems) { out.writeObject(promoItem); } out.close(); } catch(Exception ex) { ex.printStackTrace(); } } public static ArrayList<PromoItem> readPromotions(Context context, String filename) { ArrayList<PromoItem> promoItems = new ArrayList<PromoItem>(); try { File file = new File(filename); if (file.exists()) { FileInputStream fis = context.openFileInput(filename); ObjectInputStream in = new ObjectInputStream(fis); Object promoItem...

Leave a Comment