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 java.util.ArrayList;
public class DB extends SQLiteOpenHelper {
SQLiteDatabase db;
public DB(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, "Prueba", factory, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table datos(nombre text, apellido text)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
// metodo para borrar un usuario especifico ( Funciona bien )
public String eliminar(String Nombre){
String mensaje ="";
SQLiteDatabase database = this.getWritableDatabase();
int cantidad =database.delete("datos", "nombre='" + Nombre + "'", null);
if (cantidad !=0){
mensaje="Eliminado Correctamente";
}
else{
mensaje = "No existe";
}
database.close();
return mensaje;
}
// ESTE ES EL METODO PARA BORRAR EL HISTORIAL ( Falta algo )
public String borrarHistorial(){
SQLiteDatabase database = this.getWritableDatabase();
String mensaje ="";
Cursor c = database.rawQuery("SELECT * FROM datos", null);
// Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
mensaje = "Historial historial completamente vacio";
return mensaje;
}
else {
// SQLiteDatabase db = this.getWritableDatabase();
// db.delete(TABLE_NAME,null,null);
//db.execSQL("delete * from"+ datos);
// db.delete(db, null, null);
// String selectQuery = "DELETE FROM datos ";
// Cursor cursor = this.getReadableDatabase().rawQuery(selectQuery, null);
// database.delete("datos", "nombre='" , null);
// db.delete(TABLE_NAME, null, null);
//db.execSQL("TRUNCATE table" + datos);
db.execSQL("drop table if exists datos");
db.execSQL("create table datos(nombre text, apellido text)");
mensaje = "Historial Eliminado";
}
db.close();
return mensaje;
}
}