0

The fields am troubling with is titulo on libro table. The other fields are updating successfully, but not that one.

CODE

public boolean editarLibro(Context context, Libro lib) {

    try {
        helper = new BBDD_Helper(context);

        SQLiteDatabase db = helper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(Estructura_BBDD.Libro.id_autor, lib.getId_autor());
        values.put(Estructura_BBDD.Libro.titulo, lib.getTitulo());
        values.put(Estructura_BBDD.Libro.editorial, lib.getEditorial());
        values.put(Estructura_BBDD.Libro.genero, lib.getGenero());
        values.put(Estructura_BBDD.Libro.creacion, lib.getCreacion());
        values.put(Estructura_BBDD.Libro.ejemplares, lib.getEjemplares());
        values.put(Estructura_BBDD.Libro.disponibles, lib.getDisponibles());
        values.put(Estructura_BBDD.Libro.paginas, lib.getPaginas());


        Toast.makeText(context,lib.getTitulo() , Toast.LENGTH_SHORT).show();
        String selection = Estructura_BBDD.Libro.id + " LIKE ?";
        String[] selectionArgs = {lib.getId() + ""};

        int count = db.update(
                Estructura_BBDD.Libro.libro,
                values,
                selection,
                selectionArgs
        );
Toast.makeText(context, "Se ha editado correctamente",Toast.LENGTH_SHORT).show();

        return true;
    } catch (Exception e) {
        Toast.makeText(context, e.getMessage().toString(), Toast.LENGTH_LONG).show();
    }
    return false;
}

Tables

public static class Libro implements BaseColumns {

    public static final String libro = "libro";

    public static final String id = "id";
    public static final String id_autor = "id_autor";
    public static final String titulo = "titulo";
    public static final String editorial = "editorial";
    public static final String genero = "genero";
    public static final String creacion = "creacion";
    public static final String ejemplares = "ejemplares";
    public static final String disponibles = "disponibles";
    public static final String paginas = "paginas";
    public static final String fecha_inclusion = "fecha_inclusion";
    public static final String fecha_modificacion = "fecha_modificacion";
}

public static class Autor implements BaseColumns {

    public static final String autor = "autor";

    public static final String id = "id";
    public static final String nombre = "nombre";
    /*public static final String apellidos = "apellidos";
    public static final String biografia = "biografia";*/
}

Create Queries

private static final String CREAR_TABLA_LIBRO = "create table "
        + Libro.libro + " ("
        + Libro.id + " integer primary key autoincrement, "
        + Libro.id_autor + " integer not null, "
        + Libro.titulo + " text not null,"
        + Libro.editorial + " text not null,"
        + Libro.genero + " text null,"
        + Libro.creacion + " integer null,"
        + Libro.ejemplares + " integer null,"
        + Libro.disponibles + " integer null,"
        + Libro.paginas + " integer null,"
        + Libro.fecha_inclusion + " date not null DEFAULT (CURRENT_DATE),"
        + Libro.fecha_modificacion + " date null,"
        + " FOREIGN KEY (" + Libro.id_autor + ") REFERENCES " + Autor.autor + "(" + Autor.id + "));";

private static final String CREAR_TABLA_AUTOR = "create table "
        + Autor.autor + " ("
        + Autor.id + " integer primary key autoincrement, "
        + Autor.nombre + " integer not null);";

private static final String CREAR_TRIGGER_LIBRO = "CREATE TRIGGER date_trigger AFTER UPDATE " +
        "ON "+Libro.libro +
        " BEGIN " +
        "update "+Libro.libro+" set "+Libro.fecha_modificacion+"=current_date; " +
        "END; ";
}
Rafvdvs
  • 1
  • 2
  • have you add that column later in your table? – Lalit Verma Dec 08 '17 at 15:23
  • No, however im uninstalling the app several times to test when i change the structure of the tables... That was one of the first Colums i added. – Rafvdvs Dec 08 '17 at 15:28
  • have checked if column is present in DB schema or not?, just check it if its not present than try with changing your Db version and building pproject again. – Lalit Verma Dec 08 '17 at 15:30
  • I extracted it several times (with android device monitor), opened w/ sqlitestudio. The column is there. – Rafvdvs Dec 08 '17 at 15:37
  • Edit your question to include the code used to create the column and/or the column definition (you might have constraints). What does the Toast show for `lib.getTitulo()`? What makes you think/how are you coming to the conclusion, that the update is not working? perhaps include code to get the row that you updated immediately after the update and write the data to the log. Alternately you could make use of [the utilities here](https://stackoverflow.com/questions/46642269/are-there-any-methods-that-assist-with-resolving-common-sqlite-issues). – MikeT Dec 08 '17 at 19:36
  • That toast shows the titulo i inserted in the editText, but i have checked too the ContentValues (values.toString()) too and it is the titulo i wanted. So the col titulo is coming fine at content values. I think that the update is not working for that col because I have checked the other cols, ill post the structure, ok. I tried that, but ill check that log. – Rafvdvs Dec 09 '17 at 11:19
  • I couldn't use the CommonSQLiteUtilities because im not generating any cursor in this update. – Rafvdvs Dec 09 '17 at 12:15

0 Answers0