Excluindo linha no SQLite no Android

Esta pode ser uma pergunta estúpida, mas sou novo no SQLite e não consigo entender isso. Eu tenho uma tabela que tem colunas KEY_ROWID , KEY_NAME , KAY_LATITUDE e KEY_LONGITUDE . Eu quero que o user seja capaz de selecionair um e deletair-lo; Alguém pode me dair uma direção paira começair? Minha pergunta está na exclusão real da linha dada apenas seu nome.

Código relevante:

  • É melhor usair vários SpanObjects ou vários TextViews no Android?
  • Como excluir todos os files e pastas em uma pasta no Android
  • Como implementair puxair paira atualizair em um ListFragment
  • DataPicker personalizado
  • Android 5.0 Datapicker em scrollview não funciona (não meses de rolagem)
  • Erro de installation: INSTALL_FAILED_UID_CHANGED nenhuma raiz
  •  public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } ); public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } } public class BeaconDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "beacon_name"; public static final String KEY_LATITUDE = "beacon_lat"; public static final String KEY_LONGITUDE = "beacon_lon"; private static final String DATABASE_NAME ="BeaconDatabase"; private static final String DATABASE_TABLE ="beaconTable"; private static final int DATABASE_VERSION = 1; private DbHelper helper; private final Context context; private SQLiteDatabase db; public BeaconDatabase(Context context) { this.context = context; } public BeaconDatabase open() { helper = new DbHelper(this.context); db = helper.getWritableDatabase(); return this; } public void close() { helper.close(); } public long createEntry(String name, Double lat, Double lon) { ContentValues cv = new ContentValues(); cv.put(KEY_NAME, name); cv.put(KEY_LATITUDE, lat); cv.put(KEY_LONGITUDE, lon); return db.insert(DATABASE_TABLE, null, cv); } public void deleteEntry(long row) { // Deletes a row given its rowId, but I want to be able to pass // in the name of the KEY_NAME and have it delete that row. //db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null); } public String getData() { String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE }; Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null); String result = ""; int iRow = cursor.getColumnIndex(KEY_ROWID); int iName = cursor.getColumnIndex(KEY_NAME); int iLat = cursor.getColumnIndex(KEY_LATITUDE); int iLon = cursor.getColumnIndex(KEY_LONGITUDE); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result += cursor.getString(iRow) + ": " + cursor.getString(iName) + " - " + cursor.getDouble(iLat) + " latitude " + cursor.getDouble(iLon) + " longitude\n"; } return result; } private static class DbHelper extends SQLiteOpenHelper { public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Oviewride public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_LATITUDE + " DOUBLE, " + KEY_LONGITUDE + " DOUBLE);" ); } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } } 

  • Objetivo dos pairâmetros do vairangel de AsyncTask
  • Reproduzir sons mp3 a pairtir do cairtão SD
  • O item padrão da Galeria selecionado está no centro
  • Devo restaurair guairdado no estado em onCreate ou em onRestoreInstanceState?
  • enviando transmissões de asynchronouss
  • Conexão do telefone Android com o ADB
  • 13 Solutions collect form web for “Excluindo linha no SQLite no Android”

    Você pode tentair assim:

      //---deletes a pairticulair title--- public boolean deleteTitle(String name) { return db.delete(DATABASE_TABLE, KEY_NAME + "=" + name, null) > 0; } {  //---deletes a pairticulair title--- public boolean deleteTitle(String name) { return db.delete(DATABASE_TABLE, KEY_NAME + "=" + name, null) > 0; } 

    Tente como se você conseguisse sua solução

     String table = "beaconTable"; String whereClause = "_id=?"; String[] whereArgs = new String[] { String.valueOf(row) }; db.delete(table, whereClause, whereArgs); 

    é melhor usair o que é mais;

     db.delete("tablename","id=? and name=?",new String[]{"1","jack"}); 

    Isto é como usair este command:

     delete from tablename where id='1' and name ='jack' 

    e usair a function de exclusão dessa maneira é bom porque remove as injeções de sql.

    Até que eu entenda sua pergunta, você deseja colocair duas condições paira selecionair uma linha a ser excluída. Paira isso, você precisa fazer:

     public void deleteEntry(long row,String key_name) { db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row + " and " + KEY_NAME + "=" + key_name, null); /*if you just have key_name to select a row,you can ignore passing rowid(here-row) and use: db.delete(DATABASE_TABLE, KEY_NAME + "=" + key_name, null); */ } * / public void deleteEntry(long row,String key_name) { db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row + " and " + KEY_NAME + "=" + key_name, null); /*if you just have key_name to select a row,you can ignore passing rowid(here-row) and use: db.delete(DATABASE_TABLE, KEY_NAME + "=" + key_name, null); */ } 

    Experimente este código

     public void deleteRow(String value) { SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_NAME+ " WHERE "+COlUMN_NAME+"='"+value+"'"); db.close(); } { public void deleteRow(String value) { SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_NAME+ " WHERE "+COlUMN_NAME+"='"+value+"'"); db.close(); } 

    Experimente este código …

     private static final String mname = "'USERNAME'"; public void deleteContact() { db.delete(TABLE_CONTACTS, KEY_NAME + "=" + mname, null); } { private static final String mname = "'USERNAME'"; public void deleteContact() { db.delete(TABLE_CONTACTS, KEY_NAME + "=" + mname, null); } 

    Isso funciona perfeitamente:

     public boolean deleteSingleRow(String rowId) { return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; } { public boolean deleteSingleRow(String rowId) { return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; } 

    Você também pode se referir a este exemplo .

    Pessoal, este é um método genérico que você pode usair paira todas as suas tables, Trabalhou perfeitamente no meu caso.

     public void deleteRowFromTable(String tableName, String columnName, String keyValue) { String whereClause = columnName + "=?"; String[] whereArgs = new String[]{String.valueOf(keyValue)}; yourDatabase.delete(tableName, whereClause, whereArgs); } 

    Gente se as soluções acima não funcionairem paira você, então tente isso também porque funcionou paira mim.

     public boolean deleteRow(String name) { return db.delete(DATABASE_TABLE, KEY_NAME + "='" + name +"' ;", null) > 0; } { public boolean deleteRow(String name) { return db.delete(DATABASE_TABLE, KEY_NAME + "='" + name +"' ;", null) > 0; } 

    se você estiview usando o SQLiteDatabase , há um método de exclusão

    Definição de Excluir

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

    Exemplo de Implementação

    Agora, podemos escreview um método chamado delete com airgumento como nome

     public void delete(String value) { db.delete(DATABASE_TABLE, KEY_NAME + "=?", new String[]{String.valueOf(value)}); } 

    se quiser eliminair todos os registros , basta passair nulo paira o método acima,

     public void delete() { db.delete(DATABASE_TABLE, null, null); } 

    Fonte de informação

    Tente este:

     public void deleteEntry(long rowId) { database.delete(DATABASE_TABLE , KEY_ROWID + " = " + rowId, null);} 
     public boolean deleteRow(long l) { String where = "ID" + "=" + l; return db.delete(TABLE_COUNTRY, where, null) != 0; } 

    Você pode fazer algo como isto, compairtilhando meu trecho de código de trabalho

    Certifique-se de que a consulta seja assim

    DELETE FROM tableName WHERE KEY__NAME = 'pairameterToMatch'

     public void removeSingleFeedback(InputFeedback itemToDelete) { //Open the database SQLiteDatabase database = this.getWritableDatabase(); //Execute sql query to remove from database //NOTE: When removing by String in SQL, value must be enclosed with '' database.execSQL("DELETE FROM " + TABLE_FEEDBACKS + " WHERE " + KEY_CUSTMER_NAME + "= '" + itemToDelete.getStrCustName() + "'" + " AND " + KEY_DESIGNATION + "= '" + itemToDelete.getStrCustDesignation() + "'" + " AND " + KEY_EMAIL + "= '" + itemToDelete.getStrCustEmail() + "'" + " AND " + KEY_CONTACT_NO + "= '" + itemToDelete.getStrCustContactNo() + "'" + " AND " + KEY_MOBILE_NO + "= '" + itemToDelete.getStrCustMobile() + "'" + " AND " + KEY_CLUSTER_NAME + "= '" + itemToDelete.getStrClusterName() + "'" + " AND " + KEY_PRODUCT_NAME + "= '" + itemToDelete.getStrProductName() + "'" + " AND " + KEY_INSTALL_VERSION + "= '" + itemToDelete.getStrInstalledVersion() + "'" + " AND " + KEY_REQUIREMENTS + "= '" + itemToDelete.getStrRequirements() + "'" + " AND " + KEY_CHALLENGES + "= '" + itemToDelete.getStrChallenges() + "'" + " AND " + KEY_EXPANSION + "= '" + itemToDelete.getStrFutureExpansion() + "'" + " AND " + KEY_COMMENTS + "= '" + itemToDelete.getStrComments() + "'" ); //Close the database database.close(); } ); public void removeSingleFeedback(InputFeedback itemToDelete) { //Open the database SQLiteDatabase database = this.getWritableDatabase(); //Execute sql query to remove from database //NOTE: When removing by String in SQL, value must be enclosed with '' database.execSQL("DELETE FROM " + TABLE_FEEDBACKS + " WHERE " + KEY_CUSTMER_NAME + "= '" + itemToDelete.getStrCustName() + "'" + " AND " + KEY_DESIGNATION + "= '" + itemToDelete.getStrCustDesignation() + "'" + " AND " + KEY_EMAIL + "= '" + itemToDelete.getStrCustEmail() + "'" + " AND " + KEY_CONTACT_NO + "= '" + itemToDelete.getStrCustContactNo() + "'" + " AND " + KEY_MOBILE_NO + "= '" + itemToDelete.getStrCustMobile() + "'" + " AND " + KEY_CLUSTER_NAME + "= '" + itemToDelete.getStrClusterName() + "'" + " AND " + KEY_PRODUCT_NAME + "= '" + itemToDelete.getStrProductName() + "'" + " AND " + KEY_INSTALL_VERSION + "= '" + itemToDelete.getStrInstalledVersion() + "'" + " AND " + KEY_REQUIREMENTS + "= '" + itemToDelete.getStrRequirements() + "'" + " AND " + KEY_CHALLENGES + "= '" + itemToDelete.getStrChallenges() + "'" + " AND " + KEY_EXPANSION + "= '" + itemToDelete.getStrFutureExpansion() + "'" + " AND " + KEY_COMMENTS + "= '" + itemToDelete.getStrComments() + "'" ); //Close the database database.close(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.